Search in sources :

Example 6 with PatientDomainWrapper

use of org.openmrs.module.emrapi.patient.PatientDomainWrapper 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 7 with PatientDomainWrapper

use of org.openmrs.module.emrapi.patient.PatientDomainWrapper in project openmrs-module-pihcore by PIH.

the class WaitingForConsultPageController method get.

public String get(PageModel model, @RequestParam(required = false, value = "filter") String filterString, @SpringBean("encounterService") EncounterService encounterService, @SpringBean("obsService") ObsService obsService, @SpringBean("conceptService") ConceptService conceptService, @SpringBean("personService") PersonService personService, @SpringBean("domainWrapperFactory") DomainWrapperFactory domainWrapperFactory) {
    // TODO restrict by location at some point if necessary
    Filter filter;
    if (filterString != null && filterString.toLowerCase().equals("in_consultation")) {
        filter = Filter.IN_CONSULTATION;
    } else {
        filter = Filter.WAITING_FOR_CONSULT;
    }
    List<EncounterType> primaryCareEncounterTypes = new ArrayList<EncounterType>();
    primaryCareEncounterTypes.add(encounterService.getEncounterTypeByUuid(EncounterTypes.PRIMARY_CARE_VISIT.uuid()));
    primaryCareEncounterTypes.add(encounterService.getEncounterTypeByUuid(EncounterTypes.PRIMARY_CARE_PEDS_INITIAL_CONSULT.uuid()));
    primaryCareEncounterTypes.add(encounterService.getEncounterTypeByUuid(EncounterTypes.PRIMARY_CARE_PEDS_FOLLOWUP_CONSULT.uuid()));
    primaryCareEncounterTypes.add(encounterService.getEncounterTypeByUuid(EncounterTypes.PRIMARY_CARE_ADULT_INITIAL_CONSULT.uuid()));
    primaryCareEncounterTypes.add(encounterService.getEncounterTypeByUuid(EncounterTypes.PRIMARY_CARE_ADULT_FOLLOWUP_CONSULT.uuid()));
    // first handle any patients with vitals taken today:
    // create a list of all patients that have a vitals encounter today, *ordered by time of first vitals encounter*
    LinkedHashSet<Patient> patientsWithVitalsToday = new LinkedHashSet<Patient>();
    for (Encounter encounter : encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(encounterService.getEncounterTypeByUuid(EncounterTypes.VITALS.uuid())), null, null, null, false)) {
        patientsWithVitalsToday.add(encounter.getPatient());
    }
    // fetch the set of all patients that have a primary care encounter today
    Set<Patient> patientsWithConsultToday = new HashSet<Patient>();
    for (Encounter encounter : encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, primaryCareEncounterTypes, null, null, null, false)) {
        patientsWithConsultToday.add(encounter.getPatient());
    }
    // fetch the set of all patients who have a disposition today
    Set<Patient> patientsWithDispositionToday = new HashSet<Patient>();
    Concept dispoConceptSet = conceptService.getConceptByMapping(EmrApiConstants.CONCEPT_CODE_DISPOSITION_CONCEPT_SET, EmrApiConstants.EMR_CONCEPT_SOURCE_NAME);
    for (Obs obs : obsService.getObservations(null, null, Collections.singletonList(dispoConceptSet), null, null, null, null, null, null, new DateMidnight().toDate(), null, false)) {
        // assumption: only patients have obs, not plain persio
        patientsWithDispositionToday.add((Patient) obs.getPerson());
    }
    LinkedHashSet<Patient> patientListForToday = patientsWithVitalsToday;
    // assumption: you can't have a disposition without also having a consult
    if (filter.equals(Filter.WAITING_FOR_CONSULT)) {
        // the "waiting for consult" list is all patients with vitals today but no consult
        patientListForToday.removeAll(patientsWithConsultToday);
    } else {
        // the "in-consultation" list is all patients with vitals AND consult today but no dispostion (disposition is our trigger that a consult is finished)
        patientListForToday.retainAll(patientsWithConsultToday);
        patientListForToday.removeAll(patientsWithDispositionToday);
    }
    // now handle any patients with vitals taken on the last business day
    boolean isMonday = new DateMidnight().getDayOfWeek() == DateTimeConstants.MONDAY;
    // create a list of all patients that have a vitals encounter on last business day, *ordered by time of first vitals encounter*
    LinkedHashSet<Patient> patientsWithVitalsOnPreviousBusinessDay = new LinkedHashSet<Patient>();
    for (Encounter encounter : encounterService.getEncounters(null, null, isMonday ? new DateMidnight().minusDays(3).toDate() : new DateMidnight().minusDays(1).toDate(), isMonday ? new DateMidnight().minusDays(2).toDate() : new DateMidnight().toDate(), null, Collections.singletonList(encounterService.getEncounterTypeByUuid(EncounterTypes.VITALS.uuid())), null, null, null, false)) {
        patientsWithVitalsOnPreviousBusinessDay.add(encounter.getPatient());
    }
    Set<Patient> patientsWithConsultOnPreviousBusinessDayOrToday = new HashSet<Patient>();
    // fetch the set of all patients that have a primary care encounter last business day
    for (Encounter encounter : encounterService.getEncounters(null, null, isMonday ? new DateMidnight().minusDays(3).toDate() : new DateMidnight().minusDays(1).toDate(), isMonday ? new DateMidnight().minusDays(2).toDate() : new DateMidnight().toDate(), null, primaryCareEncounterTypes, null, null, null, false)) {
        patientsWithConsultOnPreviousBusinessDayOrToday.add(encounter.getPatient());
    }
    // add all patiens with primary care encounter today
    patientsWithConsultOnPreviousBusinessDayOrToday.addAll(patientsWithConsultToday);
    Set<Patient> patientsWithDispositionOnPreviousDaysOrToday = new HashSet<Patient>();
    // fetch the set of all patients who have a disposition last business day
    for (Obs obs : obsService.getObservations(null, null, Collections.singletonList(dispoConceptSet), null, null, null, null, null, null, isMonday ? new DateMidnight().minusDays(3).toDate() : new DateMidnight().minusDays(1).toDate(), isMonday ? new DateMidnight().minusDays(2).toDate() : new DateMidnight().toDate(), false)) {
        // assumption: only patients have obs, not plain persio
        patientsWithDispositionOnPreviousDaysOrToday.add((Patient) obs.getPerson());
    }
    // add all patiens with disposition today
    patientsWithConsultOnPreviousBusinessDayOrToday.addAll(patientsWithDispositionToday);
    LinkedHashSet<Patient> patientListForPreviousBusinessDay = patientsWithVitalsOnPreviousBusinessDay;
    // assumption: you can't have a disposition without also having a consult
    if (filter.equals(Filter.WAITING_FOR_CONSULT)) {
        // the "waiting for consult" list is all patients with vitals last business day but no consult then or today
        patientListForPreviousBusinessDay.removeAll(patientsWithConsultOnPreviousBusinessDayOrToday);
    } else {
        // the "in-consultation" list is all patients with vitals last business day and consult last business day or today, but no disposition
        patientListForPreviousBusinessDay.retainAll(patientsWithConsultOnPreviousBusinessDayOrToday);
        patientListForPreviousBusinessDay.removeAll(patientsWithDispositionOnPreviousDaysOrToday);
    }
    // now create our final list by combining the list for the previous business day with the list for the current day
    LinkedHashSet<Patient> patientList = patientListForPreviousBusinessDay;
    patientList.addAll(patientListForToday);
    // now wrap them all in a patient domain wrapper
    List<PatientDomainWrapper> patientsListWrapped = new ArrayList<PatientDomainWrapper>();
    for (Patient patient : patientList) {
        patientsListWrapped.add(domainWrapperFactory.newPatientDomainWrapper(patient));
    }
    model.addAttribute("patientList", patientsListWrapped);
    model.addAttribute("filter", filter.toString().toLowerCase());
    model.addAttribute("dossierIdentifierName", PihHaitiPatientIdentifierTypes.DOSSIER_NUMBER.name());
    model.addAttribute("mothersFirstName", personService.getPersonAttributeTypeByUuid(HaitiPersonAttributeTypes.MOTHERS_FIRST_NAME.uuid()));
    return null;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) DateMidnight(org.joda.time.DateMidnight) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)7 Patient (org.openmrs.Patient)6 ArrayList (java.util.ArrayList)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 ObjectNode (org.codehaus.jackson.node.ObjectNode)2 Visit (org.openmrs.Visit)2 VisitAttributeType (org.openmrs.VisitAttributeType)2 VisitType (org.openmrs.VisitType)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2 MissingPropertyException (groovy.lang.MissingPropertyException)1 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 DateMidnight (org.joda.time.DateMidnight)1 Concept (org.openmrs.Concept)1 Encounter (org.openmrs.Encounter)1 EncounterType (org.openmrs.EncounterType)1 Location (org.openmrs.Location)1