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

Visit extension used by fact providers, added visit location and test cases

parent 619b2e92
......@@ -38,6 +38,7 @@ import java.util.logging.Logger;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ext.ExternalSourceType;
import de.sekmi.histream.ext.StoredExtensionType;
import de.sekmi.histream.ext.Visit;
import de.sekmi.histream.ext.Visit.Status;
......@@ -49,6 +50,9 @@ import de.sekmi.histream.ext.Visit.Status;
* Some optional columns are used: active_status_cd, start_date, end_date, inout_cd, location_cd, sourcesystem_cd
* <p>
* TODO use encounter_mapping table to map actual (source) patient_ide to internal patient_num for facts.
* <p>
* The variable argument list for {@link #createInstance(Object...)} requires the following arguments:
* {@link String}{@code visitId}, {@link I2b2Patient}{@code patient}, {@link ExternalSourceType}{@code source}.
*
* @author marap1
*
......@@ -530,28 +534,25 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
log.log(Level.SEVERE, "Unable to update visit "+visit.getId(), e);
}
@Override
public I2b2Visit createInstance(Observation fact) {
// TODO create visit using fact.getPatientId() and fact.getVisitId()
I2b2Visit visit = idCache.get(fact.getEncounterId());
private I2b2Visit getOrCreateInstance(String encounterId, I2b2Patient patient, ExternalSourceType source){
I2b2Visit visit = idCache.get(encounterId);
if( visit == null ){
maxEncounterNum ++;
int encounter_num = maxEncounterNum;
I2b2Patient p = fact.getExtension(I2b2Patient.class);
visit = new I2b2Visit(encounter_num, p.getNum());
visit.setPatientId(fact.getPatientId());
visit = new I2b2Visit(encounter_num, patient.getNum());
visit.setPatientId(patient.getId());
// created from observation, use source metadata
visit.setSourceId(fact.getSourceId());
visit.setSourceTimestamp(fact.getSourceTimestamp());
visit.setSourceId(source.getSourceId());
visit.setSourceTimestamp(source.getSourceTimestamp());
// put in cache
visitCache.put(encounter_num, visit);
// only one alias which is also primary
setAliases(visit, new String[]{fact.getEncounterId()}, 0);
setAliases(visit, new String[]{encounterId}, 0);
// insert to storage
try {
......@@ -563,7 +564,11 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
// but changes are written later via a call to update.
// (otherwise, the instance would need to know whether to perform INSERT or UPDATE)
}
return visit;
return visit;
}
@Override
public I2b2Visit createInstance(Observation fact) {
return getOrCreateInstance(fact.getEncounterId(), fact.getExtension(I2b2Patient.class), fact);
}
@Override
......@@ -614,6 +619,13 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
@Override
public I2b2Visit createInstance(Object... args) throws UnsupportedOperationException {
if( args.length != 3
|| !(args[0] instanceof String)
|| !(args[1] instanceof I2b2Patient)
|| !(args[2] instanceof ExternalSourceType) )
{
throw new IllegalArgumentException("Need arguments String visitId, I2b2Patient patient, ExternalSourceType source");
}
// TODO: implement
throw new UnsupportedOperationException("TODO: implement");
}
......
......@@ -177,8 +177,9 @@ public class ObservationFactoryImpl implements ObservationFactory{
}
@Override
@SuppressWarnings("unchecked")
public T accessStatic(Object... args) throws UnsupportedOperationException, IllegalArgumentException {
return null;
return (T)entry.extension.createInstance(args);
}
};
}
......
......@@ -23,6 +23,8 @@ package de.sekmi.histream.impl;
import de.sekmi.histream.Observation;
import de.sekmi.histream.Extension;
import de.sekmi.histream.ext.ExternalSourceType;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Visit;
public class SimpleVisitExtension implements Extension<VisitImpl>{
......@@ -33,14 +35,30 @@ public class SimpleVisitExtension implements Extension<VisitImpl>{
@Override
public VisitImpl createInstance(Object... args) {
// TODO: use patient id and visit id to identify visit
return new VisitImpl();
if( args.length != 3
|| !(args[0] instanceof String)
|| !(args[1] instanceof Patient)
|| !(args[2] instanceof ExternalSourceType) )
{
throw new IllegalArgumentException("Need arguments String, Patient, ExternalSourceType");
}
VisitImpl visit = new VisitImpl();
visit.setId((String)args[0]);
visit.setPatientId(((Patient)args[1]).getId());
ExternalSourceType source = (ExternalSourceType)args[2];
visit.setSourceId(source.getSourceId());
visit.setSourceTimestamp(source.getSourceTimestamp());
return visit;
}
@Override
public VisitImpl createInstance(Observation observation) {
VisitImpl visit = createInstance();
visit.setId(observation.getEncounterId());
VisitImpl visit = createInstance(observation.getEncounterId(), observation.getExtension(Patient.class), observation);
//visit.setId();
//visit.setPatientId(observation.getPatientId());
//visit.setSourceId(observation.getSourceId());
//visit.setSourceTimestamp(observation.getSourceTimestamp());
return visit;
}
......
......@@ -32,8 +32,9 @@ import java.util.stream.StreamSupport;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.ext.ExternalSourceType;
public class AbstractObservationParser {
public class AbstractObservationParser implements ExternalSourceType{
protected ObservationFactory factory;
// meta
protected Instant sourceTimestamp;
......@@ -117,4 +118,24 @@ public class AbstractObservationParser {
}
}
@Override
public Instant getSourceTimestamp() {
return sourceTimestamp;
}
@Override
public void setSourceTimestamp(Instant sourceTimestamp) {
this.sourceTimestamp = sourceTimestamp;
}
@Override
public String getSourceId() {
return sourceId;
}
@Override
public void setSourceId(String sourceSystemId) {
this.sourceId = sourceSystemId;
}
}
......@@ -173,14 +173,24 @@ public class JAXBObservationSupplier implements ObservationSupplier {
}
if( visitData.containsKey("start") ){
encounterStart = DateTimeAccuracy.parsePartialIso8601(visitData.get("start"));
}else{
encounterStart = null;
}
if( visitData.containsKey("end") ){
encounterEnd = DateTimeAccuracy.parsePartialIso8601(visitData.get("end"));
}else{
encounterEnd = null;
}
// TODO assert at <facts>
reader.nextTag();
// TODO register visit with extension, set visit data
currentVisit = visitAccessor.accessStatic(encounterId, currentPatient, source);
currentVisit.setStartTime(encounterStart);
currentVisit.setEndTime(encounterEnd);
currentVisit.setLocationId(visitData.get("location"));
// TODO set other visit data: gender, provider, in/out status
visitData.get("provider");
}
protected Observation readObservation()throws XMLStreamException{
if( reader.isWhiteSpace() ){
......@@ -245,7 +255,7 @@ public class JAXBObservationSupplier implements ObservationSupplier {
// set ObservationFactory, initialize extensions
fact.setFactory((ObservationFactoryImpl)factory);
patientAccessor.set(fact, currentPatient);
// TODO set current visit
visitAccessor.set(fact, currentVisit);
// TODO add tests to verify patient/visit extensions for parsed facts
return fact;
......
......@@ -177,6 +177,7 @@ class XMLObservationParser extends AbstractObservationParser{
visit = fact.getExtension(Visit.class);
visit.setStartTime(encounterStart);
visit.setEndTime(encounterEnd);
visit.setLocationId(visitData.get("location"));
// visit.setStatus(status.);
// TODO: set visit data
......
......@@ -83,6 +83,7 @@ public class FileObservationProviderTest {
// TODO: test more patient information
Visit v = o.getExtension(Visit.class);
Assert.assertNotNull("Visit extension required", v);
Assert.assertEquals("Zuhause", v.getLocationId());
// TODO test visit information
},
(Observation o) -> {
......
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