/** * @throws HL7Exception * @see HL7Service#processHL7InQueue(HL7InQueue) */ @Test public void processHL7InQueue_shouldCreateHL7InErrorAfterFailedParsing() throws HL7Exception { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); // sanity check, make sure there aren't any error items HL7Service hl7service = Context.getHL7Service(); Assert.assertEquals(0, hl7service.getAllHL7InErrors().size()); HL7InQueue queueItem = hl7service.getHL7InQueue(2); hl7service.processHL7InQueue(queueItem); Assert.assertEquals(1, hl7service.getAllHL7InErrors().size()); }
/** * @throws HL7Exception * @see HL7Service#createPersonFromNK1(NK1) */ @Test(expected = HL7Exception.class) public void getPersonFromNK1_shouldFailIfNoBirthdateSpecified() 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||||||||||||||||||2178037d-f86b-4f12-8d8b-be3ebc220022^^^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); hl7service.createPersonFromNK1(nk1List.get(0)); Assert.fail("should have thrown an exception"); }
/** * @throws HL7Exception * @throws IOException * @see HL7Service#processHL7InQueue(HL7InQueue) */ @Test public void processHL7InQueue_shouldCreateHL7InArchiveAfterSuccessfulParsing() throws HL7Exception, IOException { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); File tempDir = new File(System.getProperty("java.io.tmpdir"), HL7Constants.HL7_ARCHIVE_DIRECTORY_NAME); if (tempDir.exists() && tempDir.isDirectory()) Assert.assertEquals(true, OpenmrsUtil.deleteDirectory(tempDir)); //set a global property for the archives directory as a temporary folder GlobalProperty gp = new GlobalProperty(); gp.setProperty(OpenmrsConstants.GLOBAL_PROPERTY_HL7_ARCHIVE_DIRECTORY); gp.setPropertyValue(tempDir.getAbsolutePath()); gp.setDescription("temp test dir"); Context.getAdministrationService().saveGlobalProperty(gp); HL7Service hl7service = Context.getHL7Service(); Assert.assertEquals(0, hl7service.getAllHL7InArchives().size()); HL7InQueue queueItem = hl7service.getHL7InQueue(1); hl7service.processHL7InQueue(queueItem); Assert.assertEquals(1, hl7service.getAllHL7InArchives().size()); }
Context.getHL7Service().processHL7InQueue(hl7InQueue); Context.getHL7Service().garbageCollect();
/** * @throws HL7Exception * @see HL7Service#processHL7InQueue(HL7InQueue) */ @Test(expected = HL7Exception.class) public void processHL7InQueue_shouldFailIfGivenInQueueIsAlreadyMarkedAsProcessing() throws HL7Exception { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); HL7Service hl7service = Context.getHL7Service(); HL7InQueue queueItem = hl7service.getHL7InQueue(1); queueItem.setMessageState(HL7Constants.HL7_STATUS_PROCESSING); // set this to processing hl7service.processHL7InQueue(queueItem); }
Assert.assertEquals(0, service.getAllHL7InQueues().size()); Assert.assertEquals(0, service.getAllHL7InErrors().size()); Assert.assertEquals(0, service.getAllHL7InArchives().size()); Assert.assertEquals(1, service.getAllHL7InQueues().size()); Assert.assertEquals(0, service.getAllHL7InErrors().size()); Assert.assertEquals(0, service.getAllHL7InArchives().size()); service.processHL7InQueue(service.getAllHL7InQueues().get(0)); Assert.assertEquals(0, service.getAllHL7InQueues().size()); Assert.assertEquals(0, service.getAllHL7InErrors().size()); Assert.assertEquals(1, service.getAllHL7InArchives().size());
/** * @throws HL7Exception * @see HL7Service#resolvePersonFromIdentifiers(null) */ @Test public void resolvePersonFromIdentifiers_shouldReturnNullIfNoPersonIsFound() 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|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); Assert.assertEquals("too many NK1s parsed out", 1, nk1List.size()); Person result = hl7service.resolvePersonFromIdentifiers(nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers()); Assert.assertNull("should not have found a person", result); }
Message parsedMessage = Context.getHL7Service().parseHL7String(hl7Message); Context.getHL7Service().processHL7Message(parsedMessage); Context.getHL7Service().saveHL7InArchive(new HL7InArchive(hl7InQueue)); Context.getHL7Service().purgeHL7InQueue(hl7InQueue);
/** * @throws HL7Exception * @see HL7Service#resolveLocationId(ca.uhn.hl7v2.model.v25.datatype.PL) */ @Test public void resolveLocationId_shouldReturnInternalIdentifierOfLocationIfOnlyLocationNameIsSpecified() 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&Test Location&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.assertEquals("Resolved and given locationId shoud be equals", Integer.valueOf(1), locationId); }
/** * @throws HL7Exception * @see HL7Service#resolveUserId(ca.uhn.hl7v2.model.v25.datatype.XCN) */ @Test public void resolveUserId_shouldReturnUserUsingFirstAndLastNameGivenUserIDIsNull() 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|^Otterbourg^Bruno\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(501)); }
/** * @throws HL7Exception * @see HL7Service#getUuidFromIdentifiers(null) */ @Test public void getUuidFromIdentifiers_shouldNotFailIfNoAssigningAuthorityIsFound() 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|||||||||||||||||5^^^^PT||||\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); }
/** * @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()); }
@Override public IncomingHl7Message1_8 newObject() { HL7InQueue msg = new HL7InQueue(); msg.setHL7Data("hl7Data"); msg.setHL7SourceKey("sourceKey"); msg.setHL7Source(Context.getHL7Service().getHL7SourceByName(RestTestConstants1_8.HL7_SOURCE_NAME)); Context.getHL7Service().saveHL7InQueue(msg); return new IncomingHl7Message1_8(msg); }
/** * @see HL7Service#saveHL7InQueue(HL7InQueue) */ @Test public void saveHL7InQueue_shouldAddGeneratedUuidIfUuidIsNull() { HL7InQueue hl7 = new HL7InQueue(); hl7.setHL7Data("dummy data"); hl7.setHL7Source(new HL7Source(1)); hl7.setHL7SourceKey("a random key"); hl7.setMessageState(HL7Constants.HL7_STATUS_PROCESSING); Context.getHL7Service().saveHL7InQueue(hl7); Assert.assertNotNull(hl7.getUuid()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public HL7Source getByUniqueId(String uniqueId) { return Context.getHL7Service().getHL7SourceByName(uniqueId); }
/** * gets a relative based on an NK1 segment * * @param nk1 an NK1 segment from the HL7 request * @return a matching Person or null if not found * @throws HL7Exception */ private Person getRelative(NK1 nk1) throws HL7Exception { // if there are no associated party identifiers, the person will not exist if (nk1.getNextOfKinAssociatedPartySIdentifiers().length < 1) { return null; } // find the related person via given IDs return Context.getHL7Service().resolvePersonFromIdentifiers(nk1.getNextOfKinAssociatedPartySIdentifiers()); }
private Location getLocation(PV1 pv1) throws HL7Exception { PL hl7Location = pv1.getAssignedPatientLocation(); Integer locationId = Context.getHL7Service().resolveLocationId(hl7Location); if (locationId == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedLocation")); } return Context.getLocationService().getLocation(locationId); }
/** * @throws HL7Exception * @see HL7Service#parseHL7String(String) */ @Test public void parseHL7String_shouldParseTheGivenStringIntoMessage() 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" + "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"); Assert.assertNotNull(message); }
relative = Context.getHL7Service().createPersonFromNK1(nk1); if (relative == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.relativeNotCreated"));
/** * @throws HL7Exception * @see HL7Service#resolvePersonFromIdentifiers(null) */ @Test public void resolvePersonFromIdentifiers_shouldFindAPersonBasedOnAPatientIdentifier() 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|||||||||||||||||1234^^^Test Identifier Type^PT||||\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); Assert.assertEquals("too many NK1s parsed out", 1, nk1List.size()); Person result = hl7service.resolvePersonFromIdentifiers(nk1List.get(0).getNextOfKinAssociatedPartySIdentifiers()); Assert.assertNotNull("should have found a person", result); Assert.assertEquals("found the wrong person", 2, result.getId().intValue()); }