/** * @see Obs#addGroupMember(Obs) */ @Test public void addGroupMember_shouldReturnFalseWhenADuplicateObsIsAddedAsAMemberToNewObs() throws Exception { Obs obs = new Obs(); Obs member = new Obs(); obs.addGroupMember(member); assertFalse(obs.isDirty()); resetObs(obs); obs.addGroupMember(member); assertFalse(obs.isDirty()); }
/** * @see Obs#addGroupMember(Obs) */ @Test public void addGroupMember_shouldReturnFalseWhenADuplicateObsIsAddedAsAMember() throws Exception { Obs obs = new Obs(2); Obs member = new Obs(); obs.addGroupMember(member); assertFalse(obs.isDirty()); resetObs(obs); obs.addGroupMember(member); assertFalse(obs.isDirty()); }
parentObs.addGroupMember(childObs); Obs greatGrandChildObsOne = new Obs(); Obs greatGrandChildObsTwo = new Obs(); childObs.addGroupMember(grandChildObsOne); childObs.addGroupMember(grandChildObsTwo); grandChildObsOne.addGroupMember(greatGrandChildObsOne); grandChildObsOne.addGroupMember(greatGrandChildObsTwo); greatGrandChildObsTwo.addGroupMember(greatGreatGrandChildObsOne); greatGrandChildObsTwo.addGroupMember(greatGreatGrandChildObsTwo);
/** * @see Obs#addGroupMember(Obs) */ @Test public void addGroupMember_shouldReturnFalseWhenANewObsIsAddedAsAMember() throws Exception { Obs obs = new Obs(2); Obs member1 = new Obs(); obs.addGroupMember(member1); assertFalse(obs.isDirty()); resetObs(obs); Obs member2 = new Obs(); obs.addGroupMember(member2); assertFalse(obs.isDirty()); }
/** * @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_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#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#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#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#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()); }
/** * @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()); }
/** * @see Obs#removeGroupMember(Obs) */ @Test public void removeGroupMember_shouldReturnDirtyFalseWhenAnObsIsRemoved() throws Exception { Obs obs = new Obs(2); Obs member = new Obs(); obs.addGroupMember(member); assertFalse(obs.isDirty()); resetObs(obs); obs.removeGroupMember(member); assertFalse(obs.isDirty()); }
/** * @see Obs#removeGroupMember(Obs) */ @Test public void removeGroupMember_shouldReturnFalseForDirtyFlagWhenAnObsIsRemovedFromGroup() throws Exception { Obs obs = new Obs(); Obs member = new Obs(); obs.addGroupMember(member); assertFalse(obs.isDirty()); resetObs(obs); obs.removeGroupMember(member); assertFalse(obs.isDirty()); }
/** * @see Obs#hasGroupMembers(boolean) */ @Test public void hasGroupMembers_shouldReturnTrueIfThisObsHasGroupMembersBasedOnParameter() throws Exception { Obs parent = new Obs(5); Obs child = new Obs(33); child.setVoided(true); parent.addGroupMember(child); // Only contains 1 voided child assertTrue("When checking for all members, should return true", parent.hasGroupMembers(true)); assertFalse("When checking for non-voided, should return false", parent.hasGroupMembers(false)); assertFalse("Default should check for non-voided", parent.hasGroupMembers()); }
groupMember.setLocation(new Location(2)); groupMember.setValueNumeric(50d); origParentObs.addGroupMember(groupMember); assertNotNull(groupMember.getObsGroup());
parentObs.addGroupMember(childObs);
/** * @see ObsValidator#validate(Object, Errors) */ @Test public void validate_shouldNotValidateAVoidedChildObs() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setObsDatetime(new Date()); Obs validChild = new Obs(); validChild.setPerson(Context.getPersonService().getPerson(2)); validChild.setConcept(Context.getConceptService().getConcept(5089)); validChild.setObsDatetime(new Date()); validChild.setValueNumeric(80.0); obs.addGroupMember(validChild); Obs inValidChild = new Obs(); obs.addGroupMember(inValidChild); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertTrue(errors.hasErrors()); inValidChild.setVoided(true); errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasErrors()); }
/** * @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()); }