/** * Creates a new person stub. * * @param given * @param middle * @param family * @param birthdate * @param dateformat * @param age * @param gender * @return PersonListItem person stub created */ public Object createPerson( String given, String middle, String family, String birthdate, String dateformat, String age, String gender) { log.error( given + " " + middle + " " + family + " " + birthdate + " " + dateformat + " " + age + " " + gender); User user = Context.getAuthenticatedUser(); Person p = new Person(); p.setPersonCreator(user); p.setPersonDateCreated(new Date()); p.setPersonChangedBy(user); p.setPersonDateChanged(new Date()); if (StringUtils.isEmpty(gender)) { log.error("Gender cannot be null."); return String.valueOf("Gender cannot be null."); } else if (gender.toUpperCase().contains("M")) { p.setGender("M"); } else if (gender.toUpperCase().contains("F")) { p.setGender("F"); } else { log.error("Gender must be 'M' or 'F'."); return new String("Gender must be 'M' or 'F'."); } if ("".equals(given) || "".equals(family)) { log.error("Given name and family name cannot be null."); return new String("Given name and family name cannot be null."); } PersonName name = new PersonName(given, middle, family); name.setCreator(user); name.setDateCreated(new Date()); name.setChangedBy(user); name.setDateChanged(new Date()); p.addName(name); try { Date d = updateAge(birthdate, dateformat, age); p.setBirthdate(d); } catch (java.text.ParseException pe) { log.error(pe); return new String("Birthdate cannot be parsed."); } p.setGender(gender); Person person = Context.getPersonService().savePerson(p); return PersonListItem.createBestMatch(person); }
private void setParentId(Patient patient, Relationship motherRelationship) { Person mother = motherRelationship.getPersonA(); if (mother != null && !mother.getNames().isEmpty()) { List<Patient> patients = allPatients.search(mother.getNames().iterator().next().getFullName(), null); if (patients != null && !patients.isEmpty()) { patient.parentId(getParentId(mother, patients)); } } }
private static String getPatientIdentifier(Person person) throws Exception { try { Patient patient = Context.getPatientService().getPatient(person.getPersonId()); if (getPersonId(patient) == person.getPersonId()) { return patient.getPatientIdentifier().getIdentifier(); } } catch (Exception ex) { log.error(ex.getMessage(), ex); } return ""; }
private void updateRelationship(String parentId, Patient savedPatient, Relationship relationship) throws ParentNotFoundException { Patient updatedMother = getPatientByMotechId(parentId); if (updatedMother == null) { throw new ParentNotFoundException(); } Person personA = relationship.getPersonA(); if (personA != null && !personA.getId().toString().equals(updatedMother.getMrsPatient().getPerson().getId())) { allPatients.updateMotherChildRelationship( updatedMother.getMrsPatient().getPerson(), savedPatient.getMrsPatient().getPerson()); } }
/** * This method exists to allow us to quickly support providers as introduce in OpenMRS 1.9.x, * without having to branch the module. We should remove this method when do a proper * implementation. * * @return personIds of all providers that are attached to persons */ private Set<Integer> getAllProviderPersonIds() { try { Set<Integer> ret = new HashSet<Integer>(); for (Object candidate : getAllProvidersThatArePersons()) { Person person = (Person) PropertyUtils.getProperty(candidate, "person"); if (person != null) ret.add(person.getPersonId()); } return ret; } catch (Exception ex) { throw new RuntimeException( "Programming error in HTML Form Entry module. This method should be safe!", ex); } }
public static String getFullPersonAddress(Person p) { String address = "-/-/-/-/-/-"; try { // Country/Province/District/Sector/Cell/Umudugudu PersonAddress pa = null; if (p != null) pa = p.getPersonAddress(); if (pa != null) { address = ((pa.getCountry() != null) ? pa.getCountry() : "-") + " / " + ((pa.getStateProvince() != null) ? pa.getStateProvince() : "-") + " / " + ((pa.getCountyDistrict() != null) ? pa.getCountyDistrict() : "-") + " / " + ((pa.getCityVillage() != null) ? pa.getCityVillage() : "-") + " / " + ((pa.getNeighborhoodCell() != null) ? pa.getNeighborhoodCell() : "-") + " / " + ((pa.getAddress1() != null) ? pa.getAddress1() : "-"); } else return address; return address; } catch (Exception e) { log.error(">>>>>>>>>>>>>>>>>>>VCT>>Module>>Tag>>>> An error occured : " + e.getMessage()); e.printStackTrace(); return address; } }
private String getParentId(Person mother, List<Patient> patients) { for (Patient patient : patients) { if (patient.getMrsPatient().getPerson().getId().equals(mother.getId().toString())) { return patient.getMrsPatient().getMotechId(); } } return null; }
/** * Auto generated method comment * * @param personId * @return */ public static String getPersonNames(Integer personId) { try { if (personId == null) return ""; Person person = Context.getPersonService().getPerson(personId); String names = ""; if (null != person) { names = (person.getGivenName().trim() + " " + person.getMiddleName()).trim() + " " + person.getFamilyName().trim(); } return names; } catch (Exception e) { log.info(e.getMessage()); return ""; } }
public static Integer getProviderId(String userName) { User userProvider; Person personProvider; // assume its a normal user-name or systemId formatted with a dash userProvider = Context.getUserService().getUserByUsername(userName); if (userProvider != null) { return userProvider.getPerson().getPersonId(); } // next assume it is a internal providerId (Note this is a person_id // not a user_id) and try again try { personProvider = Context.getPersonService().getPerson(Integer.parseInt(userName)); if (personProvider != null) { return personProvider.getPersonId(); } } catch (NumberFormatException e) { e.printStackTrace(); } // now assume its a systemId without a dash: fix the dash and try again if (userName != null && userName.trim() != "") { if (userName.indexOf("-") == -1 && userName.length() > 1) { userName = userName.substring(0, userName.length() - 1) + "-" + userName.substring(userName.length() - 1); userProvider = Context.getUserService().getUserByUsername(userName); if (userProvider != null) { return userProvider.getPerson().getPersonId(); } } } return null; }
/** * Auto generated method comment * * @param p * @param attributeTypeId * @return */ public static String personAttribute(Person p, Integer attributeTypeId) { try { PersonAttribute pa = null; if (p != null) pa = p.getAttribute(attributeTypeId); if (pa != null) { return Context.getConceptService() .getConcept(Integer.parseInt(pa.getValue())) .getName() .getName(); } else return "-"; } catch (Exception e) { log.error(">>>>>>>>>>>>>>>>>>>VCT>>Module>>Tag>>>> An error occured : " + e.getMessage()); e.printStackTrace(); return "-"; } }
/** * Auto generated method comment * * @param p * @param addressTypeId * @return */ public static String personAddress(Person p, Integer addressTypeId) { try { PersonAddress pa = null; if (p != null) pa = p.getPersonAddress(); if (pa != null) { switch (addressTypeId) { case 1: return (pa.getAddress1().compareToIgnoreCase("") == 0) ? "-" : pa.getAddress1(); case 2: return (pa.getAddress2().compareToIgnoreCase("") == 0) ? "-" : pa.getAddress2(); case 3: return (pa.getCityVillage().compareToIgnoreCase("") == 0) ? "-" : pa.getCityVillage(); default: return "-"; } } else return "-"; } catch (Exception e) { log.error(">>>>>>>>>>>>>>>>>>>VCT>>Module>>Tag>>>> An error occured : " + e.getMessage()); e.printStackTrace(); return "-"; } }
/** * Checks the form object for any inconsistencies/errors * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if retired and retireReason is null or empty or whitespace * @should pass validation if all required fields have proper values */ public void validate(Object obj, Errors errors) { User user = (User) obj; if (user == null) { errors.rejectValue("user", "error.general"); } else { if (user.isRetired() && !StringUtils.hasText(user.getRetireReason())) errors.rejectValue("retireReason", "error.null"); if (user.getPerson() == null) { errors.rejectValue("person", "error.null"); } else { // check that required person details are filled out Person person = user.getPerson(); if (person.getGender() == null) errors.rejectValue("person.gender", "error.null"); if (person.getDead() == null) errors.rejectValue("person.dead", "error.null"); if (person.getVoided() == null) errors.rejectValue("person.voided", "error.null"); if (person.getPersonName() == null || !StringUtils.hasText(person.getPersonName().toString())) errors.rejectValue("person", "Person.names.length"); } } if (!isUserNameValid(user.getUsername())) errors.rejectValue("username", "error.username.pattern"); }
/** Gets the value of an attribute on a person. */ public static String getPersonAttributeValue(Person person, PersonAttributeType attrType) { PersonAttribute attribute = person.getAttribute(attrType); return attribute != null ? attribute.getValue() : null; }
@Test public void shouldEvaluateOBRORUR01TemplateForOBSGroup() throws Exception { // given Encounter encounter = new Encounter(); Date date = new Date(); encounter.setEncounterDatetime(date); encounter.setUuid("ENCOUNTER UUID"); EncounterType encounterType = new EncounterType(); encounterType.setName("ENCOUNTER TYPE NAME"); encounter.setEncounterType(encounterType); Location location = new Location(1); location.setUuid("LOCATION UUID"); location.setName("LOCATION NAME"); encounter.setLocation(location); Person provider = new Person(1); provider.setUuid("PROVIDER UUID"); provider.addName( new PersonName("PROVIDER GIVENNAME", "PROVIDER MIDDLENAME", "PROVIDER FAMILYNAME")); encounter.setProvider(provider); ConceptSource source = new ConceptSource(); source.setName("AMPATH"); ConceptMap map = new ConceptMap(); map.setSourceCode("200"); map.setSource(source); ConceptDatatype datatype = new ConceptDatatype(); datatype.setUuid(ConceptDatatype.NUMERIC_UUID); datatype.setHl7Abbreviation(ConceptDatatype.NUMERIC); ConceptNumeric concept = new ConceptNumeric(); concept.setDatatype(datatype); concept.addConceptMapping(map); concept.addName(new ConceptName("NumericConcept", Locale.ENGLISH)); concept.setUnits("mg"); Date dateCreated = new Date(213231421890234L); Obs obs = new Obs(2); obs.setConcept(concept); obs.setDateCreated(dateCreated); obs.setValueNumeric(10d); obs.setObsGroup(getObsGroup()); obs.getObsGroup().addGroupMember(obs); encounter.addObs(obs); obs = new Obs(3); obs.setConcept(concept); obs.setDateCreated(dateCreated); obs.setValueNumeric(23d); encounter.addObs(obs); Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("encounter", encounter); bindings.put("implementationId", "MVP"); // when HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic Obs Group"); String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings); // then evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate); Assert.assertEquals( "<ORU_R01.ORDER_OBSERVATION><OBR><OBR.1>0</OBR.1><OBR.4><CE.1>100</CE.1>" + "<CE.2>MEDICALRECORDOBSERVATIONS</CE.2><CE.3>LOCAL</CE.3></OBR.4><OBR.18>0</OBR.18>" + "<OBR.29><EIP.2><EI.3>ENCOUNTERUUID</EI.3></EIP.2></OBR.29></OBR><ORU_R01.OBSERVATION>" + "<OBX><OBX.1>1</OBX.1><OBX.2>NM</OBX.2><OBX.3><CE.1>200</CE.1><CE.2>NumericConcept</CE.2>" + "<CE.3>AMPATH</CE.3></OBX.3><OBX.5>23.0</OBX.5><OBX.6><CE.1>mg</CE.1><CE.3>UCUM</CE.3></OBX.6>" + "<OBX.14><TS.1>" + new HL7TemplateFunctions().formatDate(dateCreated, null) + "</TS.1>" + "</OBX.14></OBX></ORU_R01.OBSERVATION></ORU_R01.ORDER_OBSERVATION>" + "<ORU_R01.ORDER_OBSERVATION><OBR><OBR.1>2</OBR.1><OBR.4><CE.1>100</CE.1><CE.2>MedSet</CE.2>" + "<CE.3>LOCAL</CE.3></OBR.4><OBR.18>0</OBR.18><OBR.29><EIP.2><EI.3>ENCOUNTERUUID</EI.3></EIP.2></OBR.29" + "></OBR><ORU_R01.OBSERVATION><OBX><OBX.1>2</OBX.1><OBX.2>NM</OBX.2><OBX.3><CE.1>200</CE.1>" + "<CE.2>NumericConcept</CE.2><CE.3>AMPATH</CE.3></OBX.3><OBX.5>10.0</OBX.5><OBX.6><CE.1>mg</CE.1>" + "<CE.3>UCUM</CE.3></OBX.6><OBX.14><TS.1>" + new HL7TemplateFunctions().formatDate(dateCreated, null) + "</TS.1></OBX.14></OBX></ORU_R01.OBSERVATION></ORU_R01.ORDER_OBSERVATION>", evaluatedTemplate); }
private static String replaceIdsWithUuidsHelper( String formXmlData, String attribute, String objectType) { // pattern to find the specified attribute and pull out its values; regex matches any characters // within quotes after an equals, i.e. ="a2-32" would match a232 Pattern substitutionPattern = Pattern.compile(attribute + "=\"(.*?)\"", Pattern.CASE_INSENSITIVE); Matcher matcher = substitutionPattern.matcher(formXmlData); // list to keep track of any "repeat" keys we are going to have to substitute out as well Set<String> keysToReplace = new HashSet<String>(); StringBuffer buffer = new StringBuffer(); while (matcher.find()) { // split the group into the various ids String[] ids = matcher.group(1).split(","); StringBuffer idBuffer = new StringBuffer(); // now loop through each id for (String id : ids) { // see if this is a concept id (i.e., is made up of one or more digits), as opposed to a // mapping id or a uuid, or a key used in a repeat template) if (id.matches("^\\d+$")) { // now we need to fetch the appropriate object for this id, and append the uuid to the // buffer if ("concept".equalsIgnoreCase(objectType)) { Concept concept = Context.getConceptService().getConcept(Integer.valueOf(id)); idBuffer.append(concept.getUuid() + ","); } else if ("location".equalsIgnoreCase(objectType)) { Location location = Context.getLocationService().getLocation(Integer.valueOf(id)); idBuffer.append(location.getUuid() + ","); } else if ("program".equalsIgnoreCase(objectType)) { Program program = Context.getProgramWorkflowService().getProgram(Integer.valueOf(id)); idBuffer.append(program.getUuid() + ","); } else if ("person".equalsIgnoreCase(objectType)) { Person person = Context.getPersonService().getPerson(Integer.valueOf(id)); idBuffer.append(person.getUuid() + ","); } } else { // otherwise, leave the id only idBuffer.append(id + ","); // also, if this id is a key (i.e., something in curly braces) we need to keep track of it // so that we can perform key substitutions // pattern matches one or more characters of any type within curly braces Matcher keyMatcher = Pattern.compile("\\{(.+)\\}").matcher(id); if (keyMatcher.find()) { keysToReplace.add(keyMatcher.group(1)); } } } // trim off the trailing comma idBuffer.deleteCharAt(idBuffer.length() - 1); // now do the replacement // append to the buffer the matched sequence, substituting out group(1) with the updated ids matcher.appendReplacement( buffer, matcher.group().substring(0, matcher.start(1) - matcher.start()) + idBuffer.toString() + "\""); } // append the rest of htmlform matcher.appendTail(buffer); formXmlData = buffer.toString(); // now recursively handle any keys we have discovered during this substitution for (String key : keysToReplace) { formXmlData = replaceIdsWithUuidsHelper(formXmlData, key); } return formXmlData; }
/** * Construct a new EncounterDetailSubmissionElement * * @param context * @param parameters * @should display 'Enter' option if 'type' is set to Autocomplete */ public EncounterDetailSubmissionElement( FormEntryContext context, Map<String, Object> parameters) { // Register Date and Time widgets, if appropriate if (Boolean.TRUE.equals(parameters.get("date"))) { dateWidget = new DateWidget(); dateErrorWidget = new ErrorWidget(); if (context.getExistingEncounter() != null) { dateWidget.setInitialValue(context.getExistingEncounter().getEncounterDatetime()); } else if (parameters.get("defaultDate") != null) { dateWidget.setInitialValue(parameters.get("defaultDate")); } if (parameters.get("disallowMultipleEncountersOnDate") != null && StringUtils.hasText((String) parameters.get("disallowMultipleEncountersOnDate"))) { dateWidget.setOnChangeFunction( "existingEncounterOnDate(this, '" + parameters.get("disallowMultipleEncountersOnDate") + "') "); } if ("true".equals(parameters.get("showTime"))) { timeWidget = new TimeWidget(); timeErrorWidget = new ErrorWidget(); if (context.getExistingEncounter() != null) { timeWidget.setInitialValue(context.getExistingEncounter().getEncounterDatetime()); } else if (parameters.get("defaultDate") != null) { timeWidget.setInitialValue(parameters.get("defaultDate")); } context.registerWidget(timeWidget); context.registerErrorWidget(timeWidget, timeErrorWidget); } context.registerWidget(dateWidget); context.registerErrorWidget(dateWidget, dateErrorWidget); } // Register Provider widgets, if appropriate 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 the "order" attribute is passed in, limit to the specified locations in order if (parameters.get("order") != null) { String[] temp = ((String) parameters.get("order")).split(","); for (String s : temp) { Location loc = HtmlFormEntryUtil.getLocation(s); if (loc == null) { throw new RuntimeException("Cannot find location: " + loc); } locations.add(loc); } } // Set default values Location defaultLocation = null; if (context.getExistingEncounter() != null) { defaultLocation = context.getExistingEncounter().getLocation(); } else { String defaultLocId = (String) parameters.get("default"); if (StringUtils.hasText(defaultLocId)) { defaultLocation = HtmlFormEntryUtil.getLocation(defaultLocId); } } defaultLocation = defaultLocation == null ? context.getDefaultLocation() : defaultLocation; locationWidget.setInitialValue(defaultLocation); if (!locations.isEmpty()) { for (Location location : locations) { String label = location.getName(); Option option = new Option(label, location.getId().toString(), location.equals(defaultLocation)); locationOptions.add(option); } } else { locations = Context.getLocationService().getAllLocations(); for (Location location : locations) { String label = location.getName(); Option option = new Option(label, location.getId().toString(), location.equals(defaultLocation)); locationOptions.add(option); } Collections.sort(locationOptions, new OptionComparator()); } if ("autocomplete".equals(parameters.get("type"))) { locationWidget.addOption(new Option()); if (!locationOptions.isEmpty()) { locationWidget.setOptions(locationOptions); } } else { boolean initialValueIsSet = !(locationWidget.getInitialValue() == null); locationWidget.addOption( new Option( Context.getMessageSourceService().getMessage("htmlformentry.chooseALocation"), "", !initialValueIsSet)); if (!locationOptions.isEmpty()) { for (Option option : locationOptions) locationWidget.addOption(option); } } context.registerWidget(locationWidget); context.registerErrorWidget(locationWidget, locationErrorWidget); } if (Boolean.TRUE.equals(parameters.get("showVoidEncounter")) && context.getMode() == Mode .EDIT) { // only show void option if the encounter already exists. And VIEW implies // not voided. if (parameters.get("toggle") != null) { ToggleWidget toggleWidget = new ToggleWidget((String) parameters.get("toggle")); voidWidget = new CheckboxWidget( " " + Context.getMessageSourceService().getMessage("general.voided"), (context.getExistingEncounter() != null && context.getExistingEncounter().isVoided().equals(true)) ? "true" : "false", toggleWidget.getTargetId(), toggleWidget.isToggleDim()); } else { voidWidget = new CheckboxWidget(); } voidWidget.setLabel(" " + Context.getMessageSourceService().getMessage("general.voided")); voidErrorWidget = new ErrorWidget(); if (context.getExistingEncounter() != null && context.getExistingEncounter().isVoided().equals(true)) voidWidget.setInitialValue("true"); context.registerWidget(voidWidget); context.registerErrorWidget(voidWidget, voidErrorWidget); } // set the id, if it has been specified if (parameters.get("id") != null) { id = (String) parameters.get("id"); } }