/** * @see OrderService#getAllOrdersByPatient(org.openmrs.Patient) */ @Test public void getAllOrdersByPatient_shouldGetAllTheOrdersForTheSpecifiedPatient() { assertEquals(12, orderService.getAllOrdersByPatient(patientService.getPatient(2)).size()); assertEquals(2, orderService.getAllOrdersByPatient(patientService.getPatient(7)).size()); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnFalseWhenPatientIdentifierContainsAPatientAndNoOtherPatientHasThisId() throws Exception { PatientIdentifierType pit = patientService.getPatientIdentifierType(1); PatientIdentifier patientIdentifier = new PatientIdentifier("Nobody could possibly have this identifier", pit, null); patientIdentifier.setPatient(patientService.getPatient(2)); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier)); }
/** * @see PatientService#getPatientByExample(Patient) */ @Test public void getPatientByExample_shouldNotFetchPatientMatchingAnyOtherPatientInformation() throws Exception { Patient examplePatient = Context.getPatientService().getPatient(6); // TODO Test this - it shouldn't matter what the identifier is examplePatient.setId(null); Patient patient = Context.getPatientService().getPatientByExample(examplePatient); Assert.assertNull(patient); }
/** * @see PatientService#getPatient(Integer) */ @Test public void getPatient_shouldFetchPatientWithGivenPatientId() throws Exception { Patient patient = Context.getPatientService().getPatient(2); Assert.assertNotNull(patient); Assert.assertTrue(patient.getClass().isAssignableFrom(Patient.class)); }
private Patient getPatient(PID pid) throws HL7Exception { Integer patientId = Context.getHL7Service().resolvePatientId(pid); if (patientId == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedPatient")); } return Context.getPatientService().getPatient(patientId); }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldVoidNonPreferredPersonObject() throws Exception { Patient notPreferred = patientService.getPatient(2); voidOrders(Collections.singleton(notPreferred)); Context.getPatientService().mergePatients(patientService.getPatient(6), notPreferred); Assert.assertTrue(Context.getPersonService().getPerson(2).getVoided()); }
/** * @see PatientService#voidPatient(Patient,String) */ @Test public void voidPatient_shouldVoidPerson() throws Exception { //given Patient patient = patientService.getPatient(2); //when patientService.voidPatient(patient, "reason"); //then Assert.assertTrue(patient.getPersonVoided()); }
/** * @see RequireVoidReasonVoidHandler#handle(Voidable,User,Date,String) */ @Test(expected = IllegalArgumentException.class) public void handle_shouldThrowIllegalArgumentExceptionIfPatientVoidReasonIsNull() { Patient p = Context.getPatientService().getPatient(2); Context.getPatientService().voidPatient(p, null); }
/** * @see OrderService#getOrderHistoryByConcept(Patient, Concept) */ @Test public void getOrderHistoryByConcept_shouldReturnEmptyListForConceptWithoutOrders() { Concept concept = Context.getConceptService().getConcept(21); Patient patient = Context.getPatientService().getPatient(2); List<Order> orders = orderService.getOrderHistoryByConcept(patient, concept); Assert.assertEquals(0, orders.size()); }
/** * @see OrderService#(OrderSearchCriteria) */ @Test public void getOrders_shouldGetOrdersByPatient() { Patient patient = patientService.getPatient(2); OrderSearchCriteria orderSearchCriteria = new OrderSearchCriteriaBuilder().setPatient(patient).build(); List<Order> orders = orderService.getOrders(orderSearchCriteria); assertEquals(11, orders.size()); }
private Visit makeVisit(Integer patientId) { Visit visit = new Visit(); visit.setPatient(Context.getPatientService().getPatient(patientId)); visit.setStartDatetime(new Date()); visit.setVisitType(visitService.getVisitType(1)); return visit; }
/** * @see EncounterService#getEncountersNotAssignedToAnyVisit(Patient) */ @Test public void getEncountersNotAssignedToAnyVisit_shouldReturnTheUnvoidedEncountersNotAssignedToAnyVisit() { executeDataSet(UNIQUE_ENC_WITH_PAGING_XML); List<Encounter> encs = Context.getEncounterService().getEncountersNotAssignedToAnyVisit( Context.getPatientService().getPatient(10)); Assert.assertEquals(2, encs.size()); Assert.assertNull(encs.get(0).getVisit()); Assert.assertNull(encs.get(1).getVisit()); }
@Test public void removePatientFromCohort_shouldSaveCohortAfterRemovingPatient() { executeDataSet(COHORT_XML); Cohort cohort = service.getCohort(2); Integer patientId = cohort.getMemberships().iterator().next().getPatientId(); Patient patient = Context.getPatientService().getPatient(patientId); service.removePatientFromCohort(cohort, patient); assertFalse(cohort.contains(patientId)); }
/** * @see VisitService#saveVisit(Visit) */ @Test public void saveVisit_shouldPassIfNoValidationErrorsAreFound() { Visit visit = new Visit(); visit.setPatient(Context.getPatientService().getPatient(2)); visit.setVisitType(visitService.getVisitType(1)); visit.setStartDatetime(new Date()); visitService.saveVisit(visit); }
/** * @see VisitValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfVisitTypeIsNotSet() { Visit visit = new Visit(); visit.setPatient(Context.getPatientService().getPatient(2)); visit.setStartDatetime(new Date()); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertTrue(errors.hasFieldErrors("visitType")); }
@Test public void shouldGetTheActiveDrugOrdersForAPatient() { Patient patient = patientService.getPatient(2); List<Order> activeDrugOrders = orderService.getActiveOrders(patient, orderService.getOrderTypeByName("Drug order"), null, null); assertEquals(4, activeDrugOrders.size()); Order[] expectedDrugOrders = { orderService.getOrder(222), orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5) }; assertThat(activeDrugOrders, hasItems(expectedDrugOrders)); }
/** * @see CohortService#addPatientToCohort(Cohort,Patient) */ @Test public void addPatientToCohort_shouldAddAPatientAndSaveTheCohort() { executeDataSet(COHORT_XML); // make a patient, add it using the method Patient patientToAdd = Context.getPatientService().getPatient(3); service.addPatientToCohort(service.getCohort(2), patientToAdd); // proof of "save the cohort": see if the patient is in the cohort assertTrue(service.getCohort(2).contains(3)); }
/** * @see PatientService#voidPatient(Patient,String) */ @Test public void voidPatient_shouldVoidGivenPatientWithGivenReason() throws Exception { Patient patient = Context.getPatientService().getPatient(2); Patient voidedPatient = Context.getPatientService().voidPatient(patient, "Void for testing"); Assert.assertTrue(voidedPatient.getVoided()); Assert.assertEquals("Void for testing", voidedPatient.getVoidReason()); }
@Test public void setAllergies_shouldSetTheNonCodedConceptForNonCodedAllergenIfNotSpecified() { Patient patient = allergyService.getPatient(2); Allergen allergen = new Allergen(AllergenType.DRUG, null, "Some allergy name"); Allergy allergy = new Allergy(patient, allergen, null, null, null); Allergies allergies = allergyService.getAllergies(patient); allergies.add(allergy); allergyService.setAllergies(patient, allergies); Assert.assertFalse(allergy.getAllergen().isCoded()); } }
@Test public void savePatientIdentifier_shouldCreateNewPatientIndentifier() throws Exception { PatientIdentifier patientIdentifier = new PatientIdentifier("677-56-6666", new PatientIdentifierType(4), new Location(1)); Patient associatedPatient = patientService.getPatient(2); patientIdentifier.setPatient(associatedPatient); PatientIdentifier createdPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier); Assert.assertNotNull(createdPatientIdentifier); Assert.assertNotNull(createdPatientIdentifier.getPatientIdentifierId()); }