/** * @see org.openmrs.api.ConceptService#hasAnyObservation(org.openmrs.Concept) */ @Override @Transactional(readOnly = true) public boolean hasAnyObservation(Concept concept) { List<Concept> concepts = new ArrayList<>(); concepts.add(concept); Integer count = Context.getObsService().getObservationCount(null, null, concepts, null, null, null, null, null, null, true); return count > 0; }
/** * @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"); }
/** * @see ObsService#removeHandler(String) */ @Test public void removeHandler_shouldNotFailWithInvalidKey() { Context.getObsService().removeHandler("SomeRandomHandler"); }
/** * @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean) * @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean,String) */ @Test public void getObservations_shouldGetAllObsAssignedToGivenEncounters() { ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, Collections.singletonList(new Encounter(4)), null, null, null, null, null, null, null, null, null, false, null); Assert.assertEquals(6, obss.size()); }
/** * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean) * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean,String) */ @Test public void getObservationCount_shouldReturnCountOfObsWhosePersonIsAPatientOnly() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); Integer count = obsService.getObservationCount(null, null, null, null, Collections.singletonList(PERSON_TYPE.PATIENT), null, null, null, null, false, null); Assert.assertEquals(15, count.intValue()); }
/** * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean) * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean,String) */ @Test public void getObservationCount_shouldReturnCountOfObsWhosePersonIsAUserOnly() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); Integer count = obsService.getObservationCount(null, null, null, null, Collections.singletonList(PERSON_TYPE.USER), null, null, null, null, false, null); Assert.assertEquals(1, count.intValue()); }
/** * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean) * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean,String) */ @Test public void getObservationCount_shouldReturnCountOfObsWithLocationInGivenLocationsParameter() { ObsService obsService = Context.getObsService(); Integer count = obsService.getObservationCount(null, null, null, null, null, Collections.singletonList(new Location(1)), null, null, null, false, null); Assert.assertEquals(8, count.intValue()); }
/** * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean) * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean,String) */ @Test public void getObservationCount_shouldGetCountOfObsWithQuestionConceptInGivenQuestionsParameter() { ObsService obsService = Context.getObsService(); Integer count = obsService.getObservationCount(null, null, Collections.singletonList(new Concept(5497)), null, null, null, null, null, null, false, null); Assert.assertEquals(2, count.intValue()); }
/** * @see ObsService#getObservations(String) */ @Test public void getObservations_shouldGetObsMatchingEncounterIdInSearchString() { ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations("5"); Assert.assertEquals(1, obss.size()); Assert.assertEquals(16, obss.get(0).getObsId().intValue()); }
/** * @see ObsService#getObservations(String) */ @Test public void getObservations_shouldGetObsMatchingObsIdInSearchString() { ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations("15"); Assert.assertEquals(1, obss.size()); Assert.assertEquals(15, obss.get(0).getObsId().intValue()); }
/** * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean) * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean,String) */ @Test public void getObservationCount_shouldReturnCountOfObsWhoseGroupIdIsGivenObsGroupId() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); Integer count = obsService.getObservationCount(null, null, null, null, null, null, 2 /*obsGroupId*/, null, null, false, null); Assert.assertEquals(2, count.intValue()); }
/** * @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean) * @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean,String) */ @Test public void getObservations_shouldReturnObsWhoseGroupIdIsGivenObsGroupId() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, null, null, null, null, null, null, null, 2 /*obsGroupId*/, null, null, false, null); Assert.assertEquals(2, obss.size()); }
/** * @see ObsService#getHandler(String) */ @Test public void getHandler_shouldGetHandlerWithMatchingKey() { ObsService os = Context.getObsService(); ComplexObsHandler handler = os.getHandler("ImageHandler"); Assert.assertNotNull(handler); Assert.assertTrue(handler instanceof ImageHandler); }
/** * @see ObsService#registerHandler(String,String) */ @Test public void registerHandler_shouldLoadHandlerAndRegisterKey() { ObsService os = Context.getObsService(); // name it something other than what we used in the previous test os.registerHandler("DummyHandler2", "org.openmrs.obs.handler.ImageHandler"); ComplexObsHandler dummyHandler = os.getHandler("DummyHandler2"); Assert.assertNotNull(dummyHandler); }
/** * @see ObsService#registerHandler(String,ComplexObsHandler) */ @Test public void registerHandler_shouldRegisterHandlerWithTheGivenKey() { ObsService os = Context.getObsService(); os.registerHandler("DummyHandler", new ImageHandler()); ComplexObsHandler dummyHandler = os.getHandler("DummyHandler"); Assert.assertNotNull(dummyHandler); }
/** * @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#getHandlers() */ @Test public void getHandlers_shouldNeverReturnNull() { Assert.assertNotNull(Context.getObsService().getHandlers()); // test our current implementation without it being initialized by spring Assert.assertNotNull(new ObsServiceImpl().getHandlers()); }
@Test public void saveConcept_shouldUpdateConceptIfConceptIsAttachedToAnObservationAndItIsANonDatatypeChange() { executeDataSet(INITIAL_CONCEPTS_XML); Concept concept = conceptService.getConcept(1); assertNotNull(concept); ObsService obsService = Context.getObsService(); Obs obs = new Obs(new Person(1), concept, new Date(), new Location(1)); obs.setValueCoded(Context.getConceptService().getConcept(7)); obsService.saveObs(obs, "Creating a new observation with a concept"); conceptService.saveConcept(concept); }
@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()); }