Package org.openmrs.module.htmlformentry.widget

Examples of org.openmrs.module.htmlformentry.widget.DropdownWidget


        Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" checked=\"true\"/><label for=\"w1\">This is a label</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context));
    }
   
    @Test
    public void dropdownWidgetShouldProduceHtml() {
        DropdownWidget dw = new DropdownWidget();
        context.registerWidget(dw);
        dw.addOption(new Option("Extra Large", "XL", false));
        dw.addOption(new Option("Large", "L", true));
        Assert.assertEquals("<select id=\"w1\" name=\"w1\"><option value=\"XL\">Extra Large</option><option value=\"L\" selected=\"true\">Large</option></select>", dw.generateHtml(context));
    }
View Full Code Here


        createNumRefillsWidget(context);
  }
 
  private void createDurationUnitsWidget(FormEntryContext context) {
    durationUnitsWidget = new DropdownWidget();
    List<Option> options = new ArrayList<Option>();
    List<Concept> durationUnits = Context.getOrderService().getDurationUnits();
    for (Concept concept : durationUnits) {
      options.add(new Option(concept.getName().getName(), concept.getId().toString(), false));
    }
View Full Code Here

    durationErrorWidget = new ErrorWidget();
    context.registerErrorWidget(durationWidget, durationErrorWidget);
  }
 
  private void createQuantityUnitsWidget(FormEntryContext context) {
    quantityUnitsWidget = new DropdownWidget();
   
    List<Option> options = new ArrayList<Option>();
    List<Concept> drugDispensingUnits = Context.getOrderService().getDrugDispensingUnits();
    for (Concept concept : drugDispensingUnits) {
      options.add(new Option(concept.getName().getName(), concept.getId().toString(), false));
View Full Code Here

    quantityErrorWidget = new ErrorWidget();
    context.registerErrorWidget(quantityWidget, quantityErrorWidget);
  }
 
  private void createDosingTypeWidget(FormEntryContext context) {
    dosingTypeWidget = new DropdownWidget();
   
    List<Option> options = new ArrayList<Option>();
        MessageSourceService mss = Context.getMessageSourceService();
        options.add(new Option(mss.getMessage("htmlformentry.drugOrder.dosingType.simple"), SimpleDosingInstructions.class.getName(), true));
        //options.add(new Option(mss.getMessage("htmlformentry.drugOrder.dosingType.freetext"), FreeTextDosingInstructions.class.getName(), false));
View Full Code Here

    }
    context.registerWidget(widget);
  }
 
  private void createDoseUnitsWidget(FormEntryContext context) {
    doseUnitsWidget = new DropdownWidget();
    List<Concept> concepts = Context.getOrderService().getDrugDosingUnits();
    List<Option> options = new ArrayList<Option>();
   
    for (Concept concept : concepts) {
      options.add(new Option(concept.getName().getName(), concept.getId().toString(), false));
View Full Code Here

   
    setupDropdownWidget(context, doseUnitsWidget, options);
  }
 
  public static DropdownWidget createCareSettingWidget(FormEntryContext context, boolean inpatientOnly) {
    DropdownWidget careSettingWidget = new DropdownWidget();
    List<CareSetting> careSettings = Context.getOrderService().getCareSettings(false);
    List<Option> options = new ArrayList<Option>();
    for (CareSetting careSetting : careSettings) {
      if (!inpatientOnly || careSetting.getCareSettingType().equals(CareSettingType.INPATIENT)) {
        options.add(new Option(careSetting.getName(), careSetting.getId().toString(), false));
View Full Code Here

   
    return careSettingWidget;
  }
 
  private void createRouteWidget(FormEntryContext context) {
    routeWidget = new DropdownWidget();
    List<Concept> drugRoutes = Context.getOrderService().getDrugRoutes();
   
    List<Option> options = new ArrayList<Option>();
    for (Concept route : drugRoutes) {
      options.add(new Option(route.getName().getName(), route.getId().toString(), false));
View Full Code Here

    //It's not used in 1.10
  }
 
  @Override
  protected void createFrequencyWidget(FormEntryContext context, MessageSourceService mss) {
    frequencyWidget = new DropdownWidget();
    frequencyErrorWidget = new ErrorWidget();
    // fill frequency drop down lists (ENTER, EDIT)
    List<OrderFrequency> orderFrequencies = Context.getOrderService().getOrderFrequencies(false);
   
    List<Option> freqOptions = new ArrayList<Option>();
View Full Code Here

        if (Boolean.TRUE.equals(parameters.get("provider"))) {

            if ("autocomplete".equals(parameters.get("type"))) {
                providerWidget = new AutocompleteWidget(Person.class);
            }else{
                providerWidget = new DropdownWidget();
            }
            providerErrorWidget = new ErrorWidget();

            List<Option> providerOptions = new ArrayList<Option>();
            // If specific persons are specified, display only those persons in order
            String personsParam = (String) parameters.get("persons");
            if (personsParam != null) {
                for (String s : personsParam.split(",")) {
                    Person p = HtmlFormEntryUtil.getPerson(s);
                    if (p == null) {
                        throw new RuntimeException("Cannot find Person: " + s);
                    }
                    String label = p.getPersonName().getFullName();
                    providerOptions.add(new Option(label, p.getId().toString(), false));
                }
                removeNonProviders(providerOptions);
            }

            // Only if specific person ids are not passed in do we get by user Role
            if (providerOptions.isEmpty()) {

                List<PersonStub> users = new ArrayList<PersonStub>();
                List<Option> providerUsers = new ArrayList<Option>();

                // If the "role" attribute is passed in, limit to users with this role
                if (parameters.get("role") != null) {
                    Role role = Context.getUserService().getRole((String) parameters.get("role"));
                    if (role == null) {
                        throw new RuntimeException("Cannot find role: " + parameters.get("role"));
                    } else {
                        users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole());
                    }
                }

                // Otherwise, use default options appropriate to the underlying OpenMRS version
                else {
                    if (openmrsVersionDoesNotSupportProviders()) {
                        // limit to users with the default OpenMRS PROVIDER role,
                        String defaultRole = OpenmrsConstants.PROVIDER_ROLE;
                        Role role = Context.getUserService().getRole(defaultRole);
                        if (role != null) {
                            users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole());
                        }
                        // If this role isn't used, default to all Users
                        if (users.isEmpty()) {
                            users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(null);
                        }
                    } else {
                        // in OpenMRS 1.9+, get all suitable providers
                        users = getAllProvidersThatArePersonsAsPersonStubs();
                    }
                }

                for (PersonStub personStub : users) {

                    Option option = new Option(personStub.toString(), personStub.getId().toString(), false);
                    providerUsers.add(option);
                }
                providerOptions.addAll(providerUsers);

            }

            // Set default values as appropriate
            Person defaultProvider = null;
            Option defProviderOption;
            if (context.getExistingEncounter() != null) {
                defaultProvider = context.getExistingEncounter().getProvider();
                // this is done to avoid default provider being added twice due to that it can be added from the
                // users = getAllProvidersThatArePersonsAsPersonStubs(); section with selected="false", therefore this can't be caught when
                // searching whether the options list contains the 'defaultProvider'
            boolean defaultOptionPresent = false;
              if(defaultProvider != null){
                for(Option option: providerOptions){
                  if(option.getValue().equals(defaultProvider.getId().toString())){
                      defaultOptionPresent = true;
                      providerOptions.remove(option);
                      break;
                  }
                }
              }
              if(defaultOptionPresent)  {
                  defProviderOption
                     = new Option(defaultProvider.getPersonName().getFullName(), defaultProvider.getId().toString(), true);
                   providerOptions.add(defProviderOption);
              }

            } else {
                String defParam = (String) parameters.get("default");
                if (StringUtils.hasText(defParam)) {
                    if ("currentuser".equalsIgnoreCase(defParam)) {
                        defaultProvider = Context.getAuthenticatedUser().getPerson();
                    } else {
                        defaultProvider = HtmlFormEntryUtil.getPerson(defParam);
                    }
                    if (defaultProvider == null) {
                        throw new IllegalArgumentException("Invalid default provider specified for encounter: " + defParam);
                    } else {
                        defProviderOption
                                = new Option(defaultProvider.getPersonName().getFullName(), defaultProvider.getId().toString(), true);
                        for (Option option : providerOptions) {
                            if (option.getValue().equals(defProviderOption.getValue())) {
                                providerOptions.remove(option);
                                break;
                            }
                        }
                        providerOptions.add(defProviderOption);
                    }

                }
            }
            if (defaultProvider != null) {
                providerWidget.setInitialValue(new PersonStub(defaultProvider));
            }
            Collections.sort(providerOptions,new OptionComparator());

            if (("autocomplete").equals(parameters.get("type"))) {
                providerWidget.addOption(new Option());
                if (!providerOptions.isEmpty()) {
                    providerWidget.setOptions(providerOptions);
                }

            } else {
                // if initialValueIsSet=false, no initial/default provider, hence this shows the 'select input' field as first option
                boolean initialValueIsSet = !(providerWidget.getInitialValue() == null);
                providerWidget.addOption(new Option
                        (Context.getMessageSourceService().getMessage("htmlformentry.chooseAProvider"), "", !initialValueIsSet)); // if no initial or default value

                if (!providerOptions.isEmpty()) {
                    for (Option option : providerOptions) {
                        providerWidget.addOption(option);
                    }

                }
            }
            context.registerWidget(providerWidget);
            context.registerErrorWidget(providerWidget, providerErrorWidget);
        }

        if (Boolean.TRUE.equals(parameters.get("encounterType"))) {
            encounterTypeWidget = new EncounterTypeWidget();
            encounterTypeErrorWidget = new ErrorWidget();
            if (parameters.get("types") != null) {
                List<EncounterType> encounterTypes = new ArrayList<EncounterType>();
                String[] temp = ((String) parameters.get("types")).split(",");
                for (String s : temp) {
                    EncounterType type = HtmlFormEntryUtil.getEncounterType(s);
                    if (type == null) {
                        throw new RuntimeException("Cannot find encounter type: " + s);
                    }
                    encounterTypes.add(type);
                }

               encounterTypeWidget.setOptions(encounterTypes);
            }
            // Set default values

            EncounterType defaultEncounterType = null;
            if (context.getExistingEncounter() != null) {
                defaultEncounterType = context.getExistingEncounter().getEncounterType();
            } else {
                String defaultTypeId = (String) parameters.get("default");
                if (StringUtils.hasText(defaultTypeId)) {
                    defaultEncounterType = HtmlFormEntryUtil.getEncounterType(defaultTypeId);
                }
            }

            encounterTypeWidget.setInitialValue(defaultEncounterType);
            context.registerWidget(encounterTypeWidget);
            context.registerErrorWidget(encounterTypeWidget, encounterTypeErrorWidget);
        }

        // Register Location widgets, if appropriate
        if (Boolean.TRUE.equals(parameters.get("location"))) {

                locationErrorWidget = new ErrorWidget();
            List<Location> locations = new ArrayList<Location>();
            List<Option> locationOptions = new ArrayList<Option>();

            if ("autocomplete".equals(parameters.get("type"))) {
                locationWidget = new AutocompleteWidget(Location.class);
            } else {
                locationWidget = new DropdownWidget();
            }

            if (parameters.get("tags") != null && parameters.get("orders") != null) {
                throw new RuntimeException("Using both \"order\" and \"tags\" attribute in an encounterLocation tag is not currently supported");
            }
View Full Code Here

TOP

Related Classes of org.openmrs.module.htmlformentry.widget.DropdownWidget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.