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);
}
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));
}
}
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);
}
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);
}
}
}
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);
}
Aggregations