|
15 | 15 | import org.openmrs.Role; |
16 | 16 | import org.openmrs.Visit; |
17 | 17 | import org.openmrs.api.context.Context; |
| 18 | +import org.openmrs.module.htmlformentry.BadFormDesignException; |
18 | 19 | import org.openmrs.module.htmlformentry.FormEntryContext; |
19 | 20 | import org.openmrs.module.htmlformentry.FormEntryContext.Mode; |
20 | 21 | import org.openmrs.module.htmlformentry.FormEntrySession; |
|
30 | 31 | import org.openmrs.module.htmlformentry.widget.ConceptSearchAutocompleteWidget; |
31 | 32 | import org.openmrs.module.htmlformentry.widget.DateTimeWidget; |
32 | 33 | import org.openmrs.module.htmlformentry.widget.DateWidget; |
| 34 | +import org.openmrs.module.htmlformentry.util.MatchMode; |
33 | 35 | import org.openmrs.module.htmlformentry.widget.DropdownWidget; |
34 | 36 | import org.openmrs.module.htmlformentry.widget.DynamicAutocompleteWidget; |
| 37 | +import org.openmrs.module.htmlformentry.widget.ProviderAjaxAutoCompleteWidget; |
35 | 38 | import org.openmrs.module.htmlformentry.widget.ErrorWidget; |
36 | 39 | import org.openmrs.module.htmlformentry.widget.NumberFieldWidget; |
37 | 40 | import org.openmrs.module.htmlformentry.widget.Option; |
@@ -163,7 +166,7 @@ public class ObsSubmissionElement<T extends FormEntryContext> implements HtmlGen |
163 | 166 |
|
164 | 167 | private String tagControlId; |
165 | 168 |
|
166 | | - public ObsSubmissionElement(T context, Map<String, String> parameters) { |
| 169 | + public ObsSubmissionElement(T context, Map<String, String> parameters) throws BadFormDesignException { |
167 | 170 | if (parameters.get("locale") != null) { |
168 | 171 | this.locale = LocaleUtility.fromSpecification(parameters.get("locale")); |
169 | 172 | } |
@@ -241,7 +244,7 @@ else if (conceptId == null && conceptIds == null) |
241 | 244 | isLocationObs = "location".equals(parameters.get("style")) || "location_radio".equals(parameters.get("style")) |
242 | 245 | || "location_dropdown".equals(parameters.get("style")); |
243 | 246 | isProviderObs = "provider".equals(parameters.get("style")) || "provider_radio".equals(parameters.get("style")) |
244 | | - || "provider_dropdown".equals(parameters.get("style")); |
| 247 | + || "provider_dropdown".equals(parameters.get("style")) || "provider_autocomplete".equals(parameters.get("style")); |
245 | 248 | isRadioSet = "radio".equals(parameters.get("style")) || "location_radio".equals(parameters.get("style")) |
246 | 249 | || "provider_radio".equals(parameters.get("style")); |
247 | 250 |
|
@@ -273,7 +276,7 @@ private Widget buildDropdownWidget(Integer size) { |
273 | 276 | return dropdownWidget; |
274 | 277 | } |
275 | 278 |
|
276 | | - private void prepareWidgets(T context, Map<String, String> parameters) { |
| 279 | + private void prepareWidgets(T context, Map<String, String> parameters) throws BadFormDesignException { |
277 | 280 | String userLocaleStr = locale.toString(); |
278 | 281 | try { |
279 | 282 | if (answerConcept == null) |
@@ -565,40 +568,55 @@ private void prepareWidgets(T context, Map<String, String> parameters) { |
565 | 568 | } |
566 | 569 | // configure the special obs type that allows selection of a provider (the provider_id PK is stored as the valueText) |
567 | 570 | else if (isProviderObs) { |
568 | | - if (isRadioSet) { |
569 | | - valueWidget = new RadioButtonsWidget(); |
570 | | - if (answerSeparator != null) { |
571 | | - ((RadioButtonsWidget) valueWidget).setAnswerSeparator(answerSeparator); |
572 | | - } |
573 | | - } else { // dropdown |
574 | | - valueWidget = new DropdownWidget(); |
575 | | - // if initialValueIsSet=false, no initial/default location, hence this shows the 'select input' field as first option |
576 | | - boolean initialValueIsSet = !(initialValue == null); |
577 | | - ((SingleOptionWidget) valueWidget).addOption( |
578 | | - new Option(Context.getMessageSourceService().getMessage("htmlformentry.chooseAProvider"), "", |
579 | | - !initialValueIsSet)); |
580 | | - } |
581 | 571 | List<String> roleIds = new ArrayList<>(); |
582 | 572 | String roleParam = parameters.get("providerRoles"); |
583 | 573 | if (StringUtils.isNotBlank(roleParam)) { |
584 | 574 | for (String roleId : roleParam.split(",")) { |
585 | 575 | roleIds.add(roleId.trim()); |
586 | 576 | } |
587 | 577 | } |
588 | | - List<Provider> providers = HtmlFormEntryUtil.getProviders(roleIds, true); |
589 | | - |
590 | | - List<Option> providerOptions = new ArrayList<>(); |
591 | | - for (Provider provider : providers) { |
592 | | - String providerId = provider.getId().toString(); |
593 | | - String label = HtmlFormEntryUtil.format(provider); |
594 | | - Option option = new Option(label, providerId, providerId.equals(initialValue)); |
595 | | - providerOptions.add(option); |
596 | | - } |
597 | | - Collections.sort(providerOptions, new OptionComparator()); |
598 | | - |
599 | | - if (!providerOptions.isEmpty()) { |
600 | | - for (Option option : providerOptions) { |
601 | | - ((SingleOptionWidget) valueWidget).addOption(option); |
| 578 | + if ("provider_autocomplete".equals(parameters.get("style"))) { |
| 579 | + MatchMode matchMode = MatchMode.ANYWHERE; |
| 580 | + if (StringUtils.isNotBlank(parameters.get("providerMatchMode"))) { |
| 581 | + try { |
| 582 | + matchMode = MatchMode.valueOf(parameters.get("providerMatchMode").toUpperCase()); |
| 583 | + } |
| 584 | + catch (Exception e) { |
| 585 | + throw new BadFormDesignException( |
| 586 | + "Invalid providerMatchMode '" + parameters.get("providerMatchMode") |
| 587 | + + "'. Valid values are: " + Arrays.toString(MatchMode.values()), e); |
| 588 | + } |
| 589 | + } |
| 590 | + valueWidget = new ProviderAjaxAutoCompleteWidget(matchMode, roleIds); |
| 591 | + } else { |
| 592 | + if (isRadioSet) { |
| 593 | + valueWidget = new RadioButtonsWidget(); |
| 594 | + if (answerSeparator != null) { |
| 595 | + ((RadioButtonsWidget) valueWidget).setAnswerSeparator(answerSeparator); |
| 596 | + } |
| 597 | + } else { // dropdown |
| 598 | + valueWidget = new DropdownWidget(); |
| 599 | + // if initialValueIsSet=false, no initial/default location, hence this shows the 'select input' field as first option |
| 600 | + boolean initialValueIsSet = !(initialValue == null); |
| 601 | + ((SingleOptionWidget) valueWidget).addOption( |
| 602 | + new Option(Context.getMessageSourceService().getMessage("htmlformentry.chooseAProvider"), "", |
| 603 | + !initialValueIsSet)); |
| 604 | + } |
| 605 | + List<Provider> providers = HtmlFormEntryUtil.getProviders(roleIds, true); |
| 606 | + |
| 607 | + List<Option> providerOptions = new ArrayList<>(); |
| 608 | + for (Provider provider : providers) { |
| 609 | + String providerId = provider.getId().toString(); |
| 610 | + String label = HtmlFormEntryUtil.format(provider); |
| 611 | + Option option = new Option(label, providerId, providerId.equals(initialValue)); |
| 612 | + providerOptions.add(option); |
| 613 | + } |
| 614 | + Collections.sort(providerOptions, new OptionComparator()); |
| 615 | + |
| 616 | + if (!providerOptions.isEmpty()) { |
| 617 | + for (Option option : providerOptions) { |
| 618 | + ((SingleOptionWidget) valueWidget).addOption(option); |
| 619 | + } |
602 | 620 | } |
603 | 621 | } |
604 | 622 | } else if ("person".equals(parameters.get("style"))) { |
|
0 commit comments