use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsAfterVisitStopDateTime.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEncounterDateTimeIsAfterVisitStopDateTime() {
Encounter encounter = Context.getEncounterService().getEncounter(3);
Visit visit = Context.getVisitService().getVisit(1);
visit.setPatient(encounter.getPatient());
encounter.setVisit(visit);
// Set encounter dateTime to after the visit stopDateTime.
visit.setStopDatetime(new Date());
Date date = new Date(visit.getStopDatetime().getTime() + 1);
encounter.setEncounterDatetime(date);
errors = new BindException(encounter, "encounter");
encounterValidator.validate(encounter, errors);
Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime"));
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsBeforeVisitStartDateTime.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEncounterDateTimeIsBeforeVisitStartDateTime() {
Encounter encounter = Context.getEncounterService().getEncounter(3);
Visit visit = Context.getVisitService().getVisit(1);
visit.setPatient(encounter.getPatient());
encounter.setVisit(visit);
// Set encounter dateTime to before the visit startDateTime.
Date date = new Date(visit.getStartDatetime().getTime() - 1);
encounter.setEncounterDatetime(date);
errors = new BindException(encounter, "encounter");
encounterValidator.validate(encounter, errors);
Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime"));
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterValidatorTest method setUp.
@Before
public void setUp() {
encounterValidator = new EncounterValidator();
encounter = new Encounter();
errors = new BindException(encounter, "encounter");
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class ObsServiceImpl method getObservations.
/**
* This implementation queries the obs table comparing the given <code>searchString</code> with
* the patient's identifier, encounterId, and obsId
*
* @see org.openmrs.api.ObsService#getObservations(java.lang.String)
*/
@Override
@Transactional(readOnly = true)
public List<Obs> getObservations(String searchString) {
// search on patient identifier
PatientService ps = Context.getPatientService();
List<Patient> patients = ps.getPatients(searchString);
List<Person> persons = new ArrayList<>(patients);
// try to search on encounterId
EncounterService es = Context.getEncounterService();
List<Encounter> encounters = new ArrayList<>();
try {
Encounter e = es.getEncounter(Integer.valueOf(searchString));
if (e != null) {
encounters.add(e);
}
} catch (NumberFormatException e) {
// pass
}
List<Obs> returnList = new ArrayList<>();
if (!encounters.isEmpty() || !persons.isEmpty()) {
returnList = Context.getObsService().getObservations(persons, encounters, null, null, null, null, null, null, null, null, null, false);
}
// try to search on obsId
try {
Obs o = getObs(Integer.valueOf(searchString));
if (o != null) {
returnList.add(o);
}
} catch (NumberFormatException e) {
// pass
}
return returnList;
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class PatientDataUnvoidHandler method handle.
@Override
public void handle(Patient patient, User originalVoidingUser, Date origParentVoidedDate, String unused) {
// can't be unvoiding a patient that doesn't exist in the database
if (patient.getId() != null) {
// unvoid all the encounter that got voided as a result of the patient getting voided
EncounterService es = Context.getEncounterService();
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
if (CollectionUtils.isNotEmpty(encounters)) {
for (Encounter encounter : encounters) {
if (encounter.getVoided() && encounter.getDateVoided().equals(origParentVoidedDate) && encounter.getVoidedBy().equals(originalVoidingUser)) {
es.unvoidEncounter(encounter);
}
}
}
// unvoid all the orders that got voided as a result of the patient getting voided
OrderService os = Context.getOrderService();
List<Order> orders = os.getAllOrdersByPatient(patient);
if (CollectionUtils.isNotEmpty(orders)) {
for (Order order : orders) {
if (order.getVoided() && order.getDateVoided().equals(origParentVoidedDate) && order.getVoidedBy().equals(originalVoidingUser)) {
os.unvoidOrder(order);
}
}
}
CohortService cs = Context.getCohortService();
cs.notifyPatientUnvoided(patient, originalVoidingUser, origParentVoidedDate);
}
}
Aggregations