Search in sources :

Example 6 with VisitAttributeType

use of org.openmrs.VisitAttributeType in project openmrs-core by openmrs.

the class VisitServiceTest method createVisitAttributeWithoutCreatorAndDateCreated.

private VisitAttribute createVisitAttributeWithoutCreatorAndDateCreated() {
    VisitAttribute visitAttribute = new VisitAttribute();
    VisitAttributeType attributeType = visitService.getVisitAttributeType(1);
    attributeType.setName("visit type");
    visitAttribute.setValue(new Date());
    visitAttribute.setAttributeType(attributeType);
    return visitAttribute;
}
Also used : VisitAttributeType(org.openmrs.VisitAttributeType) VisitAttribute(org.openmrs.VisitAttribute) Date(java.util.Date)

Example 7 with VisitAttributeType

use of org.openmrs.VisitAttributeType 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 8 with VisitAttributeType

use of org.openmrs.VisitAttributeType 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 9 with VisitAttributeType

use of org.openmrs.VisitAttributeType 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)

Example 10 with VisitAttributeType

use of org.openmrs.VisitAttributeType 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)

Aggregations

VisitAttributeType (org.openmrs.VisitAttributeType)17 Test (org.junit.Test)9 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)9 Visit (org.openmrs.Visit)7 VisitAttribute (org.openmrs.VisitAttribute)5 Date (java.util.Date)4 APIException (org.openmrs.api.APIException)3 BindException (org.springframework.validation.BindException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 VisitType (org.openmrs.VisitType)2 PatientDomainWrapper (org.openmrs.module.emrapi.patient.PatientDomainWrapper)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ObjectResult (org.openmrs.ui.framework.fragment.action.ObjectResult)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BindingResult (org.springframework.validation.BindingResult)2 Errors (org.springframework.validation.Errors)2 Criteria (org.hibernate.Criteria)1 Before (org.junit.Before)1 Patient (org.openmrs.Patient)1