o.setLocation(getLocation());
obsExit.setLocation(loc); } else { log.error("Could not find a suitable location for which to create this new Obs");
Location location = Context.getLocationService().getDefaultLocation(); if (location != null) { obsDeath.setLocation(location); } else { log.error("Could not find a suitable location for which to create this new Obs");
private Obs buildObs() { Obs newObs = new Obs(); newObs.setConcept(Context.getConceptService().getConcept(1)); newObs.setValueNumeric(50d); newObs.setLocation(new Location(2)); return newObs; }
ob.setDateCreated(new Date()); ob.setObsDatetime(cp.getEncounter().getEncounterDatetime()); ob.setLocation(cp.getEncounter().getLocation()); ob.setPerson(cp.getEncounter().getPatient()); if (ob.getUuid() == null) {
o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); ConceptName cn1 = new ConceptName(1847); o.setValueCodedName(cn1); o2.setEncounter(new Encounter(3)); o2.setObsDatetime(new Date()); o2.setLocation(new Location(1)); ConceptName cn2 = new ConceptName(2453); o2.setValueCodedName(cn2);
o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); ConceptName cn1 = new ConceptName(1847); o.setValueCodedName(cn1); o2.setEncounter(new Encounter(3)); o2.setObsDatetime(new Date()); o2.setLocation(new Location(1)); ConceptName cn2 = new ConceptName(2453); o2.setValueCodedName(cn2);
o.setLocation(new Location(1)); o.setObsDatetime(new Date()); o.setPerson(new Patient(2)); oSibling.setLocation(new Location(1)); oSibling.setObsDatetime(new Date()); oSibling.setValueText("childObs2"); oParent.setLocation(new Location(1)); oParent.setObsDatetime(new Date()); oSibling.setValueText("parentObs"); oGrandparent.setLocation(new Location(1)); oGrandparent.setObsDatetime(new Date()); oGrandparent.setPerson(new Patient(2)); o2.setLocation(new Location(1)); o2.setObsDatetime(new Date()); o2.setPerson(new Patient(2)); oGGP.setLocation(new Location(1)); oGGP.setObsDatetime(new Date()); oGGP.setPerson(new Patient(2)); oGGPleaf.setLocation(new Location(1)); oGGPleaf.setObsDatetime(new Date()); oGGPleaf.setPerson(new Patient(2));
/** * @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())); }
obs.setLocation(newLocation);
o1.setDateCreated(newDate); o1.setCreator(Context.getAuthenticatedUser()); o1.setLocation(new Location(1)); o1.setObsDatetime(newDate); o1.setValueText("NewObs Value");
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldCascadeSaveToChildObsGroups() { ObsService obsService = Context.getObsService(); Obs parentObs = new Obs(); parentObs.setConcept(Context.getConceptService().getConcept(3)); parentObs.setObsDatetime(new Date()); parentObs.setPerson(new Patient(2)); parentObs.setLocation(new Location(1)); Obs groupMember = new Obs(); groupMember.setConcept(Context.getConceptService().getConcept(3)); groupMember.setValueNumeric(1.0); groupMember.setObsDatetime(new Date()); groupMember.setPerson(new Patient(2)); groupMember.setLocation(new Location(1)); parentObs.addGroupMember(groupMember); obsService.saveObs(parentObs, null); // make sure the child obs was saved Assert.assertNotNull(groupMember.getObsId()); }
groupMember.setObsDatetime(new Date()); groupMember.setPerson(new Patient(2)); groupMember.setLocation(new Location(2)); groupMember.setValueNumeric(50d); origParentObs.addGroupMember(groupMember);
@Test public void saveEncounter_shouldSaveEncounterWithComplexObs() { executeDataSet(ENC_OBS_HIERARCHY_DATA_XML); EncounterService es = Context.getEncounterService(); Encounter encounter = es.getEncounter(101); Obs observation = buildObs(); observation.setLocation(encounter.getLocation()); observation.setPerson(encounter.getPatient()); encounter.addObs(observation); es.saveEncounter(encounter); Context.flushSession(); Context.clearSession(); encounter = es.getEncounter(101); assertEquals(2, encounter.getObsAtTopLevel(true).size()); }
@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()))); }
/** * @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()); }
/** * @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); }
/** * When you save the encounter with a changed location, the location change should be cascaded * to all the obs associated with the encounter that had the same location as the encounter. * * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldCascadeChangeOfLocationInEncounterToContainedObs() { EncounterService es = Context.getEncounterService(); Encounter enc = buildEncounter(); es.saveEncounter(enc); // Now add an obs to it Obs newObs = new Obs(); newObs.setConcept(Context.getConceptService().getConcept(1)); newObs.setValueNumeric(50d); Location location = new Location(1); newObs.setLocation(location); enc.addObs(newObs); es.saveEncounter(enc); enc.setLocation(location); es.saveEncounter(enc); assertEquals(enc.getLocation(), newObs.getLocation()); }
o.setDateCreated(new Date()); o.setCreator(Context.getAuthenticatedUser()); o.setLocation(new Location(1)); o.setObsDatetime(new Date()); o.setPerson(new Patient(2)); o2.setDateCreated(new Date()); o2.setCreator(Context.getAuthenticatedUser()); o2.setLocation(new Location(1)); o2.setObsDatetime(new Date()); o2.setValueText("second obs value text"); oParent.setDateCreated(new Date()); oParent.setCreator(Context.getAuthenticatedUser()); oParent.setLocation(new Location(1)); oParent.setObsDatetime(new Date()); oParent.setPerson(new Patient(2)); oGP.setDateCreated(new Date()); oGP.setCreator(Context.getAuthenticatedUser()); oGP.setLocation(new Location(1)); oGP.setObsDatetime(new Date()); oGP.setPerson(new Patient(2)); o3.setDateCreated(new Date()); o3.setCreator(Context.getAuthenticatedUser()); o3.setLocation(new Location(1)); o3.setObsDatetime(new Date()); o3.setValueText("leaf obs value text");
obs.setEncounter(encounter); obs.setObsDatetime(datetime); obs.setLocation(location); obs.setValueGroupId(valueGroupId); obs.setValueDatetime(valueDatetime);