/** * @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_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping() { Encounter enc = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); enc.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(enc); enc.addObs(childObs); //remove the obsGrouping, so that both obs are now just children of the Encounter parentObs.removeGroupMember(childObs); assertEquals(2, enc.getAllObs(true).size()); }
/** * @see Encounter#getObsAtTopLevel(null) */ @Test public void getObsAtTopLevel_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping() { Encounter enc = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); enc.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(enc); enc.addObs(childObs); //remove the obsGrouping, so that both obs are now just children of the Encounter parentObs.removeGroupMember(childObs); assertEquals(2, enc.getObsAtTopLevel(false).size()); }
/** * @see Encounter#getObs() */ @Test public void getObs_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping() { Encounter enc = new Encounter(); //create and add an Obs Obs parentObs = new Obs(); enc.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(enc); enc.addObs(childObs); //remove the obsGrouping, so that both obs are now just children of the Encounter parentObs.removeGroupMember(childObs); // do the check assertEquals(2, enc.getObs().size()); }
o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); o2.setConcept(Context.getConceptService().getConcept(3)); o2.setPerson(new Patient(2)); o2.setEncounter(new Encounter(3)); o2.setObsDatetime(new Date()); o2.setLocation(new Location(1));
o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); o2.setConcept(Context.getConceptService().getConcept(3)); o2.setPerson(new Patient(2)); o2.setEncounter(new Encounter(3)); o2.setObsDatetime(new Date()); o2.setLocation(new Location(1));
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldCreateVeryBasicObsAndAddNewObsId() { Obs o = new Obs(); o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); o.setValueNumeric(50d); Obs oSaved = Context.getObsService().saveObs(o, null); // make sure the returned Obs and the passed in obs // now both have primary key obsIds assertTrue(oSaved.getObsId().equals(o.getObsId())); }
childObs.setEncounter(enc); enc.addObs(childObs);
@Test public void saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs() { executeDataSet(ENC_OBS_HIERARCHY_DATA_XML); ConceptService cs = Context.getConceptService(); EncounterService es = Context.getEncounterService(); ObsService os = Context.getObsService(); Encounter enc = es.getEncounter(100); Obs o3 = new Obs(); o3.setConcept(cs.getConcept(3)); o3.setDateCreated(new Date()); o3.setCreator(Context.getAuthenticatedUser()); o3.setLocation(new Location(1)); o3.setObsDatetime(new Date()); o3.setPerson(Context.getPersonService().getPerson(3)); o3.setValueText("third obs value text"); o3.setEncounter(enc); Obs oParent = os.getObs(100); oParent.addGroupMember(o3); es.saveEncounter(enc); Context.flushSession(); Context.clearSession(); enc = es.getEncounter(100); Set<Obs> obsAtTopLevelUpdated = enc.getObsAtTopLevel(true); assertEquals(1,obsAtTopLevelUpdated.size()); assertEquals(3, obsAtTopLevelUpdated.iterator().next().getGroupMembers(true).size()); oParent = os.getObs(100); assertTrue(oParent.getGroupMembers(true).contains(os.getObs(101))); assertTrue(oParent.getGroupMembers(true).contains(os.getObs(102))); assertTrue(oParent.getGroupMembers(true).contains(os.getObs(o3.getObsId()))); }
childObs.setEncounter(enc); enc.addObs(childObs);
childObs.setEncounter(enc); enc.addObs(childObs);
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldAuditMovedIndependentObservations() throws Exception { //retrieve patients Patient preferred = patientService.getPatient(999); Patient notPreferred = patientService.getPatient(7); voidOrders(Collections.singleton(notPreferred)); //get an observation for notPreferred and make it independent from any encounter Obs obs = Context.getObsService().getObs(7); obs.setEncounter(null); obs.setComment("this observation is for testing the merge"); Context.getObsService().saveObs(obs, "Reason cannot be blank"); //merge the two patients and retrieve the audit object PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); String uuid = null; List<Obs> observations = Context.getObsService().getObservationsByPerson(preferred); for (Obs o : observations) { if (obs.getComment().equals(o.getComment())) { uuid = o.getUuid(); } } Assert.assertTrue("moving of independent observation was not audited", isValueInList(uuid, audit.getPersonMergeLogData().getMovedIndependentObservations())); }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldSetCreatorAndDateCreatedOnNewObs() { Obs o = new Obs(); o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); o.setValueNumeric(50d); Context.getObsService().saveObs(o, null); assertNotNull(o.getDateCreated()); assertNotNull(o.getCreator()); }
childObs.setEncounter(enc); enc.addObs(childObs);
/** * @see ConceptService#purgeConcept(Concept) */ @Test(expected = ConceptNameInUseException.class) public void purgeConcept_shouldFailIfAnyOfTheConceptNamesOfTheConceptIsBeingUsedByAnObs() { Obs o = new Obs(); o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); ConceptName conceptName = new ConceptName(1847); o.setValueCodedName(conceptName); Context.getObsService().saveObs(o, null); //ensure that the association between the conceptName and the obs has been established Assert.assertEquals(true, conceptService.hasAnyObservation(conceptName)); Concept concept = conceptService.getConceptByName("cd4 count"); //make sure the name concept name exists Assert.assertNotNull(concept); conceptService.purgeConcept(concept); }
obsCopy.setEncounter(target); obsCopy.setPerson(patient); target.addObs(obsCopy);
obs.setConcept(concept); obs.setPerson(patient); obs.setEncounter(encounter); obs.setObsDatetime(datetime); obs.setLocation(location);
newObs.setValueText(obsToCopy.getValueText()); newObs.setComment(obsToCopy.getComment()); newObs.setEncounter(obsToCopy.getEncounter()); newObs.setCreator(obsToCopy.getCreator()); newObs.setDateCreated(obsToCopy.getDateCreated());