use of org.openmrs.ui.framework.fragment.action.FailureResult in project openmrs-module-coreapps by openmrs.
the class DiagnosesFragmentController method codeDiagnosis.
public FragmentActionResult codeDiagnosis(UiUtils ui, @RequestParam("nonCodedObsId") Integer nonCodedObsId, // each string is json, like {"certainty":"PRESUMED","diagnosisOrder":"PRIMARY","diagnosis":"ConceptName:840"}
@RequestParam("diagnosis") List<String> diagnoses, @SpringBean("obsService") ObsService obsService, @SpringBean("emrDiagnosisService") DiagnosisService diagnosisService, @SpringBean("conceptService") ConceptService conceptService) throws Exception {
if (nonCodedObsId != null) {
Obs nonCodedObs = obsService.getObs(nonCodedObsId);
if (nonCodedObs != null) {
List<Diagnosis> diagnosisList = new ArrayList<Diagnosis>();
for (String diagnosisJson : diagnoses) {
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(diagnosisJson);
Iterator<JsonNode> iterator = rootNode.iterator();
while (iterator.hasNext()) {
JsonNode next = iterator.next();
Diagnosis diagnosis = parseDiagnosisJson(next.toString(), conceptService);
diagnosisList.add(diagnosis);
}
}
List<Obs> newDiagnoses = diagnosisService.codeNonCodedDiagnosis(nonCodedObs, diagnosisList);
if ((newDiagnoses != null) && (newDiagnoses.size() > 0)) {
return new SuccessResult(ui.message("coreapps.dataManagement.codeDiagnosis.success"));
}
}
}
return new FailureResult(ui.message("coreapps.dataManagement.codeDiagnosis.failure"));
}
use of org.openmrs.ui.framework.fragment.action.FailureResult in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentController method deleteEncounter.
public FragmentActionResult deleteEncounter(UiUtils ui, @RequestParam("encounterId") Encounter encounter, @SpringBean("encounterService") EncounterService encounterService, UiSessionContext sessionContext) {
if (encounter != null) {
User authenticatedUser = sessionContext.getCurrentUser();
boolean canDelete = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_ENCOUNTER);
if (verifyIfUserHasPermissionToDeleteAnEncounter(encounter, authenticatedUser, canDelete)) {
encounterService.voidEncounter(encounter, "delete encounter");
encounterService.saveEncounter(encounter);
} else {
return new FailureResult(ui.message("coreapps.patientDashBoard.deleteEncounter.notAllowed"));
}
}
return new SuccessResult(ui.message("coreapps.patientDashBoard.deleteEncounter.successMessage"));
}
use of org.openmrs.ui.framework.fragment.action.FailureResult in project openmrs-module-coreapps by openmrs.
the class RetrospectiveVisitFragmentController method create.
public Object create(@SpringBean("adtService") AdtService adtService, @RequestParam("patientId") Patient patient, @RequestParam("locationId") Location location, @RequestParam("startDate") Date startDate, @RequestParam(value = "stopDate", required = false) Date stopDate, HttpServletRequest request, UiUtils ui) {
// if no stop date, set it to start date
if (stopDate == null) {
stopDate = startDate;
}
// set the startDate time component to the start of day
startDate = new DateTime(startDate).withTime(0, 0, 0, 0).toDate();
// if stopDate is today, set stopDate to current datetime, otherwise set time component to end of date
if (new DateTime().withTime(0, 0, 0, 0).equals(new DateTime(stopDate).withTime(0, 0, 0, 0))) {
stopDate = new Date();
} else {
stopDate = new DateTime(stopDate).withTime(23, 59, 59, 999).toDate();
}
try {
VisitDomainWrapper createdVisit = adtService.createRetrospectiveVisit(patient, location, startDate, stopDate);
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("coreapps.retrospectiveVisit.addedVisitMessage"));
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
return SimpleObject.create("success", true, "id", createdVisit.getVisit().getId().toString(), "uuid", createdVisit.getVisit().getUuid());
} catch (ExistingVisitDuringTimePeriodException e) {
// if there are existing visit(s), return these existing visits
List<SimpleObject> simpleVisits = new ArrayList<SimpleObject>();
List<VisitDomainWrapper> visits = adtService.getVisits(patient, location, startDate, stopDate);
if (visits != null) {
for (VisitDomainWrapper visit : visits) {
simpleVisits.add(SimpleObject.create("startDate", ui.format(new DateTime(visit.getVisit().getStartDatetime()).toDateMidnight().toDate()), "stopDate", ui.format(new DateTime(visit.getVisit().getStopDatetime()).toDateMidnight().toDate()), "id", visit.getVisit().getId(), "uuid", visit.getVisit().getUuid()));
}
}
return simpleVisits;
} catch (Exception e) {
log.error("Unable to add retrospective visit", e);
return new FailureResult(ui.message(e.getMessage()));
}
}
use of org.openmrs.ui.framework.fragment.action.FailureResult in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentController method deleteVisit.
public FragmentActionResult deleteVisit(UiUtils ui, @RequestParam("visitId") Visit visit, @SpringBean("visitService") VisitService visitService, UiSessionContext sessionContext) {
if (visit != null) {
User authenticatedUser = sessionContext.getCurrentUser();
boolean canDeleteVisit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_VISIT);
if (verifyIfUserHasPermissionToDeleteVisit(visit, authenticatedUser, canDeleteVisit)) {
visitService.voidVisit(visit, "delete visit");
visitService.saveVisit(visit);
} else {
return new FailureResult(ui.message("emr.patientDashBoard.deleteVisit.notAllowed"));
}
}
return new SuccessResult(ui.message("coreapps.task.deleteVisit.successMessage"));
}
use of org.openmrs.ui.framework.fragment.action.FailureResult 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);
}
Aggregations