Search in sources :

Example 26 with VisitType

use of org.openmrs.VisitType in project openmrs-core by openmrs.

the class VisitServiceTest method saveVisit_shouldAddANewVisitToTheDatabase.

/**
 * @see VisitService#saveVisit(Visit)
 */
@Test
public void saveVisit_shouldAddANewVisitToTheDatabase() {
    Integer originalSize = visitService.getAllVisits().size();
    Visit visit = new Visit(new Patient(2), new VisitType(1), new Date());
    visit = visitService.saveVisit(visit);
    assertNotNull(visit.getId());
    assertNotNull(visit.getUuid());
    assertNotNull(visit.getCreator());
    assertNotNull(visit.getDateCreated());
    assertEquals(originalSize + 1, visitService.getAllVisits().size());
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitType(org.openmrs.VisitType) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with VisitType

use of org.openmrs.VisitType in project openmrs-core by openmrs.

the class VisitTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see VisitTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    VisitType visitType = new VisitType();
    visitType.setName("name");
    visitType.setDescription("some text");
    visitType.setRetireReason("some text");
    Errors errors = new BindException(visitType, "visitType");
    new VisitTypeValidator().validate(visitType, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) VisitType(org.openmrs.VisitType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 28 with VisitType

use of org.openmrs.VisitType in project openmrs-core by openmrs.

the class VisitTypeValidator method validate.

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if name is null or empty or whitespace
 * @should fail validation if description is null or empty or whitespace
 * @should pass validation if all required fields have proper values
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) {
    VisitType visitType = (VisitType) obj;
    if (visitType == null) {
        errors.rejectValue("visitType", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason");
    }
}
Also used : VisitType(org.openmrs.VisitType)

Example 29 with VisitType

use of org.openmrs.VisitType in project openmrs-core by openmrs.

the class ExistingOrNewVisitAssignmentHandler method loadVisitType.

/**
 * Get the visit type corresponding to an encounter type by reading valid mappings
 * from a global property
 * @param encounterType
 * @return
 * @throws APIException
 */
private static VisitType loadVisitType(EncounterType encounterType) throws APIException {
    String value = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GP_ENCOUNTER_TYPE_TO_VISIT_TYPE_MAPPING, "");
    // or encounterTypeUuid:visitTypeUuid o a mixture of uuids and id
    if (!StringUtils.isBlank(value)) {
        VisitService visitService = Context.getVisitService();
        String targetEncounterTypeId = encounterType.getId().toString();
        String[] mappings = value.split(",");
        for (String mapping : mappings) {
            int index = mapping.indexOf(':');
            if (index > 0) {
                String encounterTypeIdOrUuid = mapping.substring(0, index).trim();
                if (targetEncounterTypeId.equals(encounterTypeIdOrUuid) || encounterType.getUuid().equals(encounterTypeIdOrUuid)) {
                    String visitTypeIdOrUuid = mapping.substring(index + 1).trim();
                    VisitType visitType;
                    if (StringUtils.isNumeric(visitTypeIdOrUuid)) {
                        visitType = visitService.getVisitType(Integer.parseInt(visitTypeIdOrUuid));
                    } else {
                        visitType = visitService.getVisitTypeByUuid(visitTypeIdOrUuid);
                    }
                    if (visitType != null) {
                        return visitType;
                    }
                }
            }
        }
        // Reaching here means this encounter type is not in the user's mapping.
        throw new APIException("GlobalProperty.error.loadVisitType", new Object[] { encounterType.getName() });
    }
    return Context.getVisitService().getAllVisitTypes().get(0);
}
Also used : APIException(org.openmrs.api.APIException) VisitService(org.openmrs.api.VisitService) VisitType(org.openmrs.VisitType)

Example 30 with VisitType

use of org.openmrs.VisitType in project openmrs-module-pihcore by PIH.

the class BaseInpatientReportTest method setup.

@Before
@Override
public void setup() throws Exception {
    super.setup();
    VisitType atFacility = visitService.getVisitTypeByUuid(PihEmrConfigConstants.VISITTYPE_CLINIC_OR_HOSPITAL_VISIT_UUID);
    EncounterType checkIn = getCheckInEncounterType();
    EncounterType admission = getAdmissionEncounterType();
    EncounterType transfer = getTransferEncounterType();
    EncounterType exit = getExitEncounterType();
    EncounterType consultation = getConsultationEncounterType();
    EncounterType postOpNote = getPostOpNoteEncounterType();
    Location visitLocation = locationService.getLocation("Mirebalais");
    Location outpatientClinic = locationService.getLocation("Klinik Ekstèn");
    Location womensInternalMedicine = locationService.getLocation("Sal Fanm");
    Location mensInternalMedicine = locationService.getLocation("Sal Gason");
    Location surgicalWard = locationService.getLocation("Sal Aprè Operasyon");
    Location emergencyDepartment = locationService.getLocation("Ijans");
    Concept dispositionConcept = conceptService.getConceptByUuid("c8b22b09-e2f2-4606-af7d-e52579996de3");
    // Already admitted at start of 3 Oct (Women's Internal Medicine)
    patient1 = data.randomPatient().save();
    String startDateStr = "2013-10-02 09:15:00";
    patient1 = this.conditionallySetBirthDateBeforeStartDate(patient1, startDateStr);
    Visit visit1 = data.visit().patient(patient1).visitType(atFacility).started(startDateStr).stopped("2013-10-14 04:30:00").location(visitLocation).save();
    Encounter enc1a = data.encounter().visit(visit1).encounterType(checkIn).location(outpatientClinic).encounterDatetime("2013-10-02 09:15:00").save();
    Encounter enc1b = data.encounter().visit(visit1).encounterType(admission).location(womensInternalMedicine).encounterDatetime("2013-10-02 12:30:00").save();
    // Admitted and discharged the days before. Visit extends into 3 Oct, but they've already been discharged at that point. (I.e. not an inpatient on Oct 3.)
    patient2 = data.randomPatient().save();
    startDateStr = "2013-10-01 17:30:00";
    patient2 = this.conditionallySetBirthDateBeforeStartDate(patient2, startDateStr);
    Visit visit2 = data.visit().patient(patient2).visitType(atFacility).started(startDateStr).stopped("2013-10-03 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit2).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
    data.encounter().visit(visit2).encounterType(admission).location(womensInternalMedicine).encounterDatetime("2013-10-01 18:30:00").save();
    data.encounter().visit(visit2).encounterType(exit).location(womensInternalMedicine).encounterDatetime("2013-10-02 23:45:00").save();
    // Admitted during the day of 3 Oct (Men's Internal Medicine)
    patient3 = data.randomPatient().save();
    startDateStr = "2013-10-03 12:34:00";
    patient3 = this.conditionallySetBirthDateBeforeStartDate(patient3, startDateStr);
    Visit visit3a = data.visit().patient(patient3).visitType(atFacility).started(startDateStr).stopped("2013-10-07 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit3a).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
    data.encounter().visit(visit3a).encounterType(admission).location(mensInternalMedicine).encounterDatetime("2013-10-03 13:57:00").save();
    Encounter encounter3a = data.encounter().visit(visit3a).encounterType(exit).location(mensInternalMedicine).encounterDatetime("2013-10-07 12:45:00").save();
    data.obs().encounter(encounter3a).concept(dispositionConcept).value("Transfer out of hospital", "PIH").save();
    // This was a possible readmission, because the patient was admitted and left the previous day
    startDateStr = "2013-10-02 12:34:00";
    Visit visit3b = data.visit().patient(patient3).visitType(atFacility).started(startDateStr).stopped("2013-10-02 16:45:00").location(visitLocation).save();
    data.encounter().visit(visit3b).encounterType(admission).location(mensInternalMedicine).encounterDatetime(startDateStr).save();
    Encounter encounter3b = data.encounter().visit(visit3b).encounterType(exit).location(mensInternalMedicine).encounterDatetime("2013-10-02 16:45:00").save();
    data.obs().encounter(encounter3b).concept(dispositionConcept).value("Departed without medical discharge", "PIH").save();
    // Admitted earlier (Men's Internal Medicine), and discharged on 3 Oct
    patient4 = data.randomPatient().save();
    startDateStr = "2013-10-01 12:34:00";
    patient4 = this.conditionallySetBirthDateBeforeStartDate(patient4, startDateStr);
    Visit visit4 = data.visit().patient(patient4).visitType(atFacility).started(startDateStr).stopped("2013-10-03 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit4).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
    data.encounter().visit(visit4).encounterType(admission).location(mensInternalMedicine).encounterDatetime("2013-10-01 13:57:00").save();
    data.encounter().visit(visit4).encounterType(exit).location(mensInternalMedicine).encounterDatetime("2013-10-03 12:45:00").save();
    // consult with discharge
    Encounter encounter4a = data.encounter().visit(visit4).encounterType(consultation).location(mensInternalMedicine).encounterDatetime("2013-10-03 12:15:00").save();
    data.obs().encounter(encounter4a).concept(dispositionConcept).value("DISCHARGED", "PIH").save();
    // Begins the day of 3 Oct at Women's Inpatient (was admitted earlier), and transferred to Surgical Ward during the day
    patient5 = data.randomPatient().save();
    startDateStr = "2013-10-01 12:34:00";
    patient5 = this.conditionallySetBirthDateBeforeStartDate(patient5, startDateStr);
    Visit visit5 = data.visit().patient(patient5).visitType(atFacility).started(startDateStr).stopped("2013-10-13 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit5).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
    data.encounter().visit(visit5).encounterType(admission).location(womensInternalMedicine).encounterDatetime("2013-10-01 13:57:00").save();
    data.encounter().visit(visit5).encounterType(transfer).location(surgicalWard).encounterDatetime("2013-10-03 12:45:00").save();
    // Checks into ED during the day, transferred to surgery (with no admission), and has surgery
    patient6 = data.randomPatient().save();
    startDateStr = "2013-10-03 10:05:00";
    patient6 = this.conditionallySetBirthDateBeforeStartDate(patient6, startDateStr);
    Visit visit6 = data.visit().patient(patient6).visitType(atFacility).started(startDateStr).stopped("2013-10-03 18:32:21").location(visitLocation).save();
    data.encounter().visit(visit6).encounterType(checkIn).location(emergencyDepartment).encounterDatetime(startDateStr).save();
    data.encounter().visit(visit6).encounterType(transfer).location(surgicalWard).encounterDatetime("2013-10-03 12:45:00").save();
    data.encounter().visit(visit6).encounterType(postOpNote).location(surgicalWard).encounterDatetime("2013-10-03 14:53:00").save();
}
Also used : Concept(org.openmrs.Concept) Visit(org.openmrs.Visit) VisitType(org.openmrs.VisitType) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Location(org.openmrs.Location) Before(org.junit.Before)

Aggregations

VisitType (org.openmrs.VisitType)30 Test (org.junit.Test)18 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)18 Visit (org.openmrs.Visit)11 Encounter (org.openmrs.Encounter)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Patient (org.openmrs.Patient)5 EncounterType (org.openmrs.EncounterType)4 Location (org.openmrs.Location)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 Calendar (java.util.Calendar)2 Concept (org.openmrs.Concept)2 VisitAttribute (org.openmrs.VisitAttribute)2 VisitAttributeType (org.openmrs.VisitAttributeType)2 APIException (org.openmrs.api.APIException)2 VisitService (org.openmrs.api.VisitService)2 PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2