/** * @see org.openmrs.api.ObsService#getObservationsByPerson(org.openmrs.Person) */ @Override @Transactional(readOnly = true) public List<Obs> getObservationsByPerson(Person who) { List<Person> whom = new ArrayList<>(); whom.add(who); return Context.getObsService().getObservations(whom, null, null, null, null, null, null, null, null, null, null, false); }
/** * @see org.openmrs.api.ObsService#getObservationsByPersonAndConcept(org.openmrs.Person, * org.openmrs.Concept) */ @Override @Transactional(readOnly = true) public List<Obs> getObservationsByPersonAndConcept(Person who, Concept question) throws APIException { List<Person> whom = new ArrayList<>(); if (who != null && who.getPersonId() != null) { whom.add(who); } List<Concept> questions = new ArrayList<>(); questions.add(question); return Context.getObsService().getObservations(whom, null, questions, null, null, null, null, null, null, null, null, false); }
/** * @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#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_shouldReturnObsWhosePersonIsAPatientOnly() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, null, null, null, Collections.singletonList(PERSON_TYPE.PATIENT), null, null, null, null, null, null, false, null); Assert.assertEquals(15, obss.size()); }
/** * @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_shouldReturnObsWhosePersonIsAUserOnly() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, null, null, null, Collections.singletonList(PERSON_TYPE.USER), null, null, null, null, null, null, false, null); Assert.assertEquals(1, obss.size()); }
/** * @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_shouldReturnObsWithLocationInGivenLocationsParameter() { ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, null, null, null, null, Collections.singletonList(new Location(1)), null, null, null, null, null, false, null); Assert.assertEquals(8, obss.size()); }
/** * @see ObsService#getObservations(List,List,List,List,List,List,List,Integer,Integer,Date,Date,boolean,String) */ @Test public void getObservations_shouldOnlyReturnedObsWithMatchingAccessionNumber() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss1 = obsService.getObservations(null, null, null, null, null, null, null, null, null, null, null, false, "AN1"); List<Obs> obss2 = obsService.getObservations(Collections.singletonList(new Person(6)), null, null, null, null, null, null, null, null, null, null, false, "AN2"); List<Obs> obss3 = obsService.getObservations(Collections.singletonList(new Person(8)), null, null, null, null, null, null, null, null, null, null, false, "AN2"); Assert.assertEquals(2, obss1.size()); Assert.assertEquals(1, obss2.size()); Assert.assertEquals(0, obss3.size()); }
/** * @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(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_shouldGetAllObsWithQuestionConceptInGivenQuestionsParameter() { ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, null, Collections.singletonList(new Concept(5497)), null, null, null, null, null, null, null, null, false, null); Assert.assertEquals(2, obss.size()); }
/** * @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_shouldReturnAllObsWhosePersonIsAPersonOnly() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, null, null, null, Collections.singletonList(PERSON_TYPE.PERSON), null, null, null, null, null, null, false, null); Assert.assertEquals(17, obss.size()); }
/** * @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#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_shouldSortReturnedObsByConceptIdIfSortIsConcept() { ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(Collections.singletonList(new Person(7)), null, null, null, null, null, Arrays.asList("concept", "obsDatetime"), null, null, null, null, false, null); // check the order of a few of the obs returned Assert.assertEquals(11, obss.get(0).getObsId().intValue()); Assert.assertEquals(9, obss.get(1).getObsId().intValue()); Assert.assertEquals(16, obss.get(2).getObsId().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_shouldSortReturnedObsByObsDatetimeIfSortIsEmpty() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(Collections.singletonList(new Person(8)), null, null, null, null, null, new ArrayList<>(), null, null, null, null, false, null); Assert.assertEquals(8, obss.get(0).getObsId().intValue()); Assert.assertEquals(7, obss.get(1).getObsId().intValue()); }
/** * Uses the OpenmrsUtil.getLastMomentOfDay(Date) method to get all observations for a given day * * @throws ParseException * @throws Exception */ @Test public void shouldGetObservationsOnDay() throws ParseException { executeDataSet(INITIAL_OBS_XML); ObsService os = Context.getObsService(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date sd = df.parse("2006-02-13"); Date ed = df.parse("2006-02-13"); List<Obs> obs = os.getObservations(null, null, null, null, null, null, null, null, null, sd, OpenmrsUtil.getLastMomentOfDay(ed), false); assertEquals(1, obs.size()); }
/** * @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_shouldLimitNumberOfObsReturnedToMostReturnNParameter() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> count = obsService.getObservations(Collections.singletonList(new Person(8)), null, null, null, null, null, null, 1, null, null, null, false, null); Assert.assertEquals(1, count.size()); }
/** * @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#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_shouldNotIncludeVoidedObs() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(Collections.singletonList(new Person(9)), null, null, null, null, null, null, null, null, null, null, false, null); Assert.assertEquals(1, obss.size()); Assert.assertEquals(9, obss.get(0).getObsId().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_shouldIncludeVoidedObsIfIncludeVoidedObsIsTrue() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(Collections.singletonList(new Person(9)), null, null, null, null, null, null, null, null, null, null, true, null); Assert.assertEquals(2, obss.size()); Assert.assertEquals(10, obss.get(0).getObsId().intValue()); Assert.assertEquals(9, obss.get(1).getObsId().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_shouldGetAllObsWithAnswerConceptInGivenAnswersParameter() { executeDataSet(INITIAL_OBS_XML); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations(null, null, null, Collections.singletonList(new Concept(7)), null, null, null, null, null, null, null, false, null); // obs 11 in INITIAL_OBS_XML and obs 13 in standardTestDataset Assert.assertEquals(3, obss.size()); Set<Integer> ids = new HashSet<>(); for (Obs o : obss) { ids.add(o.getObsId()); } Assert.assertTrue(ids.contains(11)); Assert.assertTrue(ids.contains(13)); }
/** * @see ObsService#getObservations(String) */ @Test public void getObservations_shouldGetObsMatchingPatientIdentifierInSearchString() { executeDataSet(INITIAL_OBS_XML); updateSearchIndex(); ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservations("12345K"); Assert.assertEquals(2, obss.size()); Assert.assertEquals(4, obss.get(0).getObsId().intValue()); Assert.assertEquals(3, obss.get(1).getObsId().intValue()); }