use of ca.uhn.hl7v2.model.v25.segment.PV1 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.v25.segment.PV1 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.v25.segment.PV1 in project openmrs-core by openmrs.
the class ORUR01Handler method createEncounter.
/**
* This method does not call the database to create the encounter row. The encounter is only
* created after all obs have been attached to it Creates an encounter pojo to be attached
* later. This method does not create an encounterId
*
* @param msh
* @param patient
* @param pv1
* @param orc
* @return
* @throws HL7Exception
*/
private Encounter createEncounter(MSH msh, Patient patient, PV1 pv1, ORC orc) throws HL7Exception {
// the encounter we will return
Encounter encounter;
// look for the encounter id in PV1-19
CX visitNumber = pv1.getVisitNumber();
Integer encounterId = null;
try {
encounterId = Integer.valueOf(visitNumber.getIDNumber().getValue());
} catch (NumberFormatException e) {
// pass
}
// the database
if (encounterId != null) {
encounter = Context.getEncounterService().getEncounter(encounterId);
} else {
// if no encounter_id was passed in, this is a new
// encounter, create the object
encounter = new Encounter();
Date encounterDate = getEncounterDate(pv1);
Provider provider = getProvider(pv1);
Location location = getLocation(pv1);
Form form = getForm(msh);
EncounterType encounterType = getEncounterType(msh, form);
User enterer = getEnterer(orc);
// Date dateEntered = getDateEntered(orc); // ignore this since we have no place in the data model to store it
encounter.setEncounterDatetime(encounterDate);
if (unknownRole == null) {
unknownRole = Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
}
encounter.setProvider(unknownRole, provider);
encounter.setPatient(patient);
encounter.setLocation(location);
encounter.setForm(form);
encounter.setEncounterType(encounterType);
encounter.setCreator(enterer);
encounter.setDateCreated(new Date());
}
return encounter;
}
use of ca.uhn.hl7v2.model.v25.segment.PV1 in project openmrs-core by openmrs.
the class ORUR01Handler method getProvider.
private Provider getProvider(PV1 pv1) throws HL7Exception {
XCN hl7Provider = pv1.getAttendingDoctor(0);
Provider provider = null;
String id = hl7Provider.getIDNumber().getValue();
String assignAuth = hl7Provider.getAssigningAuthority().getUniversalID().getValue();
String type = hl7Provider.getAssigningAuthority().getUniversalIDType().getValue();
String errorMessage;
if (StringUtils.hasText(id)) {
String specificErrorMsg = "";
if (OpenmrsUtil.nullSafeEquals("L", type)) {
if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_ID.equalsIgnoreCase(assignAuth)) {
try {
provider = Context.getProviderService().getProvider(Integer.valueOf(id));
} catch (NumberFormatException e) {
// ignore
}
specificErrorMsg = "with provider Id";
} else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_IDENTIFIER.equalsIgnoreCase(assignAuth)) {
provider = Context.getProviderService().getProviderByIdentifier(id);
specificErrorMsg = "with provider identifier";
} else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_UUID.equalsIgnoreCase(assignAuth)) {
provider = Context.getProviderService().getProviderByUuid(id);
specificErrorMsg = "with provider uuid";
}
} else {
try {
Person person = Context.getPersonService().getPerson(Integer.valueOf(id));
Collection<Provider> providers = Context.getProviderService().getProvidersByPerson(person);
if (!providers.isEmpty()) {
provider = providers.iterator().next();
}
} catch (NumberFormatException e) {
// ignore
}
specificErrorMsg = "associated to a person with person id";
}
errorMessage = "Could not resolve provider " + specificErrorMsg + ":" + id;
} else {
errorMessage = "No unique identifier was found for the provider";
}
if (provider == null) {
throw new HL7Exception(errorMessage);
}
return provider;
}
use of ca.uhn.hl7v2.model.v25.segment.PV1 in project openmrs-core by openmrs.
the class HL7ServiceTest method resolveLocationId_shouldReturnNullIfLocationIdAndNameAreIncorrect.
/**
* @throws HL7Exception
* @see HL7Service#resolveLocationId(ca.uhn.hl7v2.model.v25.datatype.PL)
*/
@Test
public void resolveLocationId_shouldReturnNullIfLocationIdAndNameAreIncorrect() throws HL7Exception {
executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml");
HL7Service hl7service = Context.getHL7Service();
Message message = hl7service.parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "NK1|1|Hornblower^Horatio^L|2B^Sibling^99REL||||||||||||M|19410501|||||||||||||||||1000^^^L^PN||||\r" + "PV1||O|99999^0^0^0&Unknown&0||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212");
ORU_R01 oru = (ORU_R01) message;
PV1 pv1 = oru.getPATIENT_RESULT().getPATIENT().getVISIT().getPV1();
Assert.assertNotNull("PV1 parsed as null", pv1);
PL hl7Location = pv1.getAssignedPatientLocation();
Integer locationId = hl7service.resolveLocationId(hl7Location);
Assert.assertNull(locationId);
}
Aggregations