Search in sources :

Example 1 with ObjectResult

use of org.openmrs.ui.framework.fragment.action.ObjectResult in project openmrs-module-coreapps by openmrs.

the class QuickVisitFragmentController method update.

public FragmentActionResult update(@SpringBean("visitService") VisitService visitService, @RequestParam("patientId") Patient patient, @RequestParam("visitId") Visit visit, @RequestParam(value = "selectedTypeId", required = false) VisitType selectedType, UiUtils uiUtils, HttpServletRequest request) {
    BindingResult bindingResult = null;
    if (selectedType != null) {
        visit.setVisitType(selectedType);
    }
    if (request.getParameterNames() != null && request.getParameterNames().hasMoreElements()) {
        List<VisitAttributeType> attributeTypes = visitService.getAllVisitAttributeTypes();
        WebAttributeUtil.handleSubmittedAttributesForType(visit, bindingResult, VisitAttribute.class, request, attributeTypes);
    }
    try {
        visitService.saveVisit(visit);
    } catch (APIException e) {
        request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Visit.save.error");
    }
    request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, uiUtils.message("coreapps.visit.updateVisit.successMessage", uiUtils.format(patient)));
    request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
    SimpleObject result = SimpleObject.create("success", true, "search", "?patientId=" + visit.getPatient().getId() + "&visitId=" + visit.getId());
    return new ObjectResult(result);
}
Also used : BindingResult(org.springframework.validation.BindingResult) APIException(org.openmrs.api.APIException) SimpleObject(org.openmrs.ui.framework.SimpleObject) VisitAttributeType(org.openmrs.VisitAttributeType) ObjectResult(org.openmrs.ui.framework.fragment.action.ObjectResult)

Example 2 with ObjectResult

use of org.openmrs.ui.framework.fragment.action.ObjectResult in project openmrs-module-coreapps by openmrs.

the class QuickVisitFragmentController method create.

@Transactional
public FragmentActionResult create(@SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @RequestParam("patientId") Patient patient, @RequestParam("locationId") Location location, UiUtils uiUtils, @RequestParam(value = "selectedTypeId", required = false) VisitType selectedType, UiSessionContext emrContext, HttpServletRequest request) {
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, location);
    BindingResult bindingResult = null;
    if (activeVisit != null) {
        return new FailureResult(uiUtils.message("coreapps.activeVisits.alreadyExists"));
    }
    Visit visit = adtService.ensureVisit(patient, new Date(), location);
    if (selectedType != null) {
        // set visit type
        visit.setVisitType(selectedType);
        // manually handle the attribute parameters
        List<VisitAttributeType> attributeTypes = visitService.getAllVisitAttributeTypes();
        WebAttributeUtil.handleSubmittedAttributesForType(visit, bindingResult, VisitAttribute.class, request, attributeTypes);
        try {
            visitService.saveVisit(visit);
        } catch (APIException e) {
            return new FailureResult((uiUtils.message("Visit.save.error")));
        }
    }
    request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, uiUtils.message("coreapps.visit.createQuickVisit.successMessage", uiUtils.encodeHtml(uiUtils.format(patient))));
    request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
    SimpleObject result = SimpleObject.create("id", visit.getId().toString(), "uuid", visit.getUuid());
    return new ObjectResult(result);
}
Also used : BindingResult(org.springframework.validation.BindingResult) APIException(org.openmrs.api.APIException) SimpleObject(org.openmrs.ui.framework.SimpleObject) FailureResult(org.openmrs.ui.framework.fragment.action.FailureResult) Visit(org.openmrs.Visit) VisitAttributeType(org.openmrs.VisitAttributeType) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) ObjectResult(org.openmrs.ui.framework.fragment.action.ObjectResult) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

VisitAttributeType (org.openmrs.VisitAttributeType)2 APIException (org.openmrs.api.APIException)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ObjectResult (org.openmrs.ui.framework.fragment.action.ObjectResult)2 BindingResult (org.springframework.validation.BindingResult)2 Date (java.util.Date)1 Visit (org.openmrs.Visit)1 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)1 FailureResult (org.openmrs.ui.framework.fragment.action.FailureResult)1 Transactional (org.springframework.transaction.annotation.Transactional)1