Skip to content

Commit

Permalink
Back porting to 1.9.x: Handle complex observations (ED) in ORUR01Handler
Browse files Browse the repository at this point in the history
- TRUNK-3887
  • Loading branch information
wluyima authored and dkayiwa committed Feb 19, 2013
1 parent 840e55c commit c81a72c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
28 changes: 27 additions & 1 deletion api/src/main/java/org/openmrs/hl7/handler/ORUR01Handler.java
Expand Up @@ -47,6 +47,7 @@
import org.openmrs.hl7.HL7Constants;
import org.openmrs.hl7.HL7InQueueProcessor;
import org.openmrs.hl7.HL7Service;
import org.openmrs.obs.ComplexData;
import org.openmrs.util.OpenmrsConstants;
import org.openmrs.util.OpenmrsUtil;
import org.springframework.util.StringUtils;
Expand All @@ -64,6 +65,7 @@
import ca.uhn.hl7v2.model.v25.datatype.DLD;
import ca.uhn.hl7v2.model.v25.datatype.DT;
import ca.uhn.hl7v2.model.v25.datatype.DTM;
import ca.uhn.hl7v2.model.v25.datatype.ED;
import ca.uhn.hl7v2.model.v25.datatype.FT;
import ca.uhn.hl7v2.model.v25.datatype.ID;
import ca.uhn.hl7v2.model.v25.datatype.IS;
Expand Down Expand Up @@ -136,6 +138,7 @@ public boolean canProcess(Message message) {
* @should create an encounter and find the provider by uuid
* @should create an encounter and find the provider by providerId
* @should fail if the provider name type code is not specified and is not a personId
* @should set complex data for obs with complex concepts
*/
public Message processMessage(Message message) throws ApplicationException {

Expand Down Expand Up @@ -767,6 +770,22 @@ else if (concept.getDatatype().isCoded()) {
return null;
}
obs.setValueText(value.getValue());
} else if ("ED".equals(hl7Datatype)) {
ED value = (ED) obx5;
if (value == null || value.getData() == null || !StringUtils.hasText(value.getData().getValue())) {
log.warn("Not creating null valued obs for concept " + concept);
return null;
}
//we need to hydrate the concept so that the EncounterSaveHandler
//doesn't fail since it needs to check if it is a concept numeric
Concept c = Context.getConceptService().getConcept(obs.getConcept().getConceptId());
obs.setConcept(c);
String title = null;
if (obs.getValueCodedName() != null)
title = obs.getValueCodedName().getName();
if (!StringUtils.hasText(title))
title = c.getName().getName();
obs.setComplexData(new ComplexData(title, value.getData().getValue()));
} else {
// unsupported data type
// TODO: support RP (report), SN (structured numeric)
Expand Down Expand Up @@ -1062,7 +1081,14 @@ private Location getLocation(PV1 pv1) throws HL7Exception {
location.setLocationId(locationId);
return location;
}


/**
* needs to find a Form based on information in MSH-21. example: 16^AMRS.ELD.FORMID
*
* @param msh
* @return
* @throws HL7Exception
*/
private Form getForm(MSH msh) throws HL7Exception {
Integer formId = null;
try {
Expand Down
58 changes: 58 additions & 0 deletions api/src/test/java/org/openmrs/hl7/handler/ORUR01HandlerTest.java
Expand Up @@ -38,13 +38,15 @@
import org.openmrs.Provider;
import org.openmrs.Relationship;
import org.openmrs.RelationshipType;
import org.openmrs.api.APIException;
import org.openmrs.api.ConceptService;
import org.openmrs.api.EncounterService;
import org.openmrs.api.ObsService;
import org.openmrs.api.PersonService;
import org.openmrs.api.ProviderService;
import org.openmrs.api.context.Context;
import org.openmrs.hl7.HL7Constants;
import org.openmrs.obs.ComplexObsHandler;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.Verifies;
import org.openmrs.util.OpenmrsConstants;
Expand Down Expand Up @@ -1097,4 +1099,60 @@ public void processMessage_shouldFailIfTheProviderNameTypeCodeIsNotSpecifiedAndI
Message hl7message = parser.parse(hl7string);
router.processMessage(hl7message);
}

/**
* @see {@link ORUR01Handler#processMessage(Message)}
*
*/
@Test
@Verifies(value = "should set complex data for obs with complex concepts", method = "processMessage(Message)")
public void processMessage_shouldSetComplexDataForObsWithComplexConcepts() throws Exception {
ObsHandler handler = new ObsHandler();
final String handlerName = "NeigborHandler";
final String data = "{\"firstname\":\"Horatio\"}";
Context.getObsService().registerHandler(handlerName, handler);
try {
String hl7string = "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|ED|6043^uiNEIHBOR^99DCT||^^^^" + data + "|||||||||20080206\r";
Message hl7message = parser.parse(hl7string);
router.processMessage(hl7message);
}
finally {
Context.getObsService().removeHandler(handlerName);
}
Assert.assertEquals(data, handler.getCreatedObs().getComplexData().getData());
}

private class ObsHandler implements ComplexObsHandler {

private Obs createdObs;

/**
* @return the createdObs
*/
public Obs getCreatedObs() {
return createdObs;
}

@Override
public Obs saveObs(Obs obs) throws APIException {
createdObs = obs;
return obs;
}

@Override
public Obs getObs(Obs obs, String view) {
return null;
}

@Override
public boolean purgeComplexData(Obs obs) {
return false;
}

}
}
Expand Up @@ -60,8 +60,11 @@

<concept concept_id="1284" retired="false" datatype_id="4" class_id="11" is_set="false" creator="1" date_created="2005-02-24 12:33:10.0" version="" uuid="b16cf212-e9ac-4127-a4db-7f03b37584e2"/>
<concept concept_id="6042" retired="false" datatype_id="2" class_id="4" is_set="false" creator="1" date_created="2004-08-12 00:00:00.0" version="" changed_by="1" date_changed="2005-02-22 12:18:13.0" uuid="9b68403d-8c7e-4961-8952-2da8f249a155"/>
<concept concept_id="6043" retired="false" datatype_id="13" class_id="7" is_set="false" creator="1" date_created="2004-08-12 00:00:00.0" uuid="8b68403d-8c7e-4961-8952-2da8f249a156"/>
<concept_complex concept_id="6043" handler="NeigborHandler" />
<concept_name concept_id="1284" name="PROBLEM LIST" locale="en" creator="1" date_created="2005-02-24 12:33:10.0" concept_name_id="1285" voided="0" uuid="c0b3cfd5-3c85-4c47-bb39-2d3e2a6ab00e" concept_name_type="FULLY_SPECIFIED" locale_preferred="0"/>
<concept_name concept_id="6042" name="PROBLEM ADDED" locale="en" creator="1" date_created="2004-08-12 00:00:00.0" concept_name_id="2394" voided="0" uuid="8c067348-5bf2-4050-b824-0aa009436ed5" concept_name_type="FULLY_SPECIFIED" locale_preferred="0"/>
<concept_name concept_id="6043" name="NEIGHBOR" locale="en" creator="1" date_created="2004-08-12 00:00:00.0" concept_name_id="2395" voided="0" uuid="9c067348-5bf2-4050-b824-0aa009436ed6" concept_name_type="FULLY_SPECIFIED" locale_preferred="0"/>

<hl7_in_queue hl7_in_queue_id="1" hl7_source="1" hl7_source_key="asdf" message_state="0" date_created="2004-08-12 00:00:00.0" uuid="bbbb7348-5bf2-4050-b824-0aa009499999" hl7_data="MSH|^~\&amp;|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID&#xD;PID|||3^^^^||John3^Doe^||&#xD;PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V&#xD;ORC|RE||||||||20080226102537|1^Super User&#xD;OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT&#xD;OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206&#xD;OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212" />

Expand Down

0 comments on commit c81a72c

Please sign in to comment.