use of com.ibm.streamsx.health.hapi.model.Observation in project streamsx.health by IBMStreams.
the class ObxToSplMapper method messageToModel.
@SuppressWarnings("unchecked")
public <T> Iterable<T> messageToModel(Message message) {
ArrayList<Observation> observations = new ArrayList<Observation>();
if (message instanceof ORU_R01) {
ORU_R01 oruMsg = (ORU_R01) message;
String obxTs = "";
String obxLocation = "";
String sendingApp = "";
String sendingFacility = "";
try {
MSH msh = oruMsg.getMSH();
sendingApp = msh.getSendingApplication().encode();
sendingFacility = msh.getSendingFacility().encode();
List<ORU_R01_PATIENT_RESULT> patient_RESULTAll = ((ORU_R01) message).getPATIENT_RESULTAll();
for (ORU_R01_PATIENT_RESULT result : patient_RESULTAll) {
ORU_R01_ORDER_OBSERVATION order_OBSERVATION = result.getORDER_OBSERVATION();
OBR obr = order_OBSERVATION.getOBR();
DTM ts = obr.getObservationDateTime();
obxTs = ts.getValue();
ORU_R01_PATIENT patient = result.getPATIENT();
ORU_R01_VISIT visit = patient.getVISIT();
PL location = visit.getPV1().getAssignedPatientLocation();
obxLocation = location.encode();
List<ORU_R01_OBSERVATION> observationAll = order_OBSERVATION.getOBSERVATIONAll();
for (ORU_R01_OBSERVATION oru_R01_OBSERVATION : observationAll) {
parseOBX(observations, obxTs, obxLocation, oru_R01_OBSERVATION.getOBX(), sendingApp, sendingFacility);
}
}
} catch (HL7Exception e) {
if (TRACE.isDebugEnabled())
TRACE.log(TraceLevel.WARN, e);
}
try {
OBR obr = (OBR) oruMsg.get("OBR");
DTM ts = obr.getObservationDateTime();
obxTs = ts.getValue();
Structure tmp = oruMsg.get("PV1");
if (tmp != null) {
PV1 pv1 = (PV1) tmp;
PL location = pv1.getAssignedPatientLocation();
obxLocation = location.encode();
}
Structure[] structures = oruMsg.getAll("OBX");
for (Structure structure : structures) {
parseOBX(observations, obxTs, obxLocation, (OBX) structure, sendingApp, sendingFacility);
}
} catch (HL7Exception e) {
if (TRACE.isDebugEnabled())
TRACE.log(TraceLevel.WARN, e);
}
}
return (Iterable<T>) observations;
}
use of com.ibm.streamsx.health.hapi.model.Observation in project streamsx.health by IBMStreams.
the class ObxToSplMapper method parseOBX.
private void parseOBX(ArrayList<Observation> observations, String obxTs, String obxLocation, OBX obx, String sendingApp, String sendingFacility) throws HL7Exception {
Observation observation = new Observation();
observation.setTs(obxTs);
observation.setLocation(obxLocation);
String observationId = obx.getObservationIdentifier().getIdentifier().getValue();
String unit = obx.getUnits().getIdentifier().getValue();
observation.setObservationId(observationId);
observation.setUnit(unit);
observation.setSendingApp(sendingApp);
observation.setSendingFacility(sendingFacility);
Varies[] values = obx.getObservationValue();
for (Varies value : values) {
observation.setObservationValue(value.encode());
observations.add(observation);
}
}
use of com.ibm.streamsx.health.hapi.model.Observation in project streamsx.health by IBMStreams.
the class OruR01Ingest method run.
@Override
public void run() {
Topology topology = new Topology("OruR01Ingest");
ObxToSplMapper mapper = new ObxToSplMapper();
addDependencies(topology);
TStream<Message> messages = topology.endlessSource(new HapiMessageSupplier(getPort()));
// transform message to Observation object
TStream<Observation> observationStream = messages.multiTransform(message -> {
return mapper.messageToModel(message);
});
StreamSchema schema = Type.Factory.getStreamSchema(Observation.OBSERVATION_SCHEMA_SPL);
@SuppressWarnings("serial") SPLStream splObservations = SPLStreams.convertStream(observationStream, new BiFunction<Observation, OutputTuple, OutputTuple>() {
@Override
public OutputTuple apply(Observation observation, OutputTuple outTuple) {
return mapper.modelToSpl(observation, outTuple);
}
}, schema);
splObservations.print();
splObservations.publish(getTopic());
try {
StreamsContextFactory.getStreamsContext(StreamsContext.Type.DISTRIBUTED).submit(topology);
} catch (Exception e) {
TRACE.error("Unable to submit topology", e);
}
}
Aggregations