Skip to content

Commit daac730

Browse files
authored
HTML-861 - Support creation of all test order fields supported in Ope… (#316)
1 parent af754dd commit daac730

File tree

11 files changed

+102
-6
lines changed

11 files changed

+102
-6
lines changed

api-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openmrs.module</groupId>
66
<artifactId>htmlformentry</artifactId>
7-
<version>5.6.0-SNAPSHOT</version>
7+
<version>6.0.0-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>htmlformentry-api-tests</artifactId>

api-tests/src/test/java/org/openmrs/module/htmlformentry/widget/OrderWidgetTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,26 @@ public void shouldRenderTemplateWithAllWidgets() {
5555
fst.assertHtmlContains(propertyWidget.generateHtml(fst.getFormEntrySession().getContext()));
5656
}
5757
}
58+
59+
@Test
60+
public void shouldRenderTemplateWithWidgetsForTestOrder() {
61+
FormTester formTester = FormTester.buildForm("orderLabTestForm.xml");
62+
FormSessionTester fst = formTester.openNewForm(2);
63+
OrderWidget widget = fst.getWidgets(OrderWidget.class).get(0);
64+
String[] properties = { "concept", "action", "previousOrder", "careSetting", "orderReason", "orderReasonNonCoded",
65+
"instructions", "urgency", "dateActivated", "scheduledDate", "specimenSource", "laterality",
66+
"clinicalHistory", "frequency", "numberOfRepeats", "location", "discontinueReason",
67+
"discontinueReasonNonCoded" };
68+
69+
assertThat(widget.getWidgets().size(), is(properties.length));
70+
List<Widget> widgets = new ArrayList<>(widget.getWidgets().values());
71+
for (int i = 0; i < widgets.size(); i++) {
72+
String property = properties[i];
73+
Widget propertyWidget = widgets.get(i);
74+
fst.assertHtmlContains("<div class=\"order-field order-" + property + "\"");
75+
fst.assertHtmlContains("<div class=\"order-field-label order-" + property + "\"");
76+
fst.assertHtmlContains("<div class=\"order-field-widget order-" + property);
77+
fst.assertHtmlContains(propertyWidget.generateHtml(fst.getFormEntrySession().getContext()));
78+
}
79+
}
5880
}

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openmrs.module</groupId>
66
<artifactId>htmlformentry</artifactId>
7-
<version>5.6.0-SNAPSHOT</version>
7+
<version>6.0.0-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>htmlformentry-api</artifactId>

api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.openmrs.ProgramWorkflow;
4747
import org.openmrs.ProgramWorkflowState;
4848
import org.openmrs.Provider;
49+
import org.openmrs.ServiceOrder;
4950
import org.openmrs.User;
5051
import org.openmrs.api.APIException;
5152
import org.openmrs.api.ConceptNameType;
@@ -688,6 +689,18 @@ public static boolean isADrugOrderType(OrderType orderType) {
688689
}
689690
}
690691

692+
/**
693+
* @return true if a given Order Type represents a Service Order
694+
*/
695+
public static boolean isAServiceOrderType(OrderType orderType) {
696+
try {
697+
return ServiceOrder.class.isAssignableFrom(orderType.getJavaClass());
698+
}
699+
catch (Exception e) {
700+
return false;
701+
}
702+
}
703+
691704
/**
692705
* @return all of the Order Types in the system that represent Drug Orders
693706
*/

api/src/main/java/org/openmrs/module/htmlformentry/widget/OrderWidget.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.openmrs.Order;
2424
import org.openmrs.OrderFrequency;
2525
import org.openmrs.OrderType;
26+
import org.openmrs.ServiceOrder;
2627
import org.openmrs.api.context.Context;
2728
import org.openmrs.module.htmlformentry.CapturingPrintWriter;
2829
import org.openmrs.module.htmlformentry.FormEntryContext;
@@ -73,6 +74,13 @@ public OrderWidget(FormEntryContext context, OrderWidgetConfig widgetConfig) {
7374
configureNumericWidget(context, "quantity", true);
7475
configureOptionWidget(context, "quantityUnits", "dropdown");
7576
configureNumericWidget(context, "numRefills", false);
77+
} else if (isServiceOrder()) {
78+
configureOptionWidget(context, "specimenSource", "dropdown");
79+
configureOptionWidget(context, "laterality", "dropdown");
80+
configureTextWidget(context, "clinicalHistory");
81+
configureOptionWidget(context, "frequency", "dropdown");
82+
configureNumericWidget(context, "numberOfRepeats", false);
83+
configureOptionWidget(context, "location", "dropdown");
7684
}
7785
}
7886

@@ -199,6 +207,8 @@ public JsonObject constructJavascriptConfig(FormEntryContext context) {
199207
jho.addString("previousOrderId", pd == null ? "" : pd.getOrderId().toString());
200208
jho.addString("orderClass", o.getClass().getName());
201209
jho.addString("isDrugOrder", Boolean.toString(HtmlFormEntryUtil.isADrugOrderType(o.getOrderType())));
210+
jho.addString("isServiceOrder",
211+
Boolean.toString(HtmlFormEntryUtil.isAServiceOrderType(o.getOrderType())));
202212
addToJsonObject(jho, "action", o.getAction());
203213
JsonObject conceptObj = jho.addObject("concept");
204214
conceptObj.addString("value", c.getId().toString());
@@ -230,6 +240,14 @@ public JsonObject constructJavascriptConfig(FormEntryContext context) {
230240
addToJsonObject(jho, "quantity", d.getQuantity());
231241
addToJsonObject(jho, "quantityUnits", d.getQuantityUnits());
232242
addToJsonObject(jho, "numRefills", d.getNumRefills());
243+
} else if (o instanceof ServiceOrder) {
244+
ServiceOrder serviceOrder = (ServiceOrder) o;
245+
addToJsonObject(jho, "specimenSource", serviceOrder.getSpecimenSource());
246+
addToJsonObject(jho, "laterality", serviceOrder.getLaterality());
247+
addToJsonObject(jho, "clinicalHistory", serviceOrder.getClinicalHistory());
248+
addToJsonObject(jho, "frequency", serviceOrder.getFrequency());
249+
addToJsonObject(jho, "numberOfRepeats", serviceOrder.getNumberOfRepeats());
250+
addToJsonObject(jho, "location", serviceOrder.getLocation());
233251
}
234252

235253
if (o.getAction() == Order.Action.DISCONTINUE) {
@@ -502,6 +520,15 @@ public List<OrderWidgetValue> getValue(FormEntryContext c, HttpServletRequest r)
502520
newDrugOrder.setQuantityUnits(parseValue(getValue(c, r, fs, "quantityUnits"), Concept.class));
503521
}
504522
newDrugOrder.setNumRefills(parseValue(getValue(c, r, fs, "numRefills"), Integer.class));
523+
} else if (newOrder instanceof ServiceOrder) {
524+
ServiceOrder newServiceOrder = (ServiceOrder) newOrder;
525+
newServiceOrder.setSpecimenSource(parseValue(getValue(c, r, fs, "specimenSource"), Concept.class));
526+
newServiceOrder
527+
.setLaterality(parseValue(getValue(c, r, fs, "laterality"), ServiceOrder.Laterality.class));
528+
newServiceOrder.setClinicalHistory(parseValue(getValue(c, r, fs, "clinicalHistory"), String.class));
529+
newServiceOrder.setFrequency(parseValue(getValue(c, r, fs, "frequency"), OrderFrequency.class));
530+
newServiceOrder.setNumberOfRepeats(parseValue(getValue(c, r, fs, "numberOfRepeats"), Integer.class));
531+
newServiceOrder.setLocation(parseValue(getValue(c, r, fs, "location"), Concept.class));
505532
}
506533
v.setNewOrder(newOrder);
507534
ret.add(v);
@@ -686,6 +713,10 @@ protected boolean isDrugOrder() {
686713
return HtmlFormEntryUtil.isADrugOrderType(widgetConfig.getOrderField().getOrderType());
687714
}
688715

716+
protected boolean isServiceOrder() {
717+
return HtmlFormEntryUtil.isAServiceOrderType(widgetConfig.getOrderField().getOrderType());
718+
}
719+
689720
protected String translate(String code) {
690721
return Context.getMessageSourceService().getMessage(code);
691722
}

api/src/main/resources/messages.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ htmlformentry.orders.deleteOrder = Delete
137137
htmlformentry.orders.existingOrdersViewTitle = Revised Orders
138138
htmlformentry.orders.existingOrdersEditTitle = Active Orders
139139
htmlformentry.orders.newOrdersTitle = New Orders
140+
htmlformentry.orders.specimenSource = Specimen Source
141+
htmlformentry.orders.laterality = Laterality
142+
htmlformentry.orders.clinicalHistory = Clinical History
143+
htmlformentry.orders.numberOfRepeats = Number of Repeats
144+
htmlformentry.orders.location = Location
140145

141146
htmlformentry.orders.previousOrderRequired = You must specify an existing order in order to revise it
142147
htmlformentry.orders.drugChangedForRevision = No drug changes are permitted when issuing a revise order

api/src/test/resources/org/openmrs/module/htmlformentry/include/orderLabTestForm.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<orderProperty name="concept">
99
<option value="5497" label="CD4 Test"/>
1010
</orderProperty>
11+
<orderProperty name="specimenSource"/>
12+
<orderProperty name="laterality"/>
13+
<orderProperty name="clinicalHistory" textArea="true" textAreaRows="10" textAreaColumns="20"/>
14+
<orderProperty name="frequency"/>
15+
<orderProperty name="numberOfRepeats"/>
16+
<orderProperty name="location"/>
1117
</orderTemplate>
1218
</order>
1319

omod/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openmrs.module</groupId>
66
<artifactId>htmlformentry</artifactId>
7-
<version>5.6.0-SNAPSHOT</version>
7+
<version>6.0.0-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>htmlformentry-omod</artifactId>

omod/src/main/webapp/resources/orderWidget.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,13 @@
300300
$orderForm.find('.order-discontinueReasonNonCoded').show();
301301
} else if (action === 'RENEW') {
302302
orderWidget.enableOrderDurationWidgets($orderForm);
303+
orderWidget.enableServiceOrderWidgets($orderForm);
303304
} else if (action === 'REVISE' || action === 'NEW') {
304305
$orderForm.find('.order-orderReason').show();
305306
orderWidget.enableOrderDoseWidgets($orderForm);
306307
$orderForm.find('.order-urgency').show();
307308
orderWidget.enableOrderDurationWidgets($orderForm);
309+
orderWidget.enableServiceOrderWidgets($orderForm);
308310
}
309311

310312
// Set up ability to toggle between free-text and simple dosing instructions
@@ -517,6 +519,15 @@
517519
$orderForm.find('.order-numRefills').show();
518520
}
519521

522+
orderWidget.enableServiceOrderWidgets = function($orderForm) {
523+
$orderForm.find('.order-specimenSource').show();
524+
$orderForm.find('.order-laterality').show();
525+
$orderForm.find('.order-clinicalHistory').show();
526+
$orderForm.find('.order-frequency').show();
527+
$orderForm.find('.order-numberOfRepeats').show();
528+
$orderForm.find('.order-location').show();
529+
}
530+
520531
orderWidget.populateOrderForm = function(config, $orderForm, order) {
521532
$orderForm.find('.order-field-widget.order-previousOrder').find(':input').val(order.orderId);
522533
$orderForm.find('.order-field-widget.order-concept').find(':input').val(order.concept.value);
@@ -543,6 +554,14 @@
543554
$orderForm.find('.order-field-widget.order-quantityUnits').find(':input').val(order.quantityUnits.value);
544555
$orderForm.find('.order-field-widget.order-numRefills').find(':input').val(order.numRefills.value);
545556
}
557+
if (order.isServiceOrder === 'true') {
558+
$orderForm.find('.order-field-widget.order-specimenSource').find(':input').val(order.specimenSource.value);
559+
$orderForm.find('.order-field-widget.order-laterality').find(':input').val(order.laterality.value);
560+
$orderForm.find('.order-field-widget.order-clinicalHistory').find(':input').val(order.clinicalHistory.value);
561+
$orderForm.find('.order-field-widget.order-frequency').find(':input').val(order.frequency.value);
562+
$orderForm.find('.order-field-widget.order-numberOfRepeats').find(':input').val(order.numberOfRepeats.value);
563+
$orderForm.find('.order-field-widget.order-location').find(':input').val(order.location.value);
564+
}
546565
}
547566

548567
orderWidget.formatOrder = function(d, encDate, config) {

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.openmrs.module</groupId>
66
<artifactId>htmlformentry</artifactId>
7-
<version>5.6.0-SNAPSHOT</version>
7+
<version>6.0.0-SNAPSHOT</version>
88
<packaging>pom</packaging>
99
<name>HTML Form Entry</name>
1010
<description>Parent project for HTML Form Entry</description>
@@ -13,7 +13,7 @@
1313

1414
<!-- default property values, required for eclipse build path configuration -->
1515
<properties>
16-
<openMRSVersion>2.3.2</openMRSVersion>
16+
<openMRSVersion>2.5.0</openMRSVersion>
1717
<openMRSMinorVersion>2.3</openMRSMinorVersion>
1818
<legacyuiVersion>1.7.0</legacyuiVersion>
1919
<jacksonVersion>1.5.0</jacksonVersion>

0 commit comments

Comments
 (0)