List<Option> options = new ArrayList<Option>();
options.add(new Option("", "", false));
StringTokenizer tokenizer = new StringTokenizer(regimenCodes, ",");
allSystemStandardRegimens = DrugOrderSupport.getInstance().getStandardRegimens();
StandardRegimenField srf = new StandardRegimenField();
while (tokenizer.hasMoreElements()) {
String regCode = (String) tokenizer.nextElement();
RegimenSuggestion rs = getRegimenSuggestionByCode(regCode, allSystemStandardRegimens);
if (rs != null){
options.add(new Option(rs.getDisplayName(),rs.getCodeName(), false));
srf.addStandardRegimenAnswer(new StandardRegimenAnswer(rs));
possibleRegimens.add(rs);
} else {
throw new IllegalArgumentException("standardRegimen tag can't find regimen code " + regCode + " found in regimenCodes attribute in global property " + STANDARD_REGIMEN_GLOBAL_PROPERTY);
}
}
DropdownWidget dw = new DropdownWidget();
dw.setOptions(options);
regWidget = dw;
context.registerWidget(regWidget);
regErrorWidget = new ErrorWidget();
context.registerErrorWidget(regWidget, regErrorWidget);
//start date
startDateWidget = new DateWidget();
startDateErrorWidget = new ErrorWidget();
context.registerWidget(startDateWidget);
context.registerErrorWidget(startDateWidget, startDateErrorWidget);
//end date
discontinuedDateWidget = new DateWidget();
discontinuedDateErrorWidget = new ErrorWidget();
context.registerWidget(discontinuedDateWidget);
context.registerErrorWidget(discontinuedDateWidget, discontinuedDateErrorWidget);
//discontinue reasons
if (parameters.get(FIELD_DISCONTINUED_REASON) != null){
String discReasonConceptStr = (String) parameters.get(FIELD_DISCONTINUED_REASON);
Concept discontineReasonConcept = HtmlFormEntryUtil.getConcept(discReasonConceptStr);
if (discontineReasonConcept == null)
throw new IllegalArgumentException("discontinuedReasonConceptId is not set to a valid conceptId or concept UUID");
srf.setDiscontinuedReasonQuestion(discontineReasonConcept);
discontinuedReasonWidget = new DropdownWidget();
discontinuedReasonErrorWidget = new ErrorWidget();
List<Option> discOptions = new ArrayList<Option>();
discOptions.add(new Option("", "", false));
if (parameters.get(FIELD_DISCONTINUED_REASON_ANSWERS) != null){
//setup a list of the reason concepts
List<Concept> discReasons = new ArrayList<Concept>();
String discAnswersString = (String) parameters.get(FIELD_DISCONTINUED_REASON_ANSWERS);
String[] strDiscAnswers = discAnswersString.split(",");
for (int i = 0; i < strDiscAnswers.length; i++){
String thisAnswer = strDiscAnswers[i];
Concept answer = HtmlFormEntryUtil.getConcept(thisAnswer, "discontinueReasonAnswers includes a value that is not a valid conceptId or concept UUID");
discReasons.add(answer);
}
if (parameters.get(FIELD_DISCONTINUED_REASON_ANSWER_LABELS) != null){
// use the listed discontinueReasons, and use labels:
String discLabelsString = parameters.get(FIELD_DISCONTINUED_REASON_ANSWER_LABELS);
String[] strDiscAnswerLabels = discLabelsString.split(",");
//a little validation:
if (strDiscAnswerLabels.length != discReasons.size())
throw new RuntimeException("discontinueReasonAnswers and discontinueReasonAnswerLabels must contain the same number of members.");
for (int i = 0; i < strDiscAnswerLabels.length; i ++ ){
discOptions.add(new Option( strDiscAnswerLabels[i], discReasons.get(i).getConceptId().toString(),false));
srf.addDiscontinuedReasonAnswer(new ObsFieldAnswer(strDiscAnswerLabels[i].trim(), discReasons.get(i)));
}
} else {
// use the listed discontinueReasons, and use their ConceptNames.
for (Concept c: discReasons){
discOptions.add(new Option( c.getBestName(Context.getLocale()).getName(), c.getConceptId().toString(),false));
srf.addDiscontinuedReasonAnswer(new ObsFieldAnswer(c.getBestName(Context.getLocale()).getName(), c));
}
}
} else {
//just use the conceptAnswers
for (ConceptAnswer ca : discontineReasonConcept.getAnswers()){
discOptions.add(new Option( ca.getAnswerConcept().getBestName(Context.getLocale()).getName(), ca.getAnswerConcept().getConceptId().toString(),false));
srf.addDiscontinuedReasonAnswer(new ObsFieldAnswer(ca.getAnswerConcept().getBestName(Context.getLocale()).getName(), ca.getAnswerConcept()));
}
}
if (discOptions.size() == 1)
throw new IllegalArgumentException("discontinue reason Concept doesn't have any ConceptAnswers");