Skip to content

Commit

Permalink
HTML-835 Move basic form xml template out of application context xml …
Browse files Browse the repository at this point in the history
…file (#296)
  • Loading branch information
mseaton authored Sep 15, 2023
1 parent de3f07b commit 28fa7a8
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.openmrs.module.htmlformentry;

import java.util.Date;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -15,6 +13,8 @@
import org.openmrs.test.Verifies;
import org.openmrs.util.OpenmrsClassLoader;

import java.util.Date;

public class HtmlFormEntryServiceTest extends BaseHtmlFormEntryTest {

private HtmlFormEntryService service;
Expand Down Expand Up @@ -117,4 +117,10 @@ public void getConceptByMapping_shouldReturnNullIfInvalidMappingSpecified() thro
concept = service.getConceptByMapping("XYZ123:HT");
Assert.assertNull(concept);
}

@Test
public void getStartingFormXml_shouldGetBasicFormXmlTemplate() throws Exception {
String xmlTemplate = service.getStartingFormXml(new HtmlForm());
Assert.assertTrue(xmlTemplate.contains("2. Demographic Information"));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package org.openmrs.module.htmlformentry.impl;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.VelocityContext;
Expand Down Expand Up @@ -46,6 +37,17 @@
import org.openmrs.util.PrivilegeConstants;
import org.springframework.transaction.annotation.Transactional;

import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Standard implementation of the HtmlFormEntryService
*/
Expand Down Expand Up @@ -105,6 +107,14 @@ public void setDao(HtmlFormEntryDAO dao) {
* @return the basicFormXmlTemplate
*/
public String getBasicFormXmlTemplate() {
if (basicFormXmlTemplate == null) {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("basicFormXmlTemplate.xml")) {
basicFormXmlTemplate = IOUtils.toString(is, "UTF-8");
}
catch (Exception e) {
log.warn("Unable to load basic form template from classpath", e);
}
}
return basicFormXmlTemplate;
}

Expand Down
123 changes: 123 additions & 0 deletions api/src/main/resources/basicFormXmlTemplate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<htmlform>
<!-- Autogenerated example form (template from 01-Nov-2010 -->
#set( $DOLLAR = '$' )
#set( $POUND = '#' )
<macros>
paperFormId = (Fill this in)
headerColor =#009d8e
fontOnHeaderColor = white
</macros>

<style>
.section {
border: 1px solid ${DOLLAR}headerColor;
padding: 2px;
text-align: left;
margin-bottom: 1em;
}
.sectionHeader {
background-color: ${DOLLAR}headerColor;
color: ${DOLLAR}fontOnHeaderColor;
display: block;
padding: 2px;
font-weight: bold;
}
table.baseline-aligned td {
vertical-align: baseline;
}
</style>

<span style="float:right">Paper Form ID: ${DOLLAR}paperFormId</span>
<h2>$htmlForm.name (v$htmlForm.form.version)</h2>

<section headerLabel="1. Encounter Details">
<table class="baseline-aligned">
<tr>
<td>Date:</td>
<td><encounterDate default="today"/></td>
</tr>
<tr>
<td>Location:</td>
<td><encounterLocation/></td>
</tr>
<tr>
<td>Provider:</td>
<td><encounterProvider/></td>
</tr>
</table>
</section>

<section headerLabel="2. Demographic Information">
<table class="baseline-aligned">
<tr>
<td>Name:</td>
<td><lookup class="value" expression="patient.personName"/></td>
</tr>
#foreach ($idType in $identifierTypes)
<tr>
<td>$idType.name:</td>
<td><lookup class="value" complexExpression="${POUND}foreach( ${DOLLAR}patId in ${DOLLAR}patientIdentifiers.get('$idType.name') ) ${DOLLAR}patId ${POUND}end "/></td>
</tr>
#end
<tr>
<td>Gender:</td>
<td><lookup class="value" expression="patient.gender"/></td>
</tr>
<tr>
<td>Birthdate:</td>
<td>
<lookup class="value" complexExpression="\#if( \$patient.birthdateEstimated ) ~\#end"/> <lookup class="value" expression="patient.birthdate"/>
(Age: <lookup class="value" expression="patient.age"/>)
</td>
</tr>
#foreach ($attrType in $personAttributeTypes)
#set( $attrTypeName = $attrType.name.replaceAll("'", "") )
#set( $val = "personAttributes.get('$attrTypeName')" )
#if ( $attrType.format == "org.openmrs.Concept" )
#set( $val = "${val}.name.name" )
#end
<tr>
<td>$attrType.name:</td>
<td><lookup class="value" expression="$val"/></td>
</tr>
#end
</table>
</section>

<submit/>

<!-- END OF FORM
Simple examples to copy-and-paste. Full reference at http://wiki.openmrs.org/x/kg8z
SECTION
<section headerLabel="\#. Title">
Content
</section>
NUMERIC OBSERVATION
<obs conceptId="id-of-numeric-concept" labelText="Label before"/>
DATE OBSERVATION
<obs conceptId="id-of-date-concept" labelText="Label before"/>
CODED OBSERVATION
(as a dropdown)
<obs conceptId="id-of-coded-concept" labelText="Label before"/>
(as radio buttons)
<obs conceptId="id-of-coded-concept" labelText="Label before" style="radio"/>
(as an autocomplete)
<obs conceptId="id-of-coded-concept" labelText="Label before" style="autocomplete" answerClasses="Diagnosis"/>
(as a checkbox for a specific answer)
<obs conceptId="id-of-coded-concept" labelText="Label before" answerConceptId="id-of-answer-concept" answerLabel="label for answer"/>
(as a dropdown with specific choices)
<obs conceptId="id-of-coded-concept" labelText="Label before" answerConceptIds="concept-id-1,concept-id-2,concept-id-3" answerLabels="Label 1,Label 2, Label 3"/>
FREE TEXT OBSERVATION
(as a normal text field)
<obs conceptId="id-of-text-concept" labelText="Label before"/>
(as a textarea)
<obs conceptId="id-of-text-concept" labelText="Label before" rows="4" cols="80"/>
-->
</htmlform>
129 changes: 0 additions & 129 deletions api/src/main/resources/moduleApplicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,135 +115,6 @@
</entry>
</map>
</property>
<property name="basicFormXmlTemplate">
<value>
<![CDATA[
<htmlform>
<!-- Autogenerated example form (template from 01-Nov-2010 -->
#set( $DOLLAR = '$' )
#set( $POUND = '#' )
<macros>
paperFormId = (Fill this in)
headerColor =#009d8e
fontOnHeaderColor = white
</macros>
<style>
.section {
border: 1px solid ${DOLLAR}headerColor;
padding: 2px;
text-align: left;
margin-bottom: 1em;
}
.sectionHeader {
background-color: ${DOLLAR}headerColor;
color: ${DOLLAR}fontOnHeaderColor;
display: block;
padding: 2px;
font-weight: bold;
}
table.baseline-aligned td {
vertical-align: baseline;
}
</style>
<span style="float:right">Paper Form ID: ${DOLLAR}paperFormId</span>
<h2>$htmlForm.name (v$htmlForm.form.version)</h2>
<section headerLabel="1. Encounter Details">
<table class="baseline-aligned">
<tr>
<td>Date:</td>
<td><encounterDate default="today"/></td>
</tr>
<tr>
<td>Location:</td>
<td><encounterLocation/></td>
</tr>
<tr>
<td>Provider:</td>
<td><encounterProvider/></td>
</tr>
</table>
</section>
<section headerLabel="2. Demographic Information">
<table class="baseline-aligned">
<tr>
<td>Name:</td>
<td><lookup class="value" expression="patient.personName"/></td>
</tr>
#foreach ($idType in $identifierTypes)
<tr>
<td>$idType.name:</td>
<td><lookup class="value" complexExpression="${POUND}foreach( ${DOLLAR}patId in ${DOLLAR}patientIdentifiers.get('$idType.name') ) ${DOLLAR}patId ${POUND}end "/></td>
</tr>
#end
<tr>
<td>Gender:</td>
<td><lookup class="value" expression="patient.gender"/></td>
</tr>
<tr>
<td>Birthdate:</td>
<td>
<lookup class="value" complexExpression="\#if( \$patient.birthdateEstimated ) ~\#end"/> <lookup class="value" expression="patient.birthdate"/>
(Age: <lookup class="value" expression="patient.age"/>)
</td>
</tr>
#foreach ($attrType in $personAttributeTypes)
#set( $attrTypeName = $attrType.name.replaceAll("'", "") )
#set( $val = "personAttributes.get('$attrTypeName')" )
#if ( $attrType.format == "org.openmrs.Concept" )
#set( $val = "${val}.name.name" )
#end
<tr>
<td>$attrType.name:</td>
<td><lookup class="value" expression="$val"/></td>
</tr>
#end
</table>
</section>
<submit/>
<!-- END OF FORM
Simple examples to copy-and-paste. Full reference at http://wiki.openmrs.org/x/kg8z
SECTION
<section headerLabel="\#. Title">
Content
</section>
NUMERIC OBSERVATION
<obs conceptId="id-of-numeric-concept" labelText="Label before"/>
DATE OBSERVATION
<obs conceptId="id-of-date-concept" labelText="Label before"/>
CODED OBSERVATION
(as a dropdown)
<obs conceptId="id-of-coded-concept" labelText="Label before"/>
(as radio buttons)
<obs conceptId="id-of-coded-concept" labelText="Label before" style="radio"/>
(as an autocomplete)
<obs conceptId="id-of-coded-concept" labelText="Label before" style="autocomplete" answerClasses="Diagnosis"/>
(as a checkbox for a specific answer)
<obs conceptId="id-of-coded-concept" labelText="Label before" answerConceptId="id-of-answer-concept" answerLabel="label for answer"/>
(as a dropdown with specific choices)
<obs conceptId="id-of-coded-concept" labelText="Label before" answerConceptIds="concept-id-1,concept-id-2,concept-id-3" answerLabels="Label 1,Label 2, Label 3"/>
FREE TEXT OBSERVATION
(as a normal text field)
<obs conceptId="id-of-text-concept" labelText="Label before"/>
(as a textarea)
<obs conceptId="id-of-text-concept" labelText="Label before" rows="4" cols="80"/>
-->
</htmlform>
]]>
</value>
</property>
</bean>

<!-- Service -->
Expand Down

0 comments on commit 28fa7a8

Please sign in to comment.