Search in sources :

Example 1 with PageAction

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

the class CodedOrFreeTextAnswerWidget method generateHtml.

@Override
public String generateHtml(FormEntryContext context) {
    Translator translator = context.getTranslator();
    String localeStr = locale.toString();
    String title = translator.translate(localeStr, titleCode);
    String placeholder = translator.translate(localeStr, placeholderCode);
    StringBuilder ret = new StringBuilder();
    if (context.getMode().equals(FormEntryContext.Mode.VIEW)) {
        if (initialValue != null) {
            ret.append("<span class=\"value\">" + initialValue.format(locale) + "</span>");
        }
    } else {
        String hiddenInputName = context.getFieldName(this);
        Map<String, Object> fragmentConfig = new HashMap<String, Object>();
        fragmentConfig.put("formFieldName", hiddenInputName);
        fragmentConfig.put("title", title);
        fragmentConfig.put("placeholder", placeholder);
        fragmentConfig.put("containerClasses", containerClasses);
        fragmentConfig.put("initialValue", initialValueAsJson(initialValue));
        try {
            ret.append(uiUtils.includeFragment("coreapps", "htmlformentry/codedOrFreeTextAnswer", fragmentConfig));
        } catch (PageAction pageAction) {
            throw new IllegalStateException("fragment threw PageAction", pageAction);
        } catch (NullPointerException ex) {
            // (This is hacky, but I don't see a better way to do it.)
            return "<input type=\"hidden\" name=\"" + context.getFieldName(this) + "\"/> (Submitting the form, so we don't generate HTML)";
        }
    }
    return ret.toString();
}
Also used : PageAction(org.openmrs.ui.framework.page.PageAction) Translator(org.openmrs.module.htmlformentry.Translator) HashMap(java.util.HashMap) SimpleObject(org.openmrs.ui.framework.SimpleObject)

Example 2 with PageAction

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

the class CodedOrFreeTextAnswerListWidget method generateHtml.

@Override
public String generateHtml(FormEntryContext context) {
    Translator translator = context.getTranslator();
    String localeStr = locale.toString();
    String title = translator.translate(localeStr, titleCode);
    String betweenElements = translator.translate(localeStr, betweenElementsCode);
    String placeholder = translator.translate(localeStr, placeholderCode);
    StringBuilder ret = new StringBuilder();
    ret.append("<div class=\"coded-or-free-text-list-widget\">");
    if (context.getMode().equals(FormEntryContext.Mode.VIEW)) {
        ret.append("<span class=\"coded-or-free-text-title\">" + title + "</span>\n");
        if (initialValue != null) {
            boolean first = true;
            for (CodedOrFreeTextAnswer answer : initialValue) {
                if (!first && StringUtils.isNotEmpty(betweenElements)) {
                    ret.append("<br/>");
                    ret.append("<span class=\"coded-or-free-text-between\">").append(betweenElements).append("</span>");
                }
                ret.append("<br/>");
                ret.append("<span class=\"value\">").append(answer.format(locale)).append("</span>");
                first = false;
            }
        }
    } else {
        String hiddenInputName = context.getFieldName(this);
        Map<String, Object> fragmentConfig = new HashMap<String, Object>();
        fragmentConfig.put("formFieldName", hiddenInputName);
        fragmentConfig.put("title", title);
        fragmentConfig.put("placeholder", placeholder);
        fragmentConfig.put("betweenElements", betweenElements);
        fragmentConfig.put("containerClasses", containerClasses);
        fragmentConfig.put("initialValue", initialValueAsJson(initialValue));
        try {
            ret.append(uiUtils.includeFragment("coreapps", "htmlformentry/codedOrFreeTextAnswerList", fragmentConfig));
        } catch (PageAction pageAction) {
            throw new IllegalStateException("fragment threw PageAction", pageAction);
        } catch (NullPointerException ex) {
            // (This is hacky, but I don't see a better way to do it.)
            return "<input type=\"hidden\" name=\"" + context.getFieldName(this) + "\"/> (Submitting the form, so we don't generate HTML)";
        }
    }
    ret.append("</div>");
    return ret.toString();
}
Also used : PageAction(org.openmrs.ui.framework.page.PageAction) Translator(org.openmrs.module.htmlformentry.Translator) HashMap(java.util.HashMap) SimpleObject(org.openmrs.ui.framework.SimpleObject) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)

Example 3 with PageAction

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

the class EncounterDiagnosesElement method generateHtml.

@Override
public String generateHtml(FormEntryContext context) {
    List<Diagnosis> existingDiagnoses = getExistingDiagnoses(context, emrApiProperties.getDiagnosisMetadata());
    if (FormEntryContext.Mode.VIEW == context.getMode()) {
        StringBuilder sb = new StringBuilder();
        if (existingDiagnoses != null) {
            List<ConceptSource> conceptSourcesForDiagnosisSearch = emrApiProperties.getConceptSourcesForDiagnosisSearch();
            for (Diagnosis diagnosis : existingDiagnoses) {
                sb.append("<p><small>");
                // question (e.g. "Primary diagnosis")
                sb.append(message("coreapps.patientDashBoard.diagnosisQuestion." + diagnosis.getOrder()));
                sb.append("</small><span>");
                // answer (e.g. "(Confirmed) Malaria [code]")
                sb.append("(" + message("coreapps.Diagnosis.Certainty." + diagnosis.getCertainty()) + ") ");
                sb.append(diagnosis.getDiagnosis().formatWithCode(getLocale(), conceptSourcesForDiagnosisSearch));
                sb.append("</span></p>");
            }
        }
        return sb.toString();
    } else {
        hiddenDiagnoses = new HiddenFieldWidget();
        errorWidget = new ErrorWidget();
        context.registerWidget(hiddenDiagnoses);
        context.registerErrorWidget(hiddenDiagnoses, errorWidget);
        try {
            Map<String, Object> fragmentConfig = new HashMap<String, Object>();
            fragmentConfig.put("formFieldName", "encounterDiagnoses");
            fragmentConfig.put("existingDiagnoses", existingDiagnoses);
            // add the prior diagnoses if requested
            if (FormEntryContext.Mode.ENTER == context.getMode() && dispositionTypeForPriorDiagnoses != null) {
                fragmentConfig.put("priorDiagnoses", getPriorDiagnoses(context, dispositionTypeForPriorDiagnoses));
            }
            try {
                StringBuilder output = new StringBuilder();
                output.append(errorWidget.generateHtml(context));
                output.append(uiUtils.includeFragment("coreapps", "diagnosis/encounterDiagnoses", fragmentConfig));
                if (selectedDiagnosesTarget != null) {
                    output.append("\n <script type=\"text/javascript\"> \n $(function() { $('#display-encounter-diagnoses-container').appendTo('" + selectedDiagnosesTarget + "'); }); \n </script>");
                }
                return output.toString();
            } catch (NullPointerException ex) {
                // (This is hacky, but I don't see a better way to do it.)
                return "Submitting the form, so we don't generate HTML";
            }
        } catch (PageAction pageAction) {
            throw new IllegalStateException("Included fragment threw a PageAction", pageAction);
        }
    }
}
Also used : PageAction(org.openmrs.ui.framework.page.PageAction) HashMap(java.util.HashMap) ConceptSource(org.openmrs.ConceptSource) ErrorWidget(org.openmrs.module.htmlformentry.widget.ErrorWidget) HiddenFieldWidget(org.openmrs.module.htmlformentry.widget.HiddenFieldWidget) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis)

Aggregations

HashMap (java.util.HashMap)3 PageAction (org.openmrs.ui.framework.page.PageAction)3 Translator (org.openmrs.module.htmlformentry.Translator)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ConceptSource (org.openmrs.ConceptSource)1 CodedOrFreeTextAnswer (org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)1 Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)1 ErrorWidget (org.openmrs.module.htmlformentry.widget.ErrorWidget)1 HiddenFieldWidget (org.openmrs.module.htmlformentry.widget.HiddenFieldWidget)1