Search in sources :

Example 41 with APIException

use of org.openmrs.api.APIException 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 42 with APIException

use of org.openmrs.api.APIException in project openmrs-module-coreapps by openmrs.

the class MarkPatientDeadPageController method post.

public String post(@SpringBean("patientService") PatientService patientService, @RequestParam(value = "causeOfDeath", required = false) String causeOfDeath, @RequestParam(value = "dead", required = false) Boolean dead, @RequestParam(value = "deathDate", required = false) Date deathDate, @RequestParam("patientId") String patientId, UiUtils ui, @RequestParam(value = "returnUrl", required = false) String returnUrl) {
    Patient patient = patientService.getPatientByUuid(patientId);
    try {
        Date date = new Date();
        if (dead != null && StringUtils.isNotBlank(causeOfDeath) && deathDate != null && !deathDate.before(patient.getBirthdate()) && !deathDate.after(date)) {
            patient.setDead(dead);
            patient.setCauseOfDeath(Context.getConceptService().getConceptByUuid(causeOfDeath));
            patient.setDeathDate(deathDate);
        } else {
            patient.setDeathDate(null);
            patient.setDead(false);
            patient.setCauseOfDeath(null);
        }
        patientService.savePatient(patient);
        return "redirect:" + ui.pageLink("coreapps", "clinicianfacing/patient", SimpleObject.create("patientId", patient.getId(), "returnUrl", returnUrl));
    } catch (APIException e) {
        log.error(e.getMessage(), e);
        return "redirect:" + ui.pageLink("coreapps", "markPatientDead", SimpleObject.create("patientId", patient.getId(), "returnUrl", returnUrl));
    }
}
Also used : APIException(org.openmrs.api.APIException) Patient(org.openmrs.Patient) Date(java.util.Date)

Example 43 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class FormServiceImpl method saveForm.

/**
 * @see org.openmrs.api.FormService#saveForm(org.openmrs.Form)
 */
@Override
public Form saveForm(Form form) throws APIException {
    checkIfFormsAreLocked();
    BindException errors = new BindException(form, "form");
    formValidator.validate(form, errors);
    if (errors.hasErrors()) {
        throw new APIException(errors);
    }
    if (form.getFormFields() != null) {
        for (FormField ff : form.getFormFields()) {
            if (ff.getForm() == null) {
                ff.setForm(form);
            } else if (!ff.getForm().equals(form)) {
                throw new APIException("Form.contains.FormField.error", new Object[] { ff });
            }
        }
    }
    return dao.saveForm(form);
}
Also used : APIException(org.openmrs.api.APIException) BindException(org.springframework.validation.BindException) FormField(org.openmrs.FormField)

Example 44 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class OrderServiceImpl method setProperty.

private void setProperty(Order order, String propertyName, Object value) {
    Boolean isAccessible = null;
    Field field = null;
    try {
        field = Order.class.getDeclaredField(propertyName);
        field.setAccessible(true);
        field.set(order, value);
    } catch (Exception e) {
        throw new APIException("Order.failed.set.property", new Object[] { propertyName, order }, e);
    } finally {
        if (field != null && isAccessible != null) {
            field.setAccessible(isAccessible);
        }
    }
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Field(java.lang.reflect.Field) APIException(org.openmrs.api.APIException) CannotStopDiscontinuationOrderException(org.openmrs.api.CannotStopDiscontinuationOrderException) MissingRequiredPropertyException(org.openmrs.api.MissingRequiredPropertyException) CannotDeleteObjectInUseException(org.openmrs.api.CannotDeleteObjectInUseException) CannotUpdateObjectInUseException(org.openmrs.api.CannotUpdateObjectInUseException) OrderEntryException(org.openmrs.api.OrderEntryException) APIException(org.openmrs.api.APIException) EditedOrderDoesNotMatchPreviousException(org.openmrs.api.EditedOrderDoesNotMatchPreviousException) AmbiguousOrderException(org.openmrs.api.AmbiguousOrderException) CannotUnvoidOrderException(org.openmrs.api.CannotUnvoidOrderException) CannotStopInactiveOrderException(org.openmrs.api.CannotStopInactiveOrderException) UnchangeableObjectException(org.openmrs.api.UnchangeableObjectException)

Example 45 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class PatientServiceImpl method retirePatientIdentifierType.

/**
 * @see org.openmrs.api.PatientService#retirePatientIdentifierType(org.openmrs.PatientIdentifierType,
 *      String)
 */
@Override
public PatientIdentifierType retirePatientIdentifierType(PatientIdentifierType patientIdentifierType, String reason) throws APIException {
    checkIfPatientIdentifierTypesAreLocked();
    if (reason == null || reason.length() < 1) {
        throw new APIException("Patient.identifier.retire.reason", (Object[]) null);
    }
    patientIdentifierType.setRetired(true);
    patientIdentifierType.setRetiredBy(Context.getAuthenticatedUser());
    patientIdentifierType.setDateRetired(new Date());
    patientIdentifierType.setRetireReason(reason);
    return Context.getPatientService().savePatientIdentifierType(patientIdentifierType);
}
Also used : APIException(org.openmrs.api.APIException) Date(java.util.Date)

Aggregations

APIException (org.openmrs.api.APIException)84 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 File (java.io.File)9 Obs (org.openmrs.Obs)7 List (java.util.List)6 Map (java.util.Map)6 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 Concept (org.openmrs.Concept)5 OpenmrsObject (org.openmrs.OpenmrsObject)5 User (org.openmrs.User)5 InputStream (java.io.InputStream)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Order (org.openmrs.Order)4 FileNotFoundException (java.io.FileNotFoundException)3 OutputStreamWriter (java.io.OutputStreamWriter)3 MessageDigest (java.security.MessageDigest)3 HashMap (java.util.HashMap)3