protected DrugOrder existingOrder;
protected List<Drug> drugsUsedAsKey;
public DrugOrderSubmissionElement(FormEntryContext context, Map<String, String> parameters) {
ConceptService conceptService = Context.getConceptService();
MessageSourceService mss = Context.getMessageSourceService();
Boolean usingDurationField = false;
String orderDurationStr = parameters.get(FIELD_SHOW_ORDER_DURATION);
if (!StringUtils.isEmpty(orderDurationStr) && orderDurationStr.equals("true"))
usingDurationField = true;
String hideDoseAndFreqStr = parameters.get(CONFIG_SHOW_DOSE_AND_FREQ);
if (!StringUtils.isEmpty(hideDoseAndFreqStr) && hideDoseAndFreqStr.equals("true"))
hideDoseAndFrequency = true;
String checkboxStr = parameters.get(FIELD_CHECKBOX);
if (checkboxStr != null && checkboxStr.equals("true"))
checkbox = true;
// check URL
String drugNames = parameters.get(FIELD_DRUG_NAMES);
if (drugNames == null || drugNames.length() < 1)
throw new IllegalArgumentException("You must provide a valid drug name, or a valid ID or a valid UUID in " + parameters);
String fieldValidateDose = parameters.get(FIELD_VALIDATE_DOSE);
if (fieldValidateDose != null && fieldValidateDose.length() > 1)
validateDose = Boolean.parseBoolean(fieldValidateDose);
if (parameters.get(FIELD_DRUG_LABELS) != null) {
drugLabels = Arrays.asList(parameters.get(FIELD_DRUG_LABELS).split(","));
}
// fill drop down with drug names from database
List<Option> options = new ArrayList<Option>();
options.add(new Option("", "", false));
// drugNames is comma separated list which can contain ID, UUID or drugname
StringTokenizer tokenizer = new StringTokenizer(drugNames, ",");
int drugListIndexPos = 0;
String displayText = "";
DrugOrderField dof = new DrugOrderField();
while (tokenizer.hasMoreElements()) {
String drugName = (String) tokenizer.nextElement();
Drug drug = null;
// see if this is a uuid
if (HtmlFormEntryUtil.isValidUuidFormat(drugName.trim())) {
drug = conceptService.getDrugByUuid(drugName.trim());
}
// if we didn't find by id, find by uuid or name
if (drug == null){
drug = conceptService.getDrugByNameOrId(drugName.trim());
}
if (drug != null) {
displayText = drug.getName();
if (drugLabels != null) {