use of ca.uhn.hl7v2.model.v25.segment.PID in project openmrs-core by openmrs.
the class ADTA28Handler method processADT_A28.
private Message processADT_A28(ADT_A05 adt) throws HL7Exception {
// validate HL7 version
validate(adt);
// extract segments for convenient use below
MSH msh = getMSH(adt);
PID pid = getPID(adt);
// Obtain message control id (unique ID for message from sending
// application). Eventually avoid replaying the same message.
String messageControlId = msh.getMessageControlID().getValue();
log.debug("Found HL7 message in inbound queue with control id = " + messageControlId);
// Add creator of the patient to application
String sendingApp = msh.getSendingApplication().getComponent(0).toString();
log.debug("SendingApplication = " + sendingApp);
// Search for the patient
Integer patientId = findPatientId(pid);
// Create new patient if the patient id doesn't exist yet
if (patientId == null) {
log.info("Creating new patient in response to ADT_A28 " + messageControlId);
Patient patient = createPatient(pid, sendingApp);
if (patient == null) {
throw new HL7Exception("Couldn't create Patient object from PID");
}
Context.getPatientService().savePatient(patient);
} else {
log.info("Ignoring ADT_A28 message because patient (" + patientId + ") already exists.");
}
return adt;
}
use of ca.uhn.hl7v2.model.v25.segment.PID in project openmrs-core by openmrs.
the class HL7ServiceTest method resolveUserId_shouldReturnUserUsingUsername.
/**
* @throws HL7Exception
* @see HL7Service#resolveUserId(ca.uhn.hl7v2.model.v25.datatype.XCN)
*/
@Test
public void resolveUserId_shouldReturnUserUsingUsername() throws HL7Exception {
HL7Service hl7service = Context.getHL7Service();
// construct a message such that id Number at ORC is null
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" + "ORC|RE||||||||20080226102537|^butch\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;
ORC orc = oru.getPATIENT_RESULT().getORDER_OBSERVATION().getORC();
XCN xcn = orc.getEnteredBy(0);
Integer userId = hl7service.resolveUserId(xcn);
assertThat(userId, is(502));
}
use of ca.uhn.hl7v2.model.v25.segment.PID 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);
}
use of ca.uhn.hl7v2.model.v25.segment.PID in project openmrs-core by openmrs.
the class HL7ServiceTest method processHL7Message_shouldSaveHl7MessageToTheDatabase.
/**
* @throws HL7Exception
* @see HL7Service#processHL7Message(Message)
*/
@Test
public void processHL7Message_shouldSaveHl7MessageToTheDatabase() 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" + "PV1||O|1^Unknown Location||||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");
Message result = hl7service.processHL7Message(message);
Assert.assertNotNull(result);
Concept returnVisitDateConcept = new Concept(5096);
Calendar cal = Calendar.getInstance();
cal.set(2008, Calendar.FEBRUARY, 29, 0, 0, 0);
List<Obs> returnVisitDateObsForPatient3 = Context.getObsService().getObservationsByPersonAndConcept(new Patient(3), returnVisitDateConcept);
assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient3.size());
}
use of ca.uhn.hl7v2.model.v25.segment.PID in project openmrs-core by openmrs.
the class HL7ServiceTest method getUuidFromIdentifiers_shouldFailIfMultipleDifferentUUIDsExistInIdentifiers.
/**
* @throws HL7Exception
* @see HL7Service#getUuidFromIdentifiers(null)
*/
@Test(expected = HL7Exception.class)
public void getUuidFromIdentifiers_shouldFailIfMultipleDifferentUUIDsExistInIdentifiers() throws HL7Exception {
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|||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220022^^^UUID^v4~2178037d-f86b-4f12-8d8b-be3ebc220023^^^UUID^v4||||\r" + "PV1||O|1^Unknown Location||||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;
List<NK1> nk1List = new ORUR01Handler().getNK1List(oru);
CX[] identifiers = nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers();
hl7service.getUuidFromIdentifiers(identifiers);
Assert.fail("should have failed");
}
Aggregations