Search in sources :

Example 1 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-pihcore by PIH.

the class VitalsListPageController method get.

public String get(PageModel model, UiUtils ui, @SpringBean("encounterService") EncounterService encounterService, @SpringBean("personService") PersonService personService) {
    // TODO restrict by location at some point if necessary
    Map<Patient, Encounter> patientsWithCheckInEncounter = new LinkedHashMap<Patient, Encounter>();
    // all patients that have a check-in encounter today, but no vitals encounter
    List<Encounter> checkInEncounters = encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(encounterService.getEncounterTypeByUuid(EncounterTypes.CHECK_IN.uuid())), null, null, null, false);
    List<Encounter> vitalsEncounters = encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(encounterService.getEncounterTypeByUuid(EncounterTypes.VITALS.uuid())), null, null, null, false);
    for (Encounter encounter : checkInEncounters) {
        // sanity check on visit
        if (encounter.getVisit() != null) {
            // we check that the patient isn't already in the list instead of just inserting again because we want to keep the earliest date
            if (!patientsWithCheckInEncounter.containsKey(encounter.getPatient())) {
                patientsWithCheckInEncounter.put(encounter.getPatient(), encounter);
            }
        }
    }
    for (Encounter encounter : vitalsEncounters) {
        if (patientsWithCheckInEncounter.containsKey(encounter.getPatient())) {
            patientsWithCheckInEncounter.remove(encounter.getPatient());
        }
    }
    SimpleObject vitalsListBreadcrumb = SimpleObject.create("label", ui.message("pihcore.vitalsList.title"), "link", ui.pageLink("pihcore", "vitals/vitalsList"));
    // used to determine whether or not we display a link to the patient in the results list
    model.addAttribute("patientWithCheckInEncounter", patientsWithCheckInEncounter);
    model.addAttribute("mothersFirstName", personService.getPersonAttributeTypeByUuid(HaitiPersonAttributeTypes.MOTHERS_FIRST_NAME.uuid()));
    model.addAttribute("dossierIdentifierName", PihHaitiPatientIdentifierTypes.DOSSIER_NUMBER.name());
    model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(vitalsListBreadcrumb)));
    return null;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) DateMidnight(org.joda.time.DateMidnight) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-pihcore by PIH.

the class MonthSinceMirebalaisOpeningFragmentController method controller.

public void controller(FragmentModel model) {
    List<SimpleObject> months = new ArrayList<SimpleObject>();
    YearMonth earliest = new YearMonth(2013, 2);
    YearMonth month = new YearMonth().minusMonths(1);
    while (month.isAfter(earliest)) {
        months.add(SimpleObject.create("label", month.toString("MMM yyyy", Context.getLocale()), "value", month.toString("yyyy-MM-01")));
        month = month.minusMonths(1);
    }
    model.addAttribute("months", months);
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) YearMonth(org.joda.time.YearMonth) ArrayList(java.util.ArrayList)

Example 3 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-pihcore by PIH.

the class RegistrationsByAgeReportFragmentController method evaluate.

public SimpleObject evaluate(@SpringBean DataSetDefinitionService dataSetDefinitionService, @SpringBean RegistrationDataSetManager registrationDataSetManager, @RequestParam(value = "startDate", required = false) Date startDate, @RequestParam(value = "endDate", required = false) Date endDate, PageModel model, UiUtils ui) throws Exception {
    Map<String, AgeResult> registrationsByAge = new LinkedHashMap<String, AgeResult>();
    EvaluationContext context = new EvaluationContext();
    context.addParameterValue(ReportingConstants.START_DATE_PARAMETER.getName(), startDate);
    context.addParameterValue(ReportingConstants.END_DATE_PARAMETER.getName(), endDate);
    DataSetDefinition dsd = registrationDataSetManager.constructDataSet();
    SimpleDataSet dataSet = (SimpleDataSet) dataSetDefinitionService.evaluate(dsd, context);
    List<String> columns = new ArrayList<String>();
    columns.add("EMR_ID");
    columns.add("GIVEN_NAME");
    columns.add("FAMILY_NAME");
    columns.add("AGE_AT_REGISTRATION");
    columns.add("BIRTHDATE");
    columns.add("GENDER");
    columns.add("REGISTRATION_DATE");
    List<String> ageCategories = new ArrayList<String>();
    ageCategories.add(getAgeCategory(0.0));
    for (Integer bound : ageBoundaries) {
        ageCategories.add(getAgeCategory(bound.doubleValue()));
    }
    String totalCategory = ui.message("pihcore.total");
    ageCategories.add(totalCategory);
    for (DataSetRow row : dataSet) {
        Double patientAge = (Double) row.getColumnValue("AGE_AT_REGISTRATION");
        String ageCategory = getAgeCategory(patientAge);
        Map<String, Object> m = new HashMap<String, Object>();
        for (String column : columns) {
            m.put(column, ui.format(row.getColumnValue(column)));
        }
        getAgeResult(registrationsByAge, ageCategory).addRow(m);
        getAgeResult(registrationsByAge, totalCategory).addRow(m);
    }
    List<String> columnLabels = new ArrayList<String>();
    for (String column : columns) {
        columnLabels.add(ui.message("pihcore." + column.toLowerCase()));
    }
    SimpleObject result = new SimpleObject();
    result.put("startDate", startDate);
    result.put("endDate", endDate);
    result.put("ageCategories", ageCategories);
    result.put("columns", columns);
    result.put("columnLabels", columnLabels);
    result.put("registrationsByAge", registrationsByAge);
    return result;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SimpleDataSet(org.openmrs.module.reporting.dataset.SimpleDataSet) DataSetDefinition(org.openmrs.module.reporting.dataset.definition.DataSetDefinition) LinkedHashMap(java.util.LinkedHashMap) SimpleObject(org.openmrs.ui.framework.SimpleObject) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DataSetRow(org.openmrs.module.reporting.dataset.DataSetRow)

Example 4 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-pihcore by PIH.

the class CheckinPageController method controller.

public Object controller(@RequestParam("patientId") Patient patient, @RequestParam(value = "closeVisit", required = false) Boolean closeVisit, UiUtils ui, UiSessionContext uiSessionContext, PageModel model, EmrApiProperties emrApiProperties, @SpringBean AdtService adtService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
    patientDomainWrapper.setPatient(patient);
    VisitDomainWrapper activeVisit = patientDomainWrapper.getActiveVisit(uiSessionContext.getSessionLocation());
    if (closeVisit != null && closeVisit && activeVisit != null) {
        adtService.closeAndSaveVisit(activeVisit.getVisit());
        activeVisit = null;
    }
    // if there is no active visit, redirect directly to the form
    if (activeVisit == null) {
        return new Redirect("/registrationapp/registrationSummary.page?patientId=" + patient.getId() + "&appId=registrationapp.registerPatient" + "&breadcrumbOverrideProvider=coreapps&breadcrumbOverridePage=findpatient%2FfindPatient&breadcrumbOverrideApp=mirebalais.liveCheckin&breadcrumbOverrideLabel=mirebalais.app.patientRegistration.checkin.label");
    } else // prompt the user to see if they want close the existing visit
    {
        List<Encounter> existingEncounters = new ArrayList<Encounter>();
        if (activeVisit != null) {
            for (Encounter encounter : activeVisit.getVisit().getEncounters()) {
                if (!encounter.isVoided() && emrApiProperties.getCheckInEncounterType().equals(encounter.getEncounterType())) {
                    existingEncounters.add(encounter);
                }
            }
        }
        SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.escapeJs(ui.message("mirebalais.checkin.title")));
        SimpleObject patientPageBreadcrumb = SimpleObject.create("label", ui.escapeJs(patient.getFamilyName()) + ", " + ui.escapeJs(patient.getGivenName()), "link", ui.thisUrlWithContextPath());
        model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
        model.addAttribute("activeVisit", activeVisit);
        model.addAttribute("existingEncounters", existingEncounters);
        model.addAttribute("patient", patientDomainWrapper);
        model.addAttribute("appName", "mirebalais.liveCheckin");
        return null;
    }
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Redirect(org.openmrs.ui.framework.page.Redirect)

Example 5 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-pihcore by PIH.

the class CheckInsByAgeReportFragmentController method evaluate.

public SimpleObject evaluate(@SpringBean DataSetDefinitionService dataSetDefinitionService, @SpringBean CheckInDataSetManager checkInDataSetManager, @RequestParam(value = "startDate", required = false) Date startDate, @RequestParam(value = "endDate", required = false) Date endDate, PageModel model, UiUtils ui) throws Exception {
    Map<String, AgeResult> checkInsByAge = new LinkedHashMap<String, AgeResult>();
    EvaluationContext context = new EvaluationContext();
    context.addParameterValue(ReportingConstants.START_DATE_PARAMETER.getName(), startDate);
    context.addParameterValue(ReportingConstants.END_DATE_PARAMETER.getName(), endDate);
    DataSetDefinition dsd = checkInDataSetManager.constructDataSet();
    SimpleDataSet dataSet = (SimpleDataSet) dataSetDefinitionService.evaluate(dsd, context);
    List<String> columns = new ArrayList<String>();
    columns.add("CHECK_IN_DATE");
    columns.add("EMR_ID");
    columns.add("GIVEN_NAME");
    columns.add("FAMILY_NAME");
    columns.add("AGE_AT_CHECK_IN");
    columns.add("BIRTHDATE");
    columns.add("GENDER");
    columns.add("TYPE_OF_VISIT");
    List<String> ageCategories = new ArrayList<String>();
    ageCategories.add(getAgeCategory(0.0));
    for (Integer bound : ageBoundaries) {
        ageCategories.add(getAgeCategory(bound.doubleValue()));
    }
    String totalCategory = ui.message("pihcore.total");
    ageCategories.add(totalCategory);
    for (DataSetRow row : dataSet) {
        Double patientAge = (Double) row.getColumnValue("AGE_AT_CHECK_IN");
        String ageCategory = getAgeCategory(patientAge);
        Map<String, Object> m = new HashMap<String, Object>();
        for (String column : columns) {
            m.put(column, ui.format(row.getColumnValue(column)));
        }
        getAgeResult(checkInsByAge, ageCategory).addRow(m);
        getAgeResult(checkInsByAge, totalCategory).addRow(m);
    }
    List<String> columnLabels = new ArrayList<String>();
    for (String column : columns) {
        columnLabels.add(ui.message("pihcore." + column.toLowerCase()));
    }
    SimpleObject result = new SimpleObject();
    result.put("startDate", startDate);
    result.put("endDate", endDate);
    result.put("ageCategories", ageCategories);
    result.put("columns", columns);
    result.put("columnLabels", columnLabels);
    result.put("checkInsByAge", checkInsByAge);
    return result;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SimpleDataSet(org.openmrs.module.reporting.dataset.SimpleDataSet) DataSetDefinition(org.openmrs.module.reporting.dataset.definition.DataSetDefinition) LinkedHashMap(java.util.LinkedHashMap) SimpleObject(org.openmrs.ui.framework.SimpleObject) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DataSetRow(org.openmrs.module.reporting.dataset.DataSetRow)

Aggregations

SimpleObject (org.openmrs.ui.framework.SimpleObject)67 Test (org.junit.Test)37 Location (org.openmrs.Location)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)26 ArrayList (java.util.ArrayList)18 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)17 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)13 Config (org.openmrs.module.pihcore.config.Config)12 DateTime (org.joda.time.DateTime)11 Date (java.util.Date)9 Encounter (org.openmrs.Encounter)9 Concept (org.openmrs.Concept)6 Patient (org.openmrs.Patient)6 Obs (org.openmrs.Obs)5 Visit (org.openmrs.Visit)5 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)3 ConceptSearchResult (org.openmrs.ConceptSearchResult)3 Form (org.openmrs.Form)3