Search in sources :

Example 66 with Encounter

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"));
}
Also used : Visit(org.openmrs.Visit) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 67 with Encounter

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"));
}
Also used : Visit(org.openmrs.Visit) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 68 with Encounter

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");
}
Also used : Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Before(org.junit.Before)

Example 69 with 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;
}
Also used : Obs(org.openmrs.Obs) PatientService(org.openmrs.api.PatientService) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Person(org.openmrs.Person) EncounterService(org.openmrs.api.EncounterService) Transactional(org.springframework.transaction.annotation.Transactional)

Example 70 with Encounter

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);
    }
}
Also used : Order(org.openmrs.Order) CohortService(org.openmrs.api.CohortService) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19