/** * @see ObsService#getObservationsByPersonAndConcept(Person,Concept) */ @Test public void getObservationsByPersonAndConcept_shouldNotFailWithNullPersonParameter() { ObsService obsService = Context.getObsService(); obsService.getObservationsByPersonAndConcept(null, new Concept(7)); }
/** * @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()); }
private void mergeObservationsNotContainedInEncounters(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) { // move all obs that weren't contained in encounters // TODO: this should be a copy, not a move ObsService obsService = Context.getObsService(); for (Obs obs : obsService.getObservationsByPerson(notPreferred)) { if (obs.getEncounter() == null && !obs.getVoided()) { obs.setPerson(preferred); Obs persisted = obsService.saveObs(obs, "Merged from patient #" + notPreferred.getPatientId()); mergedData.addMovedIndependentObservation(persisted.getUuid()); } } }
/** * @see org.openmrs.api.EncounterService#purgeEncounter(Encounter, boolean) */ @Override public void purgeEncounter(Encounter encounter, boolean cascade) throws APIException { // if authenticated user is not supposed to edit encounter of certain type if (!canEditEncounter(encounter, null)) { throw new APIException("Encounter.error.privilege.required.purge", new Object[] { encounter.getEncounterType() .getEditPrivilege() }); } if (cascade) { ObsService obsService = Context.getObsService(); List<Encounter> justThisEncounter = new ArrayList<>(); justThisEncounter.add(encounter); List<Obs> observations = new ArrayList<>( obsService.getObservations(null, justThisEncounter, null, null, null, null, null, null, null, null, null, true)); for (Obs o : observations) { obsService.purgeObs(o); } Set<Order> orders = encounter.getOrders(); for (Order o : orders) { Context.getOrderService().purgeOrder(o); } } Context.getEncounterService().purgeEncounter(encounter); }
os.saveObs(oGGGP, null); int oGGGPId = oGGGP.getObsId(); Obs testGGGP = os.getObs(oGGGPId); assertTrue(testGGGP.isObsGrouping()); Set<Obs> GGGPmembers = testGGGP.getGroupMembers(); Obs oGGGPThatWasUpdated = os.saveObs(oGGGP, "Updating obs group parent"); Obs obsThatWasVoided = os.saveObs(oVoidTest, null); os.voidObs(obsThatWasVoided, "testing void method"); os.voidObs(oGGGPThatWasUpdated, "testing void cascade"); assertTrue(oGGGPThatWasUpdated.getVoided()); Obs childLeafObs = os.getObs(childOneId); assertTrue(childLeafObs.getVoided()); os.unvoidObs(oGGGPThatWasUpdated); assertFalse(oGGGPThatWasUpdated.getVoided()); assertFalse(childLeafObs.getVoided()); os.voidObs(oGGGPThatWasUpdated, "testing void cascade"); childLeafObs = os.getObs(childOneId); assertTrue(childLeafObs.getVoided()); os.unvoidObs(oGGGPThatWasUpdated); childLeafObs = os.getObs(childOneId); assertFalse(childLeafObs.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)); } }
/** * @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); }
ObsService os = Context.getObsService(); Obs obs = os.getObsByUuid(obsUuid); Assert.assertNotNull(obs); Assert.assertNotNull(os.getObsByUuid(obsUuid)); Assert.assertNull(os.getObsByUuid(obsUuid));
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldAuditMovedIndependentObservations() throws Exception { //retrieve patients Patient preferred = patientService.getPatient(999); Patient notPreferred = patientService.getPatient(7); voidOrders(Collections.singleton(notPreferred)); //get an observation for notPreferred and make it independent from any encounter Obs obs = Context.getObsService().getObs(7); obs.setEncounter(null); obs.setComment("this observation is for testing the merge"); Context.getObsService().saveObs(obs, "Reason cannot be blank"); //merge the two patients and retrieve the audit object PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); String uuid = null; List<Obs> observations = Context.getObsService().getObservationsByPerson(preferred); for (Obs o : observations) { if (obs.getComment().equals(o.getComment())) { uuid = o.getUuid(); } } Assert.assertTrue("moving of independent observation was not audited", isValueInList(uuid, audit.getPersonMergeLogData().getMovedIndependentObservations())); }
List<Obs> obsForPatient3 = obsService.getObservationsByPerson(patient); assertNotNull(obsForPatient3); assertTrue("There should be some obs created for #3", obsForPatient3.size() > 0); cal.set(2008, Calendar.FEBRUARY, 29, 0, 0, 0); Date returnVisitDate = cal.getTime(); List<Obs> returnVisitDateObsForPatient3 = obsService.getObservationsByPersonAndConcept(patient, returnVisitDateConcept); assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient3.size());
/** * Unvoids an Obs * <p> * If the Obs argument is an obsGroup, all group members with the same dateVoided will also be * unvoided. * * @see org.openmrs.api.ObsService#unvoidObs(org.openmrs.Obs) * @param obs the Obs to unvoid * @return the unvoided Obs * @throws APIException */ @Override public Obs unvoidObs(Obs obs) throws APIException { return Context.getObsService().saveObs(obs,"unvoid obs"); }
/** * @see ObsService#purgeObs(Obs) */ @Test public void purgeObs_shouldDeleteTheGivenObsFromTheDatabase() { ObsService obsService = Context.getObsService(); Obs obs = obsService.getObs(7); obsService.purgeObs(obs); Assert.assertNull(obsService.getObs(7)); executeDataSet(COMPLEX_OBS_XML); Obs complexObs = obsService.getComplexObs(44, ComplexObsHandler.RAW_VIEW); // obs #44 is coded by the concept complex #8473 pointing to ImageHandler // ImageHandler inherits AbstractHandler which handles complex data files on disk assertNotNull(complexObs.getComplexData()); AdministrationService as = Context.getAdministrationService(); File complexObsDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(as .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR)); for (File file : complexObsDir.listFiles()) { file.delete(); } obsService.purgeObs(complexObs); assertNull(obsService.getObs(obs.getObsId())); }
Obs complexObs = os.getObs(44); Assert.assertNotNull(complexObs.getValueComplex()); Assert.assertNotNull(complexObs.getComplexData()); Assert.assertEquals(complexObs, os.getObsByUuid(complexObs.getUuid()));
/** * @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; }
Context.getAdministrationService().saveGlobalProperty(falseConceptGlobalProperty); ObsService os = Context.getObsService(); Assert.assertNull(os.getObs(17)); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18)); Obs newObservation = null; for (Obs newObs : newList) {
Obs obs = obsService.getObs(parentObsId); obs.addGroupMember(obsService.getObs(childObsId)); obs.addGroupMember(obsService.getObs(orderReferencingObsId)); conceptProposal.setObs(obsService.getObs(conceptProposalObsId)); obs.addGroupMember(conceptProposal.getObs()); Assert.assertNotNull(obsService.getObs(parentObsId)); Assert.assertNotNull(obsService.getObs(childObsId)); Assert.assertNotNull(obsService.getObs(unrelatedObsId)); Assert.assertNotNull(obsService.getObs(orderReferencingObsId)); Assert.assertNotNull(obsService.getObs(conceptProposalObsId)); Context.getObsService().purgeObs(obs, false); Assert.assertNull(obsService.getObs(parentObsId)); Assert.assertNull(obsService.getObs(childObsId)); Assert.assertNotNull(obsService.getObs(unrelatedObsId)); Assert.assertNull(obsService.getObs(orderReferencingObsId)); Assert.assertNull(obsService.getObs(conceptProposalObsId));
ConceptName cn1 = new ConceptName(1847); o.setValueCodedName(cn1); os.saveObs(o, null); ConceptName cn2 = new ConceptName(2453); o2.setValueCodedName(cn2); os.saveObs(o2, null); Assert.assertEquals(2, os.getObservationCount(names, true).intValue());
for (Obs o : encounter.getObsAtTopLevel(false)) { if (!o.getVoided()) { os.voidObs(o, reason);