/** * @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 ObsService#voidObs(Obs,String) */ @Test(expected = IllegalArgumentException.class) public void voidObs_shouldFailIfReasonParameterIsEmpty() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); obsService.voidObs(obs, ""); }
@Test public void shouldHaveAnObsLoadedFromTheDatabaseAsNotDirty() { assertFalse(obsService.getObs(7).isDirty()); }
/** * @see ObsService#getObs(Integer) */ @Test public void getObs_shouldGetObsMatchingGivenObsId() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); Assert.assertEquals(5089, obs.getConcept().getId().intValue()); }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldSetVoidReasonMessageToChangeMessage() { // Set changeMessage arg to saveObs() method - should equal void reason on new Obs String changeMessage = "Testing TRUNK-3701"; int obsId = 7; ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(obsId); // change something on the obs and save it again obs.setComment("Comment to make sure obs changes"); obsService.saveObs(obs, changeMessage); obs = obsService.getObs(obsId); //refetch original (now voided) obs // check assertEquals(changeMessage, obs.getVoidReason()); }
@Test public void saveObs_shouldNotChangeStatusOfPreliminaryWhenModifyingAnObs() throws Exception { Obs existing = obsService.getObs(9); existing.setValueNumeric(175.0); Obs newObs = obsService.saveObs(existing, "testing"); assertThat(newObs.getValueNumeric(), is(175.0)); assertThat(newObs.getStatus(), is(Obs.Status.PRELIMINARY)); }
/** * @see RequireVoidReasonVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldNotThrowExceptionIfVoidReasonIsNotBlank() { Obs o = Context.getObsService().getObs(7); Context.getObsService().voidObs(o, "Some Reason"); }
/** * @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 ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldVoidTheGivenObsInTheDatabase() { Obs obs = Context.getObsService().getObs(7); obs.setValueNumeric(1.0); Context.getObsService().saveObs(obs, "just testing"); // fetch the obs from the database again obs = Context.getObsService().getObs(7); Assert.assertTrue(obs.getVoided()); }
@Test public void saveObs_shouldSetStatusToAmendedWhenModifyingAnObsWithFinalStatus() throws Exception { Obs existing = obsService.getObs(7); existing.setValueNumeric(60.0); Obs amended = obsService.saveObs(existing, "testing"); assertThat(amended.getValueNumeric(), is(60.0)); assertThat(amended.getStatus(), is(Obs.Status.AMENDED)); assertThat(existing.getStatus(), is(Obs.Status.FINAL)); }
@Test public void saveObs_shouldLetYouChangeStatusFromPreliminaryToFinalWhenModifyingAnObs() throws Exception { Obs existing = obsService.getObs(9); existing.setValueNumeric(175.0); existing.setStatus(Obs.Status.FINAL); Obs newObs = obsService.saveObs(existing, "testing"); assertThat(newObs.getValueNumeric(), is(175.0)); assertThat(newObs.getStatus(), is(Obs.Status.FINAL)); }
/** * @see ObsService#unvoidObs(Obs) */ @Test public void unvoidObs_shouldUnsetVoidedBitOnGivenObs() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); obsService.unvoidObs(obs); assertFalse(obs.getVoided()); }
/** * @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()); }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldReturnADifferentObjectWhenUpdatingAnObs() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); // change something on the obs and save it again obs.setComment("A new comment"); Obs obsSaved = obsService.saveObs(obs, "Testing that a new obs is returned"); assertFalse(obsSaved.getObsId().equals(obs.getObsId())); }
/** * 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)); } }
/** * @see ObsService#purgeObs(Obs,boolean) */ @Test public void purgeObs_shouldNotDeleteReferencedOrdersWhenPurgingObs() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); final OrderService orderService = Context.getOrderService(); final int orderReferencingObsId = 4; final Obs obs = obsService.getObs(orderReferencingObsId); final Order order = obs.getOrder(); final Integer referencedOrderId = order.getOrderId(); Context.getObsService().purgeObs(obs, false); Assert.assertNull(obsService.getObs(orderReferencingObsId)); Assert.assertNotNull(orderService.getOrder(referencedOrderId)); }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldCopyTheFormNamespaceAndPathFieldInEditedObs() { executeDataSet(INITIAL_OBS_XML); Obs obs = Context.getObsService().getObs(7); obs.setValueNumeric(5.0); Obs o2 = Context.getObsService().saveObs(obs, "just testing"); Assert.assertNotNull(obs.getFormFieldNamespace()); // fetch the obs from the database again obs = Context.getObsService().getObs(o2.getObsId()); Assert.assertNotNull(obs.getFormFieldNamespace()); Assert.assertNotNull(obs.getFormFieldPath()); }
@Test public void saveObs_shouldOverwriteObsPersonValueWithEncounterPatient() { String changeMessage = "Testing TRUNK-3283"; executeDataSet(ENCOUNTER_OBS_XML); ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(13); //overwrite ObsPerson with EncounterPatient Obs obsSaved = obsService.saveObs(obs, changeMessage); assertEquals(obs.getPerson(), obsSaved.getEncounter().getPatient()); }
/** * @see EncounterService#unvoidEncounter(Encounter) */ @Test public void unvoidEncounter_shouldCascadeUnvoidToObs() { EncounterService encounterService = Context.getEncounterService(); // get a voided encounter that has some voided obs Encounter encounter = encounterService.getEncounter(2); encounterService.unvoidEncounter(encounter); Obs obs = Context.getObsService().getObs(4); assertFalse(obs.getVoided()); assertNull(obs.getVoidReason()); }
/** * @see EncounterService#voidEncounter(Encounter,String) */ @Test public void voidEncounter_shouldCascadeToObs() { EncounterService encounterService = Context.getEncounterService(); // get a nonvoided encounter that has some obs Encounter encounter = encounterService.getEncounter(1); encounterService.voidEncounter(encounter, "Just Testing"); Obs obs = Context.getObsService().getObs(1); assertTrue(obs.getVoided()); assertEquals("Just Testing", obs.getVoidReason()); }