Search in sources :

Example 1 with FailureResult

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"));
}
Also used : Obs(org.openmrs.Obs) FailureResult(org.openmrs.ui.framework.fragment.action.FailureResult) ArrayList(java.util.ArrayList) SuccessResult(org.openmrs.ui.framework.fragment.action.SuccessResult) JsonNode(org.codehaus.jackson.JsonNode) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with FailureResult

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"));
}
Also used : User(org.openmrs.User) FailureResult(org.openmrs.ui.framework.fragment.action.FailureResult) SuccessResult(org.openmrs.ui.framework.fragment.action.SuccessResult)

Example 3 with FailureResult

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()));
    }
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) FailureResult(org.openmrs.ui.framework.fragment.action.FailureResult) ExistingVisitDuringTimePeriodException(org.openmrs.module.emrapi.adt.exception.ExistingVisitDuringTimePeriodException) ArrayList(java.util.ArrayList) List(java.util.List) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) DateTime(org.joda.time.DateTime) Date(java.util.Date) ExistingVisitDuringTimePeriodException(org.openmrs.module.emrapi.adt.exception.ExistingVisitDuringTimePeriodException)

Example 4 with FailureResult

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"));
}
Also used : User(org.openmrs.User) FailureResult(org.openmrs.ui.framework.fragment.action.FailureResult) SuccessResult(org.openmrs.ui.framework.fragment.action.SuccessResult)

Example 5 with FailureResult

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

FailureResult (org.openmrs.ui.framework.fragment.action.FailureResult)6 SuccessResult (org.openmrs.ui.framework.fragment.action.SuccessResult)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 User (org.openmrs.User)2 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 List (java.util.List)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 DateTime (org.joda.time.DateTime)1 Obs (org.openmrs.Obs)1 Visit (org.openmrs.Visit)1 VisitAttributeType (org.openmrs.VisitAttributeType)1 APIException (org.openmrs.api.APIException)1 AccountDomainWrapper (org.openmrs.module.emrapi.account.AccountDomainWrapper)1 ExistingVisitDuringTimePeriodException (org.openmrs.module.emrapi.adt.exception.ExistingVisitDuringTimePeriodException)1 Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)1 ObjectResult (org.openmrs.ui.framework.fragment.action.ObjectResult)1 Transactional (org.springframework.transaction.annotation.Transactional)1