Search in sources :

Example 16 with VisitType

use of org.openmrs.VisitType in project openmrs-module-coreapps by openmrs.

the class EditVisitFragmentController method controller.

public void controller(FragmentConfiguration config, FragmentModel model, @SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper, UiSessionContext sessionContext) {
    config.require("patient");
    config.require("visit");
    PatientDomainWrapper patientWrapper;
    Object patient = config.get("patient");
    if (patient instanceof PatientDomainWrapper) {
        patientWrapper = (PatientDomainWrapper) patient;
    } else {
        throw new IllegalArgumentException("Patient must be of type PatientDomainWrapper");
    }
    Visit visit = (Visit) config.get("visit");
    // get visit types
    List<VisitType> visitTypes = visitTypeHelper.getUnRetiredVisitTypes();
    // get visit attribute types
    List<VisitAttributeType> visitAttributeTypes = visitService.getAllVisitAttributeTypes();
    model.addAttribute("patient", patientWrapper);
    model.addAttribute("visit", visit);
    model.addAttribute("visitTypes", visitTypes);
    model.addAttribute("visitAttributeTypes", visitAttributeTypes);
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) Visit(org.openmrs.Visit) VisitType(org.openmrs.VisitType) VisitAttributeType(org.openmrs.VisitAttributeType)

Example 17 with VisitType

use of org.openmrs.VisitType in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method getUnRetiredVisitTypes.

public List<VisitType> getUnRetiredVisitTypes() {
    VisitService visitService = Context.getVisitService();
    List<VisitType> visitTypes = new ArrayList<VisitType>();
    for (VisitType visitType : visitService.getAllVisitTypes()) {
        if (visitType.getRetired() == false) {
            visitTypes.add(visitType);
        }
    }
    return visitTypes;
}
Also used : VisitService(org.openmrs.api.VisitService) ArrayList(java.util.ArrayList) VisitType(org.openmrs.VisitType)

Example 18 with VisitType

use of org.openmrs.VisitType in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method getOrderedVisitTypes.

/**
 * Returns a list of ordered visit types.
 *
 * @param visitTypes All the visit types
 * @param propertyValue The visit types to order in JSON-like format
 * @param visitService
 * @return visitTypesOrdered The visit types ordered and merged with the input visit type list
 */
public List<VisitType> getOrderedVisitTypes(List<VisitType> visitTypes, String propertyValue, VisitService visitService) {
    Map<Integer, String> order = null;
    List<VisitType> visitTypesOrdered = new ArrayList<VisitType>();
    if (propertyValue != null) {
        try {
            order = new ObjectMapper().readValue(propertyValue, HashMap.class);
        } catch (JsonParseException e) {
            VisitTypeHelper.LOG.error("Unable to parse global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (JsonMappingException e) {
            VisitTypeHelper.LOG.error("Unable to map global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (APIException e) {
            VisitTypeHelper.LOG.error("Unable to load global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (IOException e) {
            VisitTypeHelper.LOG.error("Unable to read global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        }
    }
    if (order != null) {
        for (int i = 1; i <= order.size(); i++) {
            String typeUuid = order.get(Integer.toString(i));
            VisitType type = visitService.getVisitTypeByUuid(typeUuid);
            if (visitTypes.contains(type)) {
                visitTypesOrdered.add(visitService.getVisitTypeByUuid(typeUuid));
            }
        }
        for (VisitType type : visitTypes) {
            if (!order.containsValue(type.getUuid())) {
                visitTypesOrdered.add(type);
            }
        }
    }
    if (!(visitTypes.size() == visitTypesOrdered.size())) {
        VisitTypeHelper.LOG.warn("Visit Types order property is not used.");
        return visitTypes;
    }
    return visitTypesOrdered;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) APIException(org.openmrs.api.APIException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) VisitType(org.openmrs.VisitType) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 19 with VisitType

use of org.openmrs.VisitType in project openmrs-module-coreapps by openmrs.

the class VisitIncludesFragmentController method controller.

public void controller(FragmentConfiguration config, FragmentModel model, @InjectBeans PatientDomainWrapper wrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper, UiSessionContext sessionContext, HttpServletRequest request, @SpringBean("patientService") PatientService patientService) {
    Object patient = config.get("patient");
    if (patient == null) {
        // retrieve patient id from parameter map
        if (request.getParameter("patientId") != null) {
            String patientId = request.getParameter("patientId");
            if (patientId != null) {
                if (!NumberUtils.isDigits(patientId)) {
                    patient = patientService.getPatientByUuid(patientId);
                } else {
                    patient = patientService.getPatient(NumberUtils.toInt(patientId));
                }
            }
        }
    }
    if (patient instanceof Patient) {
        wrapper.setPatient((Patient) patient);
    } else if (patient instanceof PatientDomainWrapper) {
        wrapper = (PatientDomainWrapper) patient;
    } else {
        throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
    }
    model.addAttribute("patient", wrapper);
    List<VisitType> visitTypes = visitTypeHelper.getUnRetiredVisitTypes();
    // send active visits to the view, if any.
    List<Visit> activeVisits = visitService.getActiveVisitsByPatient(wrapper.getPatient());
    // get visit attributes
    List<VisitAttributeType> visitAttributeTypes = visitService.getAllVisitAttributeTypes();
    // get the current visit's visit type, if any active visit at the current visit location
    VisitDomainWrapper activeVisitWrapper = adtService.getActiveVisit(wrapper.getPatient(), sessionContext.getSessionLocation());
    if (activeVisitWrapper != null) {
        VisitType currentVisitType = activeVisitWrapper.getVisit().getVisitType();
        model.addAttribute("currentVisitType", currentVisitType);
    } else {
        model.addAttribute("currentVisitType", null);
    }
    model.addAttribute("activeVisits", activeVisits);
    model.addAttribute("visitTypes", visitTypes);
    model.addAttribute("visitAttributeTypes", visitAttributeTypes);
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitType(org.openmrs.VisitType) VisitAttributeType(org.openmrs.VisitAttributeType) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper)

Example 20 with VisitType

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

the class BaseInpatientReportTest method setupDontOverrideBaseClassSetup.

@Before
public void setupDontOverrideBaseClassSetup() throws Exception {
    VisitType atFacility = visitService.getVisitTypeByUuid(VisitTypeBundle.VisitTypes.CLINIC_OR_HOSPITAL_VISIT);
    EncounterType checkIn = Metadata.lookup(EncounterTypes.CHECK_IN);
    EncounterType admission = Metadata.lookup(EncounterTypes.ADMISSION);
    EncounterType transfer = Metadata.lookup(EncounterTypes.TRANSFER);
    EncounterType exit = Metadata.lookup(EncounterTypes.EXIT_FROM_CARE);
    EncounterType consultation = Metadata.lookup(EncounterTypes.CONSULTATION);
    EncounterType postOpNote = Metadata.lookup(EncounterTypes.POST_OPERATIVE_NOTE);
    Location visitLocation = Metadata.lookup(MirebalaisLocations.MIREBALAIS_CDI_PARENT);
    Location outpatientClinic = Metadata.lookup(MirebalaisLocations.OUTPATIENT_CLINIC);
    Location womensInternalMedicine = Metadata.lookup(MirebalaisLocations.WOMENS_INTERNAL_MEDICINE);
    Location mensInternalMedicine = Metadata.lookup(MirebalaisLocations.MENS_INTERNAL_MEDICINE);
    Location surgicalWard = Metadata.lookup(MirebalaisLocations.SURGICAL_WARD);
    Location emergencyDepartment = Metadata.lookup(MirebalaisLocations.EMERGENCY);
    Concept dispositionConcept = conceptService.getConceptByUuid("c8b22b09-e2f2-4606-af7d-e52579996de3");
    // Already admitted at start of 3 Oct (Women's Internal Medicine)
    patient1 = data.randomPatient().save();
    Visit visit1 = data.visit().patient(patient1).visitType(atFacility).started("2013-10-02 09:15:00").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();
    Visit visit2 = data.visit().patient(patient2).visitType(atFacility).started("2013-10-01 17:30:00").stopped("2013-10-03 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit2).encounterType(checkIn).location(outpatientClinic).encounterDatetime("2013-10-01 17:30:00").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();
    Visit visit3a = data.visit().patient(patient3).visitType(atFacility).started("2013-10-03 12:34:00").stopped("2013-10-07 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit3a).encounterType(checkIn).location(outpatientClinic).encounterDatetime("2013-10-03 12:34:00").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
    Visit visit3b = data.visit().patient(patient3).visitType(atFacility).started("2013-10-02 12:34:00").stopped("2013-10-02 16:45:00").location(visitLocation).save();
    data.encounter().visit(visit3b).encounterType(admission).location(mensInternalMedicine).encounterDatetime("2013-10-02 12:34:00").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();
    Visit visit4 = data.visit().patient(patient4).visitType(atFacility).started("2013-10-01 12:34:00").stopped("2013-10-03 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit4).encounterType(checkIn).location(outpatientClinic).encounterDatetime("2013-10-01 12:34:00").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();
    Visit visit5 = data.visit().patient(patient5).visitType(atFacility).started("2013-10-01 12:34:00").stopped("2013-10-13 12:45:00").location(visitLocation).save();
    data.encounter().visit(visit5).encounterType(checkIn).location(outpatientClinic).encounterDatetime("2013-10-01 12:34:00").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();
    Visit visit6 = data.visit().patient(patient6).visitType(atFacility).started("2013-10-03 10:05:00").stopped("2013-10-03 18:32:21").location(visitLocation).save();
    data.encounter().visit(visit6).encounterType(checkIn).location(emergencyDepartment).encounterDatetime("2013-10-03 10:05:00").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