use of ca.uhn.hl7v2.HL7Exception in project nifi by apache.
the class HapiMessage method populateSegments.
private void populateSegments(final Group group, final List<HL7Segment> segments) throws HL7Exception {
for (final String structureName : group.getNames()) {
final Structure[] structures = group.getAll(structureName);
if (group.isGroup(structureName)) {
for (final Structure structure : structures) {
populateSegments((Group) structure, segments);
}
} else {
for (final Structure structure : structures) {
final Segment segment = (Segment) structure;
final HapiSegment hapiSegment = new HapiSegment(segment);
segments.add(hapiSegment);
}
}
}
}
use of ca.uhn.hl7v2.HL7Exception in project nifi by apache.
the class TestHL7Query method createMessage.
private HL7Message createMessage(final String msgText) throws HL7Exception, IOException {
final HapiContext hapiContext = new DefaultHapiContext();
hapiContext.setValidationContext(ValidationContextFactory.noValidation());
final PipeParser parser = hapiContext.getPipeParser();
final Message message = parser.parse(msgText);
return new HapiMessage(message);
}
use of ca.uhn.hl7v2.HL7Exception in project nifi by apache.
the class ExtractHL7Attributes method getAllFields.
private static Map<String, Type> getAllFields(final String segmentKey, final Segment segment, final boolean useNames) throws HL7Exception {
final Map<String, Type> fields = new TreeMap<>();
final String[] segmentNames = segment.getNames();
for (int i = 1; i <= segment.numFields(); i++) {
final Type field = segment.getField(i, 0);
if (!isEmpty(field)) {
final String fieldName;
if (useNames) {
fieldName = WordUtils.capitalize(segmentNames[i - 1]).replaceAll("\\W+", "");
} else {
fieldName = String.valueOf(i);
}
final String fieldKey = new StringBuilder().append(segmentKey).append(".").append(fieldName).toString();
fields.put(fieldKey, field);
}
}
return fields;
}
use of ca.uhn.hl7v2.HL7Exception 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.HL7Exception 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;
}
Aggregations