/** * @see ObsService#voidObs(Obs,String) */ @Test(expected = IllegalArgumentException.class) public void voidObs_shouldFailIfReasonParameterIsEmpty() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); obsService.voidObs(obs, ""); }
/** * @see RequireVoidReasonVoidHandler#handle(Voidable,User,Date,String) */ @Test(expected = IllegalArgumentException.class) public void handle_shouldThrowIllegalArgumentExceptionIfObsVoidReasonIsBlank() { Obs o = Context.getObsService().getObs(7); Context.getObsService().voidObs(o, " "); }
/** * @see RequireVoidReasonVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldNotThrowExceptionIfVoidReasonIsNotBlank() { Obs o = Context.getObsService().getObs(7); Context.getObsService().voidObs(o, "Some Reason"); }
private void voidExistingObs(Obs obs, String changeMessage, Obs newObs) { // void out the original observation to keep it around for // historical purposes try { Context.addProxyPrivilege(PrivilegeConstants.DELETE_OBS); // fetch a clean copy of this obs from the database so that // we don't write the changes to the database when we save // the fact that the obs is now voided evictObsAndChildren(obs); obs = Context.getObsService().getObs(obs.getObsId()); //delete the previous file from the appdata/complex_obs folder if (newObs.hasPreviousVersion() && newObs.getPreviousVersion().isComplex()) { File previousFile = AbstractHandler.getComplexDataFile(obs); previousFile.delete(); } // calling this via the service so that AOP hooks are called Context.getObsService().voidObs(obs, changeMessage); } finally { Context.removeProxyPrivilege(PrivilegeConstants.DELETE_OBS); } }
/** * @see ObsService#voidObs(Obs,String) */ @Test public void voidObs_shouldSetVoidedBitOnGivenObs() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); obsService.voidObs(obs, "testing void function"); assertTrue(obs.getVoided()); }
/** * Tests that we support a manual workaround in case you need to modify a FINAL obs and leave its status as FINAL */ @Test public void shouldNotAutomaticallySetStatusWhenManuallyCopyingAnObs() throws Exception { Obs existing = obsService.getObs(7); Obs newObs = Obs.newInstance(existing); newObs.setValueNumeric(60.0); newObs.setPreviousVersion(existing); newObs = obsService.saveObs(newObs, null); obsService.voidObs(existing, "testing"); assertThat(existing.getStatus(), is(Obs.Status.FINAL)); assertThat(existing.getVoided(), is(true)); assertThat(newObs.getStatus(), is(Obs.Status.FINAL)); } }
for (Obs o : encounter.getObsAtTopLevel(false)) { if (!o.getVoided()) { os.voidObs(o, reason);
/** * @see ObsService#unvoidObs(Obs) */ @Test public void unvoidObs_shouldCascadeUnvoidToChildGroupedObs() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); // a obs with child groups Obs parentObs = obsService.getObs(2); obsService.voidObs(parentObs, "testing void cascade to child obs groups"); Assert.assertTrue(obsService.getObs(9).getVoided()); Assert.assertTrue(obsService.getObs(10).getVoided()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#delete(java.lang.Object, * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected void delete(Obs delegate, String reason, RequestContext context) throws ResponseException { if (delegate.isVoided()) { // DELETE is idempotent, so we return success here return; } Context.getObsService().voidObs(delegate, reason); }
os.voidObs(obsThatWasVoided, "testing void method"); os.voidObs(oGGGPThatWasUpdated, "testing void cascade"); assertTrue(oGGGPThatWasUpdated.getVoided()); os.voidObs(oGGGPThatWasUpdated, "testing void cascade"); childLeafObs = os.getObs(childOneId); assertTrue(childLeafObs.getVoided()); os.voidObs(oGGGPThatWasUpdated, "testing void cascade"); childLeafObs = os.getObs(childOneId); assertTrue(childLeafObs.getVoided());
/** * Returns true if group is an obs group that has no unvoided members. * * @param group * @return */ private void voidObsGroupIfAllChildObsVoided(Obs group) { if (group != null) { // probably should be able to just tet if group.getGroupMembers() == 0 since // getGroupMembers only returns non-voided members? boolean allObsVoided = true; for (Obs member : group.getGroupMembers()) { allObsVoided = allObsVoided && member.isVoided(); } if (allObsVoided) { Context.getObsService().voidObs(group, "htmlformentry"); } voidObsGroupIfAllChildObsVoided(group.getObsGroup()); } }
/** * 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)))); }
if (log.isDebugEnabled()) log.debug("voiding obs: " + o.getObsId()); obsService.voidObs(o, "htmlformentry");