private void unsetVoidedAndCreationProperties(Obs newObs,Obs obs) { newObs.setVoided(false); newObs.setVoidReason(null); newObs.setDateVoided(null); newObs.setVoidedBy(null); newObs.setCreator(null); newObs.setDateCreated(null); newObs.setPreviousVersion(obs); }
/** * @see Obs#getGroupMembers(boolean) */ @Test public void getGroupMembers_shouldGetAllGroupMembersIfPassedTrueAndNonvoidedIfPassedFalse() throws Exception { Obs parent = new Obs(1); Set<Obs> members = new HashSet<>(); members.add(new Obs(101)); members.add(new Obs(103)); Obs voided = new Obs(99); voided.setVoided(true); members.add(voided); parent.setGroupMembers(members); members = parent.getGroupMembers(true); assertEquals("set of all members should have length of 3", 3, members.size()); members = parent.getGroupMembers(false); assertEquals("set of non-voided should have length of 2", 2, members.size()); members = parent.getGroupMembers(); // should be same as false assertEquals("default should return non-voided with length of 2", 2, members.size()); }
/** * @see Obs#isDirty() */ @Test public void isDirty_shouldReturnFalseWhenOnlyMutableFieldsAreChanged() throws Exception { Obs obs = new Obs(); obs.setVoided(true); obs.setVoidedBy(new User(1000)); obs.setVoidReason("some other reason"); obs.setDateVoided(new Date()); assertFalse(obs.isDirty()); Obs obsEdited = new Obs(5); obsEdited.setVoided(true); obsEdited.setVoidedBy(new User(1000)); obsEdited.setVoidReason("some other reason"); obsEdited.setDateVoided(new Date()); assertFalse(obsEdited.isDirty()); }
/** * @see Encounter#getObs() */ @Test public void getObs_shouldNotGetVoidedObs() { Encounter enc = new Encounter(); //create and add an Obs Obs o = new Obs(); o.setVoided(true); enc.addObs(o); assertEquals(0, enc.getObs().size()); }
newObs.setCreator(obsToCopy.getCreator()); newObs.setDateCreated(obsToCopy.getDateCreated()); newObs.setVoided(obsToCopy.getVoided()); newObs.setVoidedBy(obsToCopy.getVoidedBy()); newObs.setDateVoided(obsToCopy.getDateVoided());
/** * @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()); }
/** * Voids an observation for the `MOTECH user, with the given reason * * @param mrsObservation MRSObservation to be voided * @param reason Reason for voiding the MRSObservation * @param userMotechId MOTECH ID of the user who's MRSObservation needs to be voided * @throws ObservationNotFoundException Exception when the expected Observation does not exist */ @Override public void voidObservation(MRSObservation mrsObservation, String reason, String userMotechId) throws ObservationNotFoundException { Obs obs = obsService.getObs(Integer.valueOf(mrsObservation.getObservationId())); if (obs == null) { throw new ObservationNotFoundException("Observation not found for MOTECH id :" + userMotechId + " and with MRS observation id :" + mrsObservation.getObservationId()); } obs.setVoided(true); obs.setVoidReason(reason); obs.setDateVoided(new Date()); obs.setVoidedBy(openMRSUserAdapter.getOpenMrsUserByUserName(userMotechId)); obsService.voidObs(obs, reason); eventRelay.sendEventMessage(new MotechEvent(EventKeys.DELETED_OBSERVATION_SUBJECT, EventHelper.observationParameters(convertOpenMRSToMRSObservation(obs)))); }
/** * @see Encounter#getObsAtTopLevel(null) */ @Test public void getObsAtTopLevel_shouldNotGetVoidedObs() { Encounter enc = new Encounter(); //create and add an Obs Obs o = new Obs(); o.setVoided(true); enc.addObs(o); assertNotNull(enc.getObsAtTopLevel(true)); assertEquals(1, enc.getObsAtTopLevel(true).size()); assertNotNull(enc.getObsAtTopLevel(false)); assertEquals(0, enc.getObsAtTopLevel(false).size()); }
for (Obs oMatched : matchedObs) { if (replacementObs.get(oMatched) != null && replacementObs.get(oMatched).equals(o)) { o.setVoided(true); o.setVoidedBy(Context.getAuthenticatedUser()); o.setVoidReason(voidReason);
/** * @see Encounter#getAllObs(null) */ @Test public void getAllObs_shouldNotGetVoidedObs() { Encounter enc = new Encounter(); //create and add an Obs Obs o = new Obs(); o.setVoided(true); enc.addObs(o); assertNotNull(enc.getAllObs(true)); assertEquals(1, enc.getAllObs(true).size()); assertNotNull(enc.getAllObs(false)); assertEquals(0, enc.getAllObs(false).size()); }
TestUtil.addObs(e, 3, 5000, date);//adding an un-matched, voided Obs for (Obs o : e.getAllObs(true)) { o.setVoided(true); o.setVoidedBy(Context.getUserService().getUser(1)); o.setVoidReason("blah");
/** * @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()); }
ConceptName cn2 = new ConceptName(2453); o2.setValueCodedName(cn2); o2.setVoided(true); os.saveObs(o2, null);
greatGrandChildObsTwo.setVoided(true);
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldNotValidateIfObsIsVoided() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setObsDatetime(new Date()); obs.setValueNumeric(null); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertTrue(errors.hasFieldErrors("valueNumeric")); obs.setVoided(true); errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasErrors()); }
/** * @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()); }
toBeVoidedObs.setValueText(newValueText); unVoidedObsToUpdate.setValueText(newValueText); toBeVoidedObs.setVoided(true); encounter.setEncounterDatetime(new Date()); encounterService.saveEncounter(encounter);
obsThatWasVoided.setVoided(false); assertFalse(obsThatWasVoided.getVoided());