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