Search in sources :

Example 1 with ErrorWidget

use of org.openmrs.module.htmlformentry.widget.ErrorWidget in project openmrs-module-pihcore by PIH.

the class CauseOfDeathListTagHandler method getSubstitution.

@Override
protected String getSubstitution(FormEntrySession session, FormSubmissionController controllerActions, Map<String, String> parameters) throws BadFormDesignException {
    Concept causeGroupConcept = HtmlFormEntryUtil.getConcept(CAUSES_OF_DEATH_CONCEPT);
    List<Obs> existingObs = session.getContext().removeExistingObs(causeGroupConcept);
    CodedOrFreeTextAnswerListWidget widget = new CodedOrFreeTextAnswerListWidget();
    widget.setUiUtils((UiUtils) session.getAttribute("uiUtils"));
    widget.setBetweenElementsCode("mirebalais.deathCertificate.due_to_or_following");
    widget.setTitleCode("mirebalais.deathCertificate.cause_of_death");
    widget.setPlaceholderCode("mirebalais.deathCertificate.cause_of_death_instructions");
    widget.setContainerClasses("required");
    if (parameters.get("locale") != null) {
        widget.setLocale(parameters.get("locale"));
    }
    if (existingObs != null && existingObs.size() > 0) {
        widget.setInitialValue(initialValue(existingObs));
    }
    session.getContext().registerWidget(widget);
    ErrorWidget errorWidget = new ErrorWidget();
    session.getContext().registerErrorWidget(widget, errorWidget);
    session.getSubmissionController().addAction(new Action(widget, errorWidget, existingObs));
    return widget.generateHtml(session.getContext());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) FormSubmissionControllerAction(org.openmrs.module.htmlformentry.action.FormSubmissionControllerAction) ErrorWidget(org.openmrs.module.htmlformentry.widget.ErrorWidget) CodedOrFreeTextAnswerListWidget(org.openmrs.module.coreapps.htmlformentry.CodedOrFreeTextAnswerListWidget)

Example 2 with ErrorWidget

use of org.openmrs.module.htmlformentry.widget.ErrorWidget in project openmrs-module-pihcore by PIH.

the class PastMedicalHistoryCheckboxTagHandler method getSubstitution.

@Override
protected String getSubstitution(FormEntrySession session, FormSubmissionController controller, Map<String, String> attributes) throws BadFormDesignException {
    Concept concept = HtmlFormEntryUtil.getConcept(attributes.get("concept"));
    if (concept == null) {
        throw new IllegalArgumentException("Concept not found: " + attributes.get("concept"));
    }
    boolean includeCommentField = parseBooleanAttribute(attributes.get("specify"), false);
    String label = attributes.get("label");
    // TODO translate label
    if (label == null) {
        label = concept.getName().getName();
    }
    FormEntryContext context = session.getContext();
    Obs existingObs = findExistingObs(context, HtmlFormEntryUtil.getConcept(PihCoreConstants.PAST_MEDICAL_HISTORY_CONSTRUCT), HtmlFormEntryUtil.getConcept(PihCoreConstants.PAST_MEDICAL_HISTORY_FINDING), concept);
    CheckboxWidget checkboxWidget = new CheckboxWidget(label, PRESENT);
    checkboxWidget.setInitialValue(existingObs);
    context.registerWidget(checkboxWidget);
    TextFieldWidget textFieldWidget = null;
    ErrorWidget errorWidget = new ErrorWidget();
    if (includeCommentField) {
        textFieldWidget = new TextFieldWidget();
        textFieldWidget.setPlaceholder(messageSourceService.getMessage("zl.pastMedicalHistory.specifyLabel"));
        if (existingObs != null) {
            Obs candidate = findMember(existingObs, HtmlFormEntryUtil.getConcept(PihCoreConstants.PAST_MEDICAL_HISTORY_FINDING_TEXT));
            if (candidate != null) {
                String comments = candidate.getValueText();
                if (StringUtils.isNotBlank(comments)) {
                    textFieldWidget.setInitialValue(comments);
                }
            }
        }
        context.registerWidget(textFieldWidget);
        context.registerErrorWidget(textFieldWidget, errorWidget);
    }
    String clazz = attributes.get("class");
    String elementId = attributes.get("id");
    StringBuilder html = new StringBuilder();
    html.append("<div ");
    if (StringUtils.isNotBlank(elementId)) {
        html.append("id=\"").append(elementId).append("\" ");
    }
    html.append("class=\"past-medical-history-item");
    if (StringUtils.isNotBlank(clazz)) {
        html.append(" ").append(clazz);
    }
    html.append("\">");
    html.append(checkboxWidget.generateHtml(context));
    if (includeCommentField) {
        html.append(textFieldWidget.generateHtml(context));
        html.append(errorWidget.generateHtml(context));
    }
    html.append("</div>");
    session.getSubmissionController().addAction(new Action(concept, checkboxWidget, textFieldWidget, existingObs));
    return html.toString();
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) FormSubmissionControllerAction(org.openmrs.module.htmlformentry.action.FormSubmissionControllerAction) FormEntryContext(org.openmrs.module.htmlformentry.FormEntryContext) CheckboxWidget(org.openmrs.module.htmlformentry.widget.CheckboxWidget) TextFieldWidget(org.openmrs.module.htmlformentry.widget.TextFieldWidget) ErrorWidget(org.openmrs.module.htmlformentry.widget.ErrorWidget)

Example 3 with ErrorWidget

use of org.openmrs.module.htmlformentry.widget.ErrorWidget 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)

Example 4 with ErrorWidget

use of org.openmrs.module.htmlformentry.widget.ErrorWidget in project openmrs-module-pihcore by PIH.

the class FamilyHistoryRelativeCheckboxesTagHandler method getSubstitution.

@Override
protected String getSubstitution(FormEntrySession session, FormSubmissionController controller, Map<String, String> attributes) throws BadFormDesignException {
    Concept concept = HtmlFormEntryUtil.getConcept(attributes.get("concept"));
    if (concept == null) {
        throw new IllegalArgumentException("Concept not found: " + attributes.get("concept"));
    }
    List<Concept> relatives = new ArrayList<Concept>();
    for (String id : attributes.get("relatives").split(",")) {
        Concept c = HtmlFormEntryUtil.getConcept(id);
        if (c == null) {
            throw new IllegalArgumentException("Relative type not found: " + id);
        }
        relatives.add(c);
    }
    if (relatives.isEmpty()) {
        throw new IllegalArgumentException(PihCoreConstants.HTMLFORMENTRY_FAMILY_HISTORY_RELATIVE_CHECKBOXES_TAG_NAME + " tag must have at least one relative specified");
    }
    boolean includeCommentField = parseBooleanAttribute(attributes.get("specify"), false);
    String label = attributes.get("label");
    // TODO translate label
    if (label == null) {
        label = concept.getName().getName();
    }
    Concept familyHistoryConstructConcept = HtmlFormEntryUtil.getConcept(PihCoreConstants.PATIENT_FAMILY_HISTORY_LIST_CONSTRUCT);
    Concept relationShipConcept = HtmlFormEntryUtil.getConcept(PihCoreConstants.RELATIONSHIP_OF_RELATIVE_TO_PATIENT);
    Concept diagnosisConcept = HtmlFormEntryUtil.getConcept(PihCoreConstants.FAMILY_HISTORY_DIAGNOSIS);
    Concept commentsConcept = HtmlFormEntryUtil.getConcept(PihCoreConstants.FAMILY_HISTORY_COMMENT);
    FormEntryContext context = session.getContext();
    TextFieldWidget textFieldWidget = null;
    ErrorWidget errorWidget = new ErrorWidget();
    // maps from wiget to existing obs for this widget
    Map<CheckboxWidget, Obs> relativeWidgets = new LinkedHashMap<CheckboxWidget, Obs>();
    for (Concept relative : relatives) {
        // group: family hx construct, member = which relative, member value = $relative
        // note: this assumes that all instances of this obs group have "is present = true"
        Obs existingObs = findObsGroupForDiagnosisAndRelativeInExistingObs(context, familyHistoryConstructConcept, diagnosisConcept, concept, relationShipConcept, relative);
        CheckboxWidget widget = new CheckboxWidget(relative.getName().getName(), relative.getUuid());
        widget.setInitialValue(existingObs);
        relativeWidgets.put(widget, existingObs);
        context.registerWidget(widget);
    }
    if (includeCommentField) {
        textFieldWidget = new TextFieldWidget();
        textFieldWidget.setPlaceholder(messageSourceService.getMessage("zl.pastMedicalHistory.specifyLabel"));
        Obs existingComments = findDiagnosisCommentInExistingDiagnosisObsGroups(relativeWidgets, commentsConcept);
        if (existingComments != null) {
            String valueText = existingComments.getValueText();
            if (StringUtils.isNotBlank(valueText)) {
                textFieldWidget.setInitialValue(valueText);
            }
        }
        context.registerWidget(textFieldWidget);
        context.registerErrorWidget(textFieldWidget, errorWidget);
    }
    String clazz = attributes.get("class");
    String elementId = attributes.get("id");
    StringBuilder html = new StringBuilder();
    html.append("<div ");
    if (StringUtils.isNotBlank(elementId)) {
        html.append("id=\"").append(elementId).append("\" ");
    }
    html.append("class=\"family-history-item");
    if (StringUtils.isNotBlank(clazz)) {
        html.append(" ").append(clazz);
    }
    html.append("\">");
    html.append("<div class=\"label\">");
    html.append(label);
    if (includeCommentField) {
        html.append(messageSourceService.getMessage("zl.familyHistoryRelativeCheckboxes.specifyLabel"));
        html.append(textFieldWidget.generateHtml(context));
        html.append(errorWidget.generateHtml(context));
    }
    html.append("</div>");
    for (Map.Entry<CheckboxWidget, Obs> entry : relativeWidgets.entrySet()) {
        html.append("<div class=\"relative\">");
        CheckboxWidget widget = entry.getKey();
        html.append(widget.generateHtml(context));
        html.append("</div>");
    }
    html.append("</div>");
    session.getSubmissionController().addAction(new Action(concept, relativeWidgets, textFieldWidget));
    return html.toString();
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) FormSubmissionControllerAction(org.openmrs.module.htmlformentry.action.FormSubmissionControllerAction) ArrayList(java.util.ArrayList) CheckboxWidget(org.openmrs.module.htmlformentry.widget.CheckboxWidget) ErrorWidget(org.openmrs.module.htmlformentry.widget.ErrorWidget) LinkedHashMap(java.util.LinkedHashMap) FormEntryContext(org.openmrs.module.htmlformentry.FormEntryContext) TextFieldWidget(org.openmrs.module.htmlformentry.widget.TextFieldWidget) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ErrorWidget (org.openmrs.module.htmlformentry.widget.ErrorWidget)4 Concept (org.openmrs.Concept)3 Obs (org.openmrs.Obs)3 FormSubmissionControllerAction (org.openmrs.module.htmlformentry.action.FormSubmissionControllerAction)3 FormEntryContext (org.openmrs.module.htmlformentry.FormEntryContext)2 CheckboxWidget (org.openmrs.module.htmlformentry.widget.CheckboxWidget)2 TextFieldWidget (org.openmrs.module.htmlformentry.widget.TextFieldWidget)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConceptSource (org.openmrs.ConceptSource)1 CodedOrFreeTextAnswerListWidget (org.openmrs.module.coreapps.htmlformentry.CodedOrFreeTextAnswerListWidget)1 Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)1 HiddenFieldWidget (org.openmrs.module.htmlformentry.widget.HiddenFieldWidget)1 PageAction (org.openmrs.ui.framework.page.PageAction)1