Search in sources :

Example 1 with PatientDomainWrapper

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

the class VisitsSectionFragmentController method controller.

public void controller(FragmentConfiguration config, PageModel pageModel, FragmentModel model, UiUtils ui, UiSessionContext sessionContext, @SpringBean("appframeworkTemplateFactory") TemplateFactory templateFactory, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper) {
    config.require("patient");
    Object patient = config.get("patient");
    if (patient instanceof Patient) {
        patientWrapper.setPatient((Patient) patient);
        config.addAttribute("patient", patientWrapper);
    } else if (patient instanceof PatientDomainWrapper) {
        patientWrapper = (PatientDomainWrapper) patient;
    }
    AppContextModel contextModel = sessionContext.generateAppContextModel();
    contextModel.put("patient", new PatientContextModel(patientWrapper.getPatient()));
    // backwards-compatible for links that still specify patient uuid substitution with "{{patientId}}"
    contextModel.put("patientId", patientWrapper.getPatient().getUuid());
    AppDescriptor app = (AppDescriptor) pageModel.get("app");
    String visitsPageWithSpecificVisitUrl = null;
    String visitsPageUrl = null;
    // see if the app specifies urls to use
    if (app != null) {
        try {
            visitsPageWithSpecificVisitUrl = app.getConfig().get("visitUrl").getTextValue();
        } catch (Exception ex) {
        }
        try {
            visitsPageUrl = app.getConfig().get("visitsUrl").getTextValue();
        } catch (Exception ex) {
        }
    }
    if (visitsPageWithSpecificVisitUrl == null) {
        visitsPageWithSpecificVisitUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
    }
    visitsPageWithSpecificVisitUrl = "/" + ui.contextPath() + "/" + visitsPageWithSpecificVisitUrl;
    if (visitsPageUrl == null) {
        visitsPageUrl = coreAppsProperties.getVisitsPageUrl();
    }
    // hack fix for RA-1002--if there is an active visit, and we are using the "regular" visit dashboard we actually want to link to the specific visit
    Location visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patientWrapper.getPatient(), visitLocation);
    if (visitsPageUrl.contains("/coreapps/patientdashboard/patientDashboard.page?") && activeVisit != null) {
        visitsPageUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
        contextModel.put("visit", activeVisit.getVisit());
    }
    visitsPageUrl = "/" + ui.contextPath() + "/" + visitsPageUrl;
    model.addAttribute("visitsUrl", templateFactory.handlebars(visitsPageUrl, contextModel));
    List<VisitDomainWrapper> recentVisits = patientWrapper.getAllVisitsUsingWrappers();
    if (recentVisits.size() > 5) {
        recentVisits = recentVisits.subList(0, 5);
    }
    Map<VisitDomainWrapper, String> recentVisitsWithLinks = new LinkedHashMap<VisitDomainWrapper, String>();
    for (VisitDomainWrapper recentVisit : recentVisits) {
        contextModel.put("visit", new VisitContextModel(recentVisit));
        // since the "recentVisit" isn't part of the context module, we bind it first to the visit url, before doing the handlebars binding against the context
        recentVisitsWithLinks.put(recentVisit, templateFactory.handlebars(ui.urlBind(visitsPageWithSpecificVisitUrl, recentVisit.getVisit()), contextModel));
    }
    Map<Integer, Map<String, Object>> recentVisitsWithAttr = visitTypeHelper.getVisitColorAndShortName(recentVisits);
    model.addAttribute("recentVisitsWithAttr", recentVisitsWithAttr);
    model.addAttribute("recentVisitsWithLinks", recentVisitsWithLinks);
    config.addAttribute("showVisitTypeOnPatientHeaderSection", visitTypeHelper.showVisitTypeOnPatientHeaderSection());
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) Patient(org.openmrs.Patient) LinkedHashMap(java.util.LinkedHashMap) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) AppDescriptor(org.openmrs.module.appframework.domain.AppDescriptor) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Location(org.openmrs.Location)

Example 2 with PatientDomainWrapper

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

the class DiagnosisWidgetFragmentController method controller.

public void controller(FragmentConfiguration config, @InjectBeans PatientDomainWrapper patientWrapper, @InjectBeans CoreAppsProperties properties) {
    config.require("patient");
    Object patient = config.get("patient");
    if (patient instanceof Patient) {
        patientWrapper.setPatient((Patient) patient);
        config.addAttribute("patient", patientWrapper);
    } else if (patient instanceof PatientDomainWrapper) {
        patientWrapper = (PatientDomainWrapper) patient;
    } else {
        throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
    }
    int days = properties.getRecentDiagnosisPeriodInDays();
    Calendar recent = Calendar.getInstance();
    recent.set(Calendar.DATE, -days);
    List<Diagnosis> recentDiagnoses = patientWrapper.getUniqueDiagnosesSince(recent.getTime());
    config.addAttribute("recentDiagnoses", recentDiagnoses);
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) Calendar(java.util.Calendar) Patient(org.openmrs.Patient) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis)

Example 3 with PatientDomainWrapper

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

the class DashboardWidgetFragmentController method controller.

public void controller(FragmentConfiguration config, @FragmentParam("app") AppDescriptor app, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("adminService") AdministrationService adminService) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    Object patient = null;
    patient = config.get("patient");
    if (patient == null) {
        patient = config.get("patientId");
    }
    ObjectNode appConfig = app.getConfig();
    if (patient != null) {
        if (patient instanceof Patient) {
            patientWrapper.setPatient((Patient) patient);
        } else if (patient instanceof PatientDomainWrapper) {
            patientWrapper = (PatientDomainWrapper) patient;
        } else if (patient instanceof Integer) {
            // assume we have patientId
            patientWrapper.setPatient(Context.getPatientService().getPatient((Integer) patient));
        } else {
            throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
        }
        appConfig.put("patientUuid", patientWrapper.getPatient().getUuid());
    }
    if (appConfig.get("dateFormat") == null) {
        appConfig.put("dateFormat", adminService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATE_FORMAT, "yyyy-MM-dd"));
    }
    appConfig.put("locale", Context.getLocale().toString());
    appConfig.put("language", Context.getLocale().getLanguage().toString());
    Map<String, Object> appConfigMap = mapper.convertValue(appConfig, Map.class);
    config.merge(appConfigMap);
    config.addAttribute("json", appConfig.toString().replace('\"', '\''));
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) ObjectNode(org.codehaus.jackson.node.ObjectNode) Patient(org.openmrs.Patient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 4 with PatientDomainWrapper

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

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

the class ProgramHistoryFragmentController method controller.

public void controller(FragmentConfiguration config, @FragmentParam("app") AppDescriptor app, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("programWorkflowService") ProgramWorkflowService programWorkflowService) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    Object patient = null;
    patient = config.get("patient");
    if (patient == null) {
        patient = config.get("patientId");
    }
    if (patient == null) {
        config.require("patient");
    }
    if (patient instanceof Patient) {
        patientWrapper.setPatient((Patient) patient);
    } else if (patient instanceof PatientDomainWrapper) {
        patientWrapper = (PatientDomainWrapper) patient;
    } else if (patient instanceof Integer) {
        // assume we have patientId
        patientWrapper.setPatient(Context.getPatientService().getPatient((Integer) patient));
    } else {
        throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
    }
    ObjectNode appConfig = app.getConfig();
    appConfig.put("patientUuid", patientWrapper.getPatient().getUuid());
    if (appConfig.get("program") == null || StringUtils.isEmpty(appConfig.get("program").getTextValue())) {
        throw new MissingPropertyException("Program must be specified");
    }
    Program program = programWorkflowService.getProgramByUuid(appConfig.get("program").getTextValue());
    if (program == null) {
        throw new MissingPropertyException("Invalid program");
    }
    List<PatientProgram> patientPrograms = programWorkflowService.getPatientPrograms(patientWrapper.getPatient(), program, null, null, null, null, false);
    // TODO: assumption here is that "getPatientPrograms" returns results in chronological order--need to confirm?
    Collections.reverse(patientPrograms);
    List<String> programJson = new ArrayList<String>();
    Boolean includeActive = appConfig.get("includeActive") != null ? appConfig.get("includeActive").getBooleanValue() : true;
    Boolean includeInactive = appConfig.get("includeInactive") != null ? appConfig.get("includeInactive").getBooleanValue() : true;
    for (PatientProgram patientProgram : patientPrograms) {
        if ((patientProgram.getDateCompleted() == null && includeActive) || (patientProgram.getDateCompleted() != null && includeInactive)) {
            appConfig.put("patientProgram", patientProgram.getUuid());
            programJson.add(appConfig.toString().replace('\"', '\''));
        }
    }
    Map<String, Object> appConfigMap = mapper.convertValue(appConfig, Map.class);
    config.merge(appConfigMap);
    config.addAttribute("programJson", programJson);
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) MissingPropertyException(groovy.lang.MissingPropertyException) PatientProgram(org.openmrs.PatientProgram) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

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