Search in sources :

Example 56 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class VisitDetailsFragmentController method getEncounterListAsJson.

protected List<SimpleObject> getEncounterListAsJson(ParseEncounterToJson parseEncounterToJson, VisitDomainWrapper visitWrapper, User authenticatedUser, int encounterIndex, int encounterCount) {
    List<Encounter> sortedEncounters = safeSubList(visitWrapper.getSortedEncounters(), encounterIndex, encounterCount + encounterIndex);
    List<SimpleObject> encounterJson = new ArrayList<SimpleObject>();
    for (Encounter encounter : sortedEncounters) {
        encounterJson.add(parseEncounterToJson.createEncounterJSON(authenticatedUser, encounter));
    }
    return encounterJson;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter)

Example 57 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class FindPatientFragmentController method simplify.

SimpleObject simplify(UiUtils ui, EmrApiProperties emrApiProperties, Patient patient) {
    PersonName name = patient.getPersonName();
    SimpleObject preferredName = SimpleObject.fromObject(name, ui, "givenName", "middleName", "familyName", "familyName2");
    preferredName.put("name", ui.format(name));
    PatientIdentifierType primaryIdentifierType = emrApiProperties.getPrimaryIdentifierType();
    List<PatientIdentifier> primaryIdentifiers = patient.getPatientIdentifiers(primaryIdentifierType);
    SimpleObject o = SimpleObject.fromObject(patient, ui, "patientId", "gender", "age", "birthdate", "birthdateEstimated");
    o.put("preferredName", preferredName);
    o.put("primaryIdentifiers", SimpleObject.fromCollection(primaryIdentifiers, ui, "identifier"));
    return o;
}
Also used : PersonName(org.openmrs.PersonName) SimpleObject(org.openmrs.ui.framework.SimpleObject) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier)

Example 58 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject 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 59 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class QuickVisitFragmentController method getConceptAnswers.

public SimpleObject getConceptAnswers(@RequestParam("conceptId") Concept concept) {
    SimpleObject results = new SimpleObject();
    List<SimpleObject> values = new LinkedList<SimpleObject>();
    for (ConceptAnswer conceptAnswer : concept.getAnswers()) {
        SimpleObject conceptAnswerMap = new SimpleObject();
        conceptAnswerMap.put("uuid", conceptAnswer.getUuid());
        conceptAnswerMap.put("name", conceptAnswer.getAnswerConcept().getName().getName());
        values.add(conceptAnswerMap);
    }
    results.put("results", values);
    return results;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ConceptAnswer(org.openmrs.ConceptAnswer) LinkedList(java.util.LinkedList)

Example 60 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject 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

SimpleObject (org.openmrs.ui.framework.SimpleObject)67 Test (org.junit.Test)37 Location (org.openmrs.Location)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)26 ArrayList (java.util.ArrayList)18 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)17 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)13 Config (org.openmrs.module.pihcore.config.Config)12 DateTime (org.joda.time.DateTime)11 Date (java.util.Date)9 Encounter (org.openmrs.Encounter)9 Concept (org.openmrs.Concept)6 Patient (org.openmrs.Patient)6 Obs (org.openmrs.Obs)5 Visit (org.openmrs.Visit)5 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)3 ConceptSearchResult (org.openmrs.ConceptSearchResult)3 Form (org.openmrs.Form)3