Commit a54b7521 authored by R.W.Majeed's avatar R.W.Majeed
Browse files

use JAXB to load meta

parent eb28122d
......@@ -24,7 +24,7 @@
Encounter-Start liegen -->
<meta>
<!-- Zeitpunkt, an dem der Export erstellt wurde bzw. Datenstand -->
<etl strategy="replace-visit" />
<etl-strategy>replace-visit</etl-strategy>
<source timestamp="2015-04-21T08:58:00" id="test"/>
<!-- weitere metadaten nötig? wertebereich, datentypen, ontologie, ...? -->
......
......@@ -63,4 +63,19 @@ public class Meta {
target.setMeta(key, value);
}
}
public String get(String key) {
switch( key ){
case ObservationSupplier.META_ETL_STRATEGY:
return this.etlStrategy;
case ObservationSupplier.META_SOURCE_ID:
if( source == null )return null;
else return source.getSourceId();
case ObservationSupplier.META_SOURCE_TIMESTAMP:
if( source == null )return null;
else if( source.getSourceTimestamp() == null )return null;
else return source.getSourceTimestamp().toString();
}
return null;
}
}
......@@ -23,20 +23,22 @@ import de.sekmi.histream.ext.ExternalSourceType;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Patient.Sex;
import de.sekmi.histream.ext.Visit;
import de.sekmi.histream.impl.Meta;
import de.sekmi.histream.impl.ObservationFactoryImpl;
import de.sekmi.histream.impl.ObservationImpl;
public class JAXBObservationSupplier extends AbstractObservationParser implements ObservationSupplier {
public class JAXBObservationSupplier implements ObservationSupplier {
static final String DOCUMENT_ROOT = "eav-data";
static final String PATIENT_ELEMENT = "patient";
static final String ENCOUNTER_ELEMENT = "encounter";
static final String FACT_WRAPPER = "facts";
private ObservationFactory factory;
private ExtensionAccessor<Patient> patientAccessor;
private ExtensionAccessor<Visit> visitAccessor;
private Patient currentPatient;
private Visit currentVisit;
private Meta meta;
private Unmarshaller unmarshaller;
private XMLStreamReader reader;
......@@ -61,7 +63,7 @@ public class JAXBObservationSupplier extends AbstractObservationParser implement
this.factory = factory;
this.patientData = new HashMap<>();
this.visitData = new HashMap<>();
unmarshaller = JAXBContext.newInstance(ObservationImpl.class).createUnmarshaller();
unmarshaller = JAXBContext.newInstance(ObservationImpl.class,Meta.class).createUnmarshaller();
// TODO: set schema
//unmarshaller.setSchema(schema);
this.reader = reader;
......@@ -85,37 +87,10 @@ public class JAXBObservationSupplier extends AbstractObservationParser implement
reader.nextTag();
}
private void readMeta()throws XMLStreamException{
private void readMeta()throws XMLStreamException, JAXBException{
if( !reader.isStartElement() || !reader.getLocalName().equals("meta") )return;
this.meta = (Meta)unmarshaller.unmarshal(reader);
// read meta
reader.nextTag();
if( reader.getLocalName().equals("etl") ){
String etlStrategy = reader.getAttributeValue(null, "strategy");
// TODO use constants for etl.strategy, etc.
if( etlStrategy != null )setMeta(ObservationSupplier.META_ETL_STRATEGY, etlStrategy);
reader.nextTag();
// should be end element
reader.nextTag();
}
if( reader.getLocalName().equals("source") ){
String sourceTimestamp = reader.getAttributeValue(null, "timestamp");
setMeta(ObservationSupplier.META_SOURCE_TIMESTAMP, sourceTimestamp);
String sourceId = reader.getAttributeValue(null, "id");
setMeta(ObservationSupplier.META_SOURCE_ID, sourceId);
// will be set automatically by setMeta
//setSourceId(sourceId);
//setSourceTimestamp(parseSourceTimestamp(sourceTimestamp));
reader.nextTag();
// should be end element
reader.nextTag();
}
// skip to end of meta
while( !reader.isEndElement() || !reader.getLocalName().equals("meta") ){
reader.next();
}
reader.nextTag();
}
......@@ -138,7 +113,7 @@ public class JAXBObservationSupplier extends AbstractObservationParser implement
reader.nextTag();
}
// register with extension
currentPatient = patientAccessor.accessStatic(patientId, (ExternalSourceType)this);
currentPatient = patientAccessor.accessStatic(patientId, (ExternalSourceType)meta.source);
// TODO set patient data
if( patientData.containsKey("birthdate") ){
currentPatient.setBirthDate(DateTimeAccuracy.parsePartialIso8601(patientData.get("birthdate")));
......@@ -182,7 +157,7 @@ public class JAXBObservationSupplier extends AbstractObservationParser implement
// TODO assert at <facts>
reader.nextTag();
currentVisit = visitAccessor.accessStatic(encounterId, currentPatient, (ExternalSourceType)this);
currentVisit = visitAccessor.accessStatic(encounterId, currentPatient, (ExternalSourceType)meta.source);
currentVisit.setStartTime(encounterStart);
currentVisit.setEndTime(encounterEnd);
currentVisit.setLocationId(visitData.get("location"));
......@@ -233,7 +208,6 @@ public class JAXBObservationSupplier extends AbstractObservationParser implement
ObservationImpl fact;
try {
fact = (ObservationImpl)unmarshaller.unmarshal(reader);
// TODO: set factory
} catch (JAXBException e) {
throw new XMLStreamException( e);
}
......@@ -241,6 +215,17 @@ public class JAXBObservationSupplier extends AbstractObservationParser implement
throw new XMLStreamException("Fact patid differs from patient id", reader.getLocation());
}
if( fact.getSource() == null ){
fact.setSource(meta.source);
}else{
if( fact.getSource().getSourceId() == null && meta.source.getSourceId() != null ){
fact.getSource().setSourceId(meta.source.getSourceId());
}
if( fact.getSource().getSourceTimestamp() == null && meta.source.getSourceTimestamp() != null ){
fact.getSource().setSourceTimestamp(meta.source.getSourceTimestamp());
}
}
fact.setPatientId(patientId);
fact.setEncounterId(encounterId);
......@@ -272,4 +257,8 @@ public class JAXBObservationSupplier extends AbstractObservationParser implement
public void close() throws XMLStreamException {
reader.close();
}
@Override
public String getMeta(String key) {
return meta.get(key);
}
}
......@@ -44,6 +44,7 @@ import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.ObservationSupplier;
import de.sekmi.histream.Value;
import de.sekmi.histream.ext.ExternalSourceType;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Visit;
import de.sekmi.histream.ext.Patient.Sex;
......@@ -93,6 +94,10 @@ public class FileObservationProviderTest {
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2014-01-01T10:30:00"), v.getStartTime());
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2014-01-05T10:30:00"), v.getEndTime());
// TODO test visit information
// test source
ExternalSourceType s = o.getSource();
Assert.assertNotNull(s);
},
(Observation o) -> {
Assert.assertEquals("T:date:mins", o.getConceptId());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment