Commit 229273eb authored by rwm's avatar rwm

Source info for encounter correctly loaded

parent 50c48c53
...@@ -119,8 +119,12 @@ public class GroupedXMLReader implements ObservationSupplier { ...@@ -119,8 +119,12 @@ public class GroupedXMLReader implements ObservationSupplier {
patientData.put(reader.getLocalName(), reader.getElementText()); patientData.put(reader.getLocalName(), reader.getElementText());
reader.nextTag(); reader.nextTag();
} }
// read source information
ExternalSourceType es = readSource();
// register with extension // register with extension
currentPatient = patientAccessor.accessStatic(patientId, (ExternalSourceType)meta.source); currentPatient = patientAccessor.accessStatic(patientId, (ExternalSourceType)es);
// TODO set patient data // TODO set patient data
if( patientData.containsKey("birthdate") ){ if( patientData.containsKey("birthdate") ){
currentPatient.setBirthDate(DateTimeAccuracy.parsePartialIso8601(patientData.get("birthdate"))); currentPatient.setBirthDate(DateTimeAccuracy.parsePartialIso8601(patientData.get("birthdate")));
...@@ -137,22 +141,39 @@ public class GroupedXMLReader implements ObservationSupplier { ...@@ -137,22 +141,39 @@ public class GroupedXMLReader implements ObservationSupplier {
if( patientData.containsKey("given-name") ){ if( patientData.containsKey("given-name") ){
currentPatient.setGivenName(patientData.get("given-name")); currentPatient.setGivenName(patientData.get("given-name"));
} }
}
/**
* Read source element and amend with meta.source. Needed for patient and encounter.
* @return source. Missing data is added from meta.
* @throws XMLStreamException on errro
*/
private ExternalSourceType readSource() throws XMLStreamException{
ExternalSourceType es;
if( reader.getLocalName().equals("source") ){ if( reader.getLocalName().equals("source") ){
ExternalSourceType es;
try { try {
es = (ExternalSourceType) unmarshaller.unmarshal(reader); es = (ExternalSourceImpl) unmarshaller.unmarshal(reader);
if( reader.getEventType() != XMLStreamConstants.START_ELEMENT ){ if( reader.getEventType() != XMLStreamConstants.START_ELEMENT ){
reader.nextTag(); reader.nextTag();
} }
} catch (JAXBException e) { } catch (JAXBException e) {
throw new XMLStreamException("Unable to parse patient source", reader.getLocation(), e); throw new XMLStreamException("Unable to parse patient source", reader.getLocation(), e);
} }
if( es.getSourceTimestamp() != null ){ // add missing fields from meta
currentPatient.setSourceTimestamp(es.getSourceTimestamp()); if( es.getSourceId() == null ){
es.setSourceId(meta.source.getSourceId());
}
if( es.getSourceTimestamp() == null ){
es.setSourceTimestamp(meta.source.getSourceTimestamp());
} }
}else{
// use meta source
es = meta.source;
} }
return es;
} }
/** /**
* Reads encounter element with content. * Reads encounter element with content.
* Precondition encounter start element. * Precondition encounter start element.
...@@ -183,22 +204,12 @@ public class GroupedXMLReader implements ObservationSupplier { ...@@ -183,22 +204,12 @@ public class GroupedXMLReader implements ObservationSupplier {
}else{ }else{
encounterEnd = null; encounterEnd = null;
} }
ExternalSourceImpl es = null; ExternalSourceType es = readSource();
if( reader.getLocalName().equals("source") ){
try {
es = (ExternalSourceImpl) unmarshaller.unmarshal(reader);
if( reader.getEventType() != XMLStreamConstants.START_ELEMENT ){
reader.nextTag();
}
} catch (JAXBException e) {
throw new XMLStreamException("Unable to parse patient source", reader.getLocation(), e);
}
}
// TODO assert at <facts> // TODO assert at <facts>
reader.nextTag(); reader.nextTag();
currentVisit = visitAccessor.accessStatic(encounterId, currentPatient, (ExternalSourceType)meta.source); currentVisit = visitAccessor.accessStatic(encounterId, currentPatient, (ExternalSourceType)es);
currentVisit.setStartTime(encounterStart); currentVisit.setStartTime(encounterStart);
currentVisit.setEndTime(encounterEnd); currentVisit.setEndTime(encounterEnd);
currentVisit.setLocationId(visitData.get("location")); currentVisit.setLocationId(visitData.get("location"));
......
...@@ -173,7 +173,9 @@ public class GroupedXMLWriter extends GroupedObservationHandler{ ...@@ -173,7 +173,9 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
// write source timestamp // write source timestamp
ExternalSourceImpl es = visitSourceWithContext(visit, meta.source); ExternalSourceImpl es = visitSourceWithContext(visit, meta.source);
if( es != null )try { if( es != null )try {
formatIndent();
marshaller.marshal(es, writer); marshaller.marshal(es, writer);
formatNewline();
} catch (JAXBException e) { } catch (JAXBException e) {
throw new ObservationException(e); throw new ObservationException(e);
} }
...@@ -272,7 +274,9 @@ public class GroupedXMLWriter extends GroupedObservationHandler{ ...@@ -272,7 +274,9 @@ public class GroupedXMLWriter extends GroupedObservationHandler{
// write source timestamp // write source timestamp
ExternalSourceImpl es = patientSourceWithContext(patient,meta.source); ExternalSourceImpl es = patientSourceWithContext(patient,meta.source);
if( es != null )try { if( es != null )try {
formatIndent();
marshaller.marshal(es, writer); marshaller.marshal(es, writer);
formatNewline();
} catch (JAXBException e) { } catch (JAXBException e) {
throw new ObservationException(e); throw new ObservationException(e);
} }
......
...@@ -87,6 +87,8 @@ public class FileObservationProviderTest { ...@@ -87,6 +87,8 @@ public class FileObservationProviderTest {
Assert.assertEquals("A B", p.getGivenName()); Assert.assertEquals("A B", p.getGivenName());
Assert.assertEquals("Dampf", p.getSurname()); Assert.assertEquals("Dampf", p.getSurname());
// TODO: test more patient information // TODO: test more patient information
// TODO test patient source timestamp different from meta source.
// TODO test patient source id automatically filled from meta
Visit v = o.getExtension(Visit.class); Visit v = o.getExtension(Visit.class);
Assert.assertNotNull("Visit extension required", v); Assert.assertNotNull("Visit extension required", v);
......
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