Search in sources :

Example 1 with MissingRequiredParameterException

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

the class VisitPageController method get.

public void get(@SpringBean("visitService") VisitService visitService, @InjectBeans PatientDomainWrapper patientDomainWrapper, @RequestParam(required = false, value = "patient") Patient patient, @RequestParam(required = false, value = "visit") Visit visit, @RequestParam(required = false, value = "encounter") Encounter enc, // passed by the htmformentryui module after form submission creates new encounter (really should be "encounter" for consistency)
@RequestParam(required = false, value = "encounterId") Encounter encounterById, @RequestParam(required = false, value = "goToNextSection") String goToNextSection, UiSessionContext uiSessionContext, PageModel model) {
    // there are two params that could pass in an encounter, test which one, if any, was used to pass in a value
    Encounter encounter = enc != null ? enc : (encounterById != null ? encounterById : null);
    // fwiw, you are allowed to have a patient without a visit, but only if viewing the "visitList" view
    if (patient == null) {
        if (visit != null) {
            patient = visit.getPatient();
        } else if (encounter != null) {
            patient = encounter.getPatient();
        } else {
            throw new MissingRequiredParameterException("patient or visit or encounter is required");
        }
    }
    // see if we can get a visit from the encounter
    if (visit == null && encounter != null) {
        visit = encounter.getVisit();
    }
    patientDomainWrapper.setPatient(patient);
    model.addAttribute("patient", patientDomainWrapper);
    model.addAttribute("visit", visit);
    model.addAttribute("encounter", encounter);
    model.addAttribute("locale", uiSessionContext.getLocale());
    model.addAttribute("goToNextSection", goToNextSection);
}
Also used : Encounter(org.openmrs.Encounter) MissingRequiredParameterException(org.openmrs.ui.framework.MissingRequiredParameterException)

Aggregations

Encounter (org.openmrs.Encounter)1 MissingRequiredParameterException (org.openmrs.ui.framework.MissingRequiredParameterException)1