Search in sources :

Example 6 with EncounterSearchCriteriaBuilder

use of org.openmrs.parameter.EncounterSearchCriteriaBuilder in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersOnOrUpToADate.

/**
 * @throws ParseException
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldGetEncountersOnOrUpToADate() throws ParseException {
    Date toDate = new SimpleDateFormat("yyyy-dd-MM").parse("2006-01-01");
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setToDate(toDate).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(2, encounters.size());
    assertEquals(15, encounters.get(0).getEncounterId().intValue());
    assertEquals(1, encounters.get(1).getEncounterId().intValue());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 7 with EncounterSearchCriteriaBuilder

use of org.openmrs.parameter.EncounterSearchCriteriaBuilder in project openmrs-core by openmrs.

the class PatientDataUnvoidHandlerTest method handle_shouldUnvoidTheOrdersAndEncountersAssociatedWithThePatient.

/**
 * @see PatientDataUnvoidHandler#handle(Patient,User,Date,String)
 */
@Test
public void handle_shouldUnvoidTheOrdersAndEncountersAssociatedWithThePatient() {
    Patient patient = Context.getPatientService().getPatient(7);
    patient = Context.getPatientService().voidPatient(patient, "Void Reason");
    assertTrue(patient.getVoided());
    EncounterService es = Context.getEncounterService();
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
    assertTrue(CollectionUtils.isNotEmpty(encounters));
    // all encounters void related fields should be null
    for (Encounter encounter : encounters) {
        assertTrue(encounter.getVoided());
        assertNotNull(encounter.getDateVoided());
        assertNotNull(encounter.getVoidedBy());
        assertNotNull(encounter.getVoidReason());
    }
    OrderService os = Context.getOrderService();
    List<Order> orders = os.getAllOrdersByPatient(patient);
    assertFalse(orders.isEmpty());
    // all order void related fields should be null
    for (Order order : orders) {
        assertTrue(order.getVoided());
        assertNotNull(order.getDateVoided());
        assertNotNull(order.getVoidedBy());
        assertNotNull(order.getVoidReason());
    }
    User user = Context.getUserService().getUser(1);
    new PatientDataUnvoidHandler().handle(patient, user, patient.getDateVoided(), null);
    // check that the voided related fields were set null
    for (Encounter encounter : encounters) {
        assertFalse(encounter.getVoided());
        assertNull(encounter.getDateVoided());
        assertNull(encounter.getVoidedBy());
        assertNull(encounter.getVoidReason());
    }
    for (Order order : orders) {
        assertFalse(order.getVoided());
        assertNull(order.getDateVoided());
        assertNull(order.getVoidedBy());
        assertNull(order.getVoidReason());
    }
}
Also used : Order(org.openmrs.Order) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) User(org.openmrs.User) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with EncounterSearchCriteriaBuilder

use of org.openmrs.parameter.EncounterSearchCriteriaBuilder in project openmrs-core by openmrs.

the class PatientServiceImpl method mergeEncounters.

private void mergeEncounters(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) {
    // change all encounters. This will cascade to obs and orders contained in those encounters
    // TODO: this should be a copy, not a move
    EncounterService es = Context.getEncounterService();
    EncounterSearchCriteria notPreferredPatientEncounterSearchCriteria = new EncounterSearchCriteriaBuilder().setIncludeVoided(true).setPatient(notPreferred).createEncounterSearchCriteria();
    for (Encounter e : es.getEncounters(notPreferredPatientEncounterSearchCriteria)) {
        e.setPatient(preferred);
        log.debug("Merging encounter " + e.getEncounterId() + " to " + preferred.getPatientId());
        Encounter persisted = es.saveEncounter(e);
        mergedData.addMovedEncounter(persisted.getUuid());
    }
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) EncounterService(org.openmrs.api.EncounterService)

Example 9 with EncounterSearchCriteriaBuilder

use of org.openmrs.parameter.EncounterSearchCriteriaBuilder in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersByForm.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldGetEncountersByForm() {
    List<Form> forms = new ArrayList<>();
    forms.add(new Form(1));
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setEnteredViaForms(forms).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(8, encounters.size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) Form(org.openmrs.Form) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 10 with EncounterSearchCriteriaBuilder

use of org.openmrs.parameter.EncounterSearchCriteriaBuilder in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersOnOrAfterDate.

/**
 * Get encounters that are after a certain date, and ensure the comparison is INCLUSIVE of the
 * given date
 *
 * @throws ParseException
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldGetEncountersOnOrAfterDate() throws ParseException {
    // there is only one nonvoided encounter, on 2005-01-01
    DateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
    // test for a min date long before all dates
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setFromDate(ymd.parse("2004-12-31")).setIncludeVoided(false).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(5, encounters.size());
    assertEquals(1, encounters.get(0).getEncounterId().intValue());
    // test for exact date search
    encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setFromDate(ymd.parse("2005-01-01")).setIncludeVoided(false).createEncounterSearchCriteria();
    encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(5, encounters.size());
    // test for one day later
    encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setFromDate(ymd.parse("2005-01-02")).setIncludeVoided(false).createEncounterSearchCriteria();
    encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(4, encounters.size());
    assertEquals(3, encounters.get(0).getEncounterId().intValue());
    assertEquals(4, encounters.get(1).getEncounterId().intValue());
    assertEquals(5, encounters.get(2).getEncounterId().intValue());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Encounter(org.openmrs.Encounter) SimpleDateFormat(java.text.SimpleDateFormat) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)12 EncounterSearchCriteriaBuilder (org.openmrs.parameter.EncounterSearchCriteriaBuilder)12 Test (org.junit.Test)10 Encounter (org.openmrs.Encounter)10 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)10 ArrayList (java.util.ArrayList)4 EncounterService (org.openmrs.api.EncounterService)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Order (org.openmrs.Order)2 OrderService (org.openmrs.api.OrderService)2 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 EncounterType (org.openmrs.EncounterType)1 Form (org.openmrs.Form)1 Location (org.openmrs.Location)1 Patient (org.openmrs.Patient)1 User (org.openmrs.User)1 Visit (org.openmrs.Visit)1 VisitType (org.openmrs.VisitType)1 CohortService (org.openmrs.api.CohortService)1