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());
}
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());
}
}
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());
}
}
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());
}
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());
}
Aggregations