use of ca.uhn.hl7v2.model.Message in project tdi-studio-se by Talend.
the class HL7PublicUtil method getChildren.
public Set getChildren(Object parentElement) {
// List values = new ArrayList();
Set values = new HashSet();
if (parentElement instanceof Message) {
Message messParent = (Message) parentElement;
String[] childNames = messParent.getNames();
if (!values.isEmpty()) {
values.clear();
}
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = messParent.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Message) {
values.add(childReps[j]);
if (getChildren(childReps[j]).size() > 0) {
values.addAll(getChildren(childReps[j]));
}
}
if (childReps[j] instanceof Group) {
values.add(childReps[j]);
allSegmentFromGroup.clear();
getAllSegmentsFromGroup((Group) childReps[j]);
}
if (childReps[j] instanceof Segment) {
SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
values.add(sModel);
if (getChildren(sModel).size() > 0) {
values.addAll(getChildren(sModel));
}
if (!allSegmentsForMessage.contains(sModel)) {
allSegmentsForMessage.add(sModel);
}
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values;
}
if (parentElement instanceof Segment) {
values.clear();
Segment segment = (Segment) parentElement;
SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
TypeModel[] models = sm.getTypes();
for (TypeModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
}
if (parentElement instanceof SegmentModel) {
SegmentModel sm = (SegmentModel) parentElement;
TypeModel[] models = sm.getTypes();
for (TypeModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
}
if (parentElement instanceof TypeModel) {
TypeModel tm = (TypeModel) parentElement;
PrimitiveModel[] models = tm.getPrimitives();
for (PrimitiveModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
// return tm.getPrimitives();
}
if (parentElement instanceof Group) {
values.clear();
Group group = (Group) parentElement;
String[] childNames = group.getNames();
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = group.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Segment) {
SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
if (sm.getTypes() != null && sm.getTypes().length > 0) {
values.add(sm);
if (getChildren(sm).size() > 0) {
values.addAll(getChildren(sm));
}
}
} else {
values.add(childReps[j]);
if (getChildren(childReps[j]).size() > 0) {
values.addAll(getChildren(childReps[j]));
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values;
}
return values;
}
use of ca.uhn.hl7v2.model.Message in project streamsx.health by IBMStreams.
the class AdtToModelMapper method messageToModel.
@SuppressWarnings("unchecked")
public <T> Iterable<T> messageToModel(Message message) {
ArrayList<ADTEvent> adtEvents = new ArrayList<ADTEvent>();
if (message instanceof ADT_AXX) {
ADT_AXX superMsg = (ADT_AXX) message;
MessageInfo msg = new MessageInfo();
Patient patient = new Patient();
try {
MSH header = superMsg.getMSH();
msg.setSendingApp(header.getSendingApplication().encode());
msg.setSendingFacility(header.getSendingFacility().encode());
msg.setReceivingApp(header.getReceivingApplication().encode());
msg.setReceivingFacility(header.getReceivingFacility().encode());
msg.setMessageTs(header.getDateTimeOfMessage().encode());
msg.setMessageType(header.getMessageType().encode());
PID pid = superMsg.getPID();
patient.setId(pid.getPatientID().encode());
XPN[] patientNames = pid.getPatientName();
for (XPN name : patientNames) {
if (patient.getName().equals(IInjestServicesConstants.EMPTYSTR)) {
patient.setName(getPatientFullName(name));
} else {
patient.addAlternateName(getPatientFullName(name));
}
}
patient.setGender(pid.getAdministrativeSex().encode());
patient.setDateOfBirth(pid.getDateTimeOfBirth().encode());
CX[] ids = pid.getAlternatePatientIDPID();
if (ids.length > 0) {
for (CX cx : ids) {
patient.addAlternativeId(cx.encode());
}
}
EventDetails evt = new EventDetails();
EVN evn = superMsg.getEVN();
evt.setEventType(evn.getEventTypeCode().encode());
evt.setEventTs(evn.getEvn6_EventOccurred().encode());
evt.setRecordTs(evn.getEvn2_RecordedDateTime().encode());
PV1 pv1 = superMsg.getPV1();
PatientVisit patientVisit = new PatientVisit();
patientVisit.setPatientClass(pv1.getPatientClass().encode());
patientVisit.setLocation(pv1.getAssignedPatientLocation().encode());
patientVisit.setPriorLocation(pv1.getPriorPatientLocation().encode());
patientVisit.setVisitNumber(pv1.getVisitNumber().encode());
patient.setStatus(pv1.getBedStatus().encode());
XCN[] doctors = pv1.getAttendingDoctor();
for (XCN xcn : doctors) {
String id = xcn.getIDNumber().encode();
String name = xcn.getFamilyName().encode() + " " + xcn.getGivenName().encode();
Clinician clinician = new Clinician();
clinician.setId(id);
clinician.setName(name);
patientVisit.addAttendingDoctor(clinician);
}
doctors = pv1.getConsultingDoctor();
for (XCN xcn : doctors) {
String id = xcn.getIDNumber().encode();
String name = xcn.getFamilyName().encode() + " " + xcn.getGivenName().encode();
Clinician clinician = new Clinician();
clinician.setId(id);
clinician.setName(name);
patientVisit.addConsultingDoctor(clinician);
}
ADTEvent adtEvent = new ADTEvent();
adtEvent.setEvt(evt);
adtEvent.setPatient(patient);
adtEvent.setMsg(msg);
adtEvent.setPv(patientVisit);
adtEvents.add(adtEvent);
} catch (HL7Exception e) {
TRACE.error("Unable to parse HL7 message", e);
}
}
return (Iterable<T>) adtEvents;
}
use of ca.uhn.hl7v2.model.Message 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 ca.uhn.hl7v2.model.Message in project streamsx.health by IBMStreams.
the class AdtIngest method run.
@Override
public void run() {
Topology topology = new Topology("AdtIngest");
AdtToModelMapper mapper = new AdtToModelMapper();
addDependencies(topology);
HapiMessageSupplier supplier = new HapiMessageSupplier(getPort());
supplier.setMessageClass(ADT_AXX.class);
TStream<Message> messages = topology.endlessSource(supplier);
// transform message to ADTEvent object
TStream<ADTEvent> adtEvents = messages.multiTransform(message -> {
return mapper.messageToModel(message);
});
// publish data as JSON
PublishAdtEvent.publish(adtEvents, getTopic());
try {
StreamsContextFactory.getStreamsContext(StreamsContext.Type.DISTRIBUTED).submit(topology);
} catch (Exception e) {
TRACE.error("Unable to submit topology", e);
}
}
use of ca.uhn.hl7v2.model.Message in project camel by apache.
the class AckExpression method evaluate.
@Override
public Object evaluate(Exchange exchange) {
Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
Message msg = exchange.getIn().getBody(Message.class);
try {
HL7Exception hl7e = generateHL7Exception(t);
AcknowledgmentCode code = acknowledgementCode;
if (t != null && code == null) {
code = AcknowledgmentCode.AE;
}
return msg.generateACK(code == null ? AcknowledgmentCode.AA : code, hl7e);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
Aggregations