private void saveObsGroup(Obs obs, String changeMessage){ if (obs.isObsGrouping()) { for (Obs o : obs.getGroupMembers(true)) { Context.getObsService().saveObs(o, changeMessage); } } }
/** * Convenience method to recursively get all leaf obs of this encounter. This method goes down * into each obs and adds all non-grouping obs to the return list * * @param obsParent current obs to loop over * @return list of leaf obs */ private List<Obs> getObsLeaves(Obs obsParent) { List<Obs> leaves = new ArrayList<>(); if (obsParent.hasGroupMembers()) { for (Obs child : obsParent.getGroupMembers()) { if (!child.getVoided()) { if (!child.isObsGrouping()) { leaves.add(child); } else { // recurse if this is a grouping obs leaves.addAll(getObsLeaves(child)); } } } } else if (!obsParent.getVoided()) { leaves.add(obsParent); } return leaves; }
if (this.isObsGrouping()) { ret.addAll(this.getGroupMembers()); Obs parentObs = this; while (parentObs.getObsGroup() != null) { for (Obs obsSibling : parentObs.getObsGroup().getGroupMembers()) { if (!obsSibling.isObsGrouping()) { ret.add(obsSibling); if (!obsSibling.isObsGrouping()) { ret.add(obsSibling);
private Obs saveObsNotDirty(Obs obs, String changeMessage) { if(!obs.isObsGrouping()){ return obs; } ObsService os = Context.getObsService(); boolean refreshNeeded = false; for (Obs o : obs.getGroupMembers(true)) { if (o.getId() == null) { os.saveObs(o, null); } else { Obs newObs = os.saveObs(o, changeMessage); refreshNeeded = !newObs.equals(o) || refreshNeeded; } } if(refreshNeeded) { Context.refreshEntity(obs); } return obs; }
/** * @see Obs#isObsGrouping() */ @Test public void isObsGrouping_shouldIncludeVoidedObs() throws Exception { Obs parent = new Obs(5); Obs child = new Obs(33); child.setVoided(true); parent.addGroupMember(child); assertTrue("When checking for Obs grouping, should include voided Obs", parent.isObsGrouping()); }
/** * @see Encounter#getObs() */ @Test public void getObs_shouldOnlyGetChildObs() { Encounter encounter = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); encounter.addObs(parentObs); //add a child to the obs and make sure that the Obs is an ObsGroup with one child: Obs childObs = new Obs(); parentObs.addGroupMember(childObs); //obsGroup should recurse and ONLY the child obs should be picked up: assertEquals(1, encounter.getObs().size()); // make sure that the obs is the oChild Obs obsInEncounter = (Obs) encounter.getObs().toArray()[0]; assertTrue(childObs.equals(obsInEncounter)); assertFalse(obsInEncounter.isObsGrouping()); }
/** * @see Encounter#getObs() */ @Test public void getObs_shouldNotGetChildObsIfChildAlsoOnEncounter() { Encounter encounter = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); encounter.addObs(parentObs); //add a child to the obs and make sure that now that the Obs is an ObsGroup with one child: Obs childObs = new Obs(); parentObs.addGroupMember(childObs); // add the child obs directly to the encounter as well childObs.setEncounter(encounter); encounter.addObs(childObs); // do the check assertEquals(1, encounter.getObs().size()); Obs obsInEncounter = (Obs) encounter.getObs().toArray()[0]; assertFalse(obsInEncounter.isObsGrouping()); }
/** * @see Encounter#getObsAtTopLevel(null) */ @Test public void getObsAtTopLevel_shouldOnlyReturnTheGroupedTopLevelObs() { Encounter encounter = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); encounter.addObs(parentObs); //add a child to the obs and make sure that now that the Obs is an ObsGroup with one child: Obs childObs = new Obs(); parentObs.addGroupMember(childObs); // add the child obs directly to the encounter as well childObs.setEncounter(encounter); encounter.addObs(childObs); // do the check assertEquals(1, encounter.getObsAtTopLevel(false).size()); Obs obsInEncounter = (Obs) encounter.getObsAtTopLevel(false).toArray()[0]; assertTrue(obsInEncounter.isObsGrouping()); }
/** * @see Encounter#getAllObs(null) */ @Test public void getAllObs_shouldGetBothParentAndChildObs() { Encounter encounter = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); encounter.addObs(parentObs); //add a child to the obs and make sure that the Obs is an ObsGroup with one child: Obs childObs = new Obs(); parentObs.addGroupMember(childObs); //assert that the parent obs is returned assertNotNull(encounter.getAllObs(true)); assertEquals(1, encounter.getAllObs(true).size()); assertNotNull(encounter.getAllObs(false)); assertEquals(1, encounter.getAllObs(false).size()); Obs obsInEncounter = (Obs) encounter.getAllObs(false).toArray()[0]; assertTrue(obsInEncounter.isObsGrouping()); }
/** * @see Encounter#getObsAtTopLevel(null) */ @Test public void getObsAtTopLevel_shouldOnlyGetParentsObs() { Encounter encounter = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); encounter.addObs(parentObs); //add a child to the obs and make sure that the Obs is an ObsGroup with one child: Obs childObs = new Obs(); parentObs.addGroupMember(childObs); //assert that the parent obs is returned by getObsAtTopLevel() assertNotNull(encounter.getObsAtTopLevel(true)); assertEquals(1, encounter.getObsAtTopLevel(true).size()); assertNotNull(encounter.getObsAtTopLevel(false)); assertEquals(1, encounter.getObsAtTopLevel(false).size()); // make sure that the obs is the parent obs Obs obsInEncounter = (Obs) encounter.getObsAtTopLevel(false).toArray()[0]; assertTrue(obsInEncounter.isObsGrouping()); }
while (newObservation == null && thisIndex < newList.size()) { Obs newObs = newList.get(thisIndex++); if (!oldList.contains(newObs) && !newObs.isObsGrouping() && newObs.getComment() != null) newObservation = newObs;
/** * @see ORUR01Handler#parseObs(Encounter,OBX,OBR,String) */ @Test public void parseObs_shouldAddCommentsToAnObservationGroup() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||23^FOOD CONSTRUCT^99DCT\r" + "NTE|1|L|This is a comment\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||1|||||||||20080206\r" + "NTE|1|L|This should not be considered :-)"; List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(23)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(23)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals("This is a comment", newObservation.getComment()); }
assertFalse(oTmp.isObsGrouping());
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumeric() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\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"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(450, newObservation.getValueNumeric().intValue()); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumericAndTheAnswerIsEither0Or1() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\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||1|||||||||20080206"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(1, newObservation.getValueNumeric().intValue()); }
int numberofParentObs = 0; for (Obs oTmp : enc.getAllObs(false)) { if (oTmp.isObsGrouping()) numberofParentObs++; else
/** * @see ORUR01Handler#parseObs(Encounter,OBX,OBR,String) */ @Test public void parseObs_shouldAddCommentsToAnObservationFromNTESegments() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\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||1|||||||||20080206\r" + "NTE|1|L|This is a comment"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals("This is a comment", newObservation.getComment()); }
assertFalse(obsGroup.isObsGrouping()); assertFalse(obsGroup.hasGroupMembers(false)); assertFalse(obsGroup.hasGroupMembers(true)); // Check both flags for false
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_CodedMatchingABooleanConceptForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsCoded() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\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|2|NM|21^CIVIL STATUS^99DCT||1|||||||||20080206"; // the expected question for the obs in the hl7 message has to be coded Assert.assertEquals("Coded", Context.getConceptService().getConcept(21).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); // hacky way to get the newly added obs and make tests on it List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(Context.getConceptService().getTrueConcept(), newObservation.getValueCoded()); }
Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs;