Guest User

Untitled

a guest
Feb 28th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. /**
  2.  
  3. * The contents of this file are subject to the OpenMRS Public License
  4.  
  5. * Version 1.0 (the "License"); you may not use this file except in
  6.  
  7. * compliance with the License. You may obtain a copy of the License at
  8.  
  9. * http://license.openmrs.org
  10.  
  11. *
  12.  
  13. * Software distributed under the License is distributed on an "AS IS"
  14.  
  15. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  16.  
  17. * License for the specific language governing rights and limitations
  18.  
  19. * under the License.
  20.  
  21. *
  22.  
  23. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  24.  
  25. */
  26.  
  27. package org.openmrs.web.attribute.handler;
  28.  
  29.  
  30.  
  31. import java.util.HashMap;
  32.  
  33. import java.util.Map;
  34.  
  35.  
  36.  
  37. import javax.servlet.http.HttpServletRequest;
  38.  
  39.  
  40.  
  41. import org.apache.commons.lang.StringUtils;
  42.  
  43. import org.openmrs.Concept;
  44.  
  45. import org.openmrs.api.context.Context;
  46.  
  47. import org.openmrs.customdatatype.CustomDatatype;
  48.  
  49. import org.openmrs.customdatatype.InvalidCustomValueException;
  50.  
  51. import org.openmrs.customdatatype.datatype.ConceptDatatype;
  52.  
  53. import org.openmrs.messagesource.MessageSourceService;
  54.  
  55. import org.springframework.stereotype.Component;
  56.  
  57.  
  58.  
  59. /**
  60.  
  61. * Handler for the concept custom datatype
  62.  
  63. */
  64.  
  65. @Component
  66.  
  67. public class ConceptDatatypeHandler implements FieldGenDatatypeHandler<ConceptDatatype, Concept> {
  68.  
  69.  
  70.  
  71. /**
  72.  
  73. * @see org.openmrs.customdatatype.CustomDatatypeHandler#setHandlerConfiguration(java.lang.String)
  74.  
  75. */
  76.  
  77. @Override
  78.  
  79. public void setHandlerConfiguration(String arg0) {
  80.  
  81. // not used
  82.  
  83. }
  84.  
  85.  
  86.  
  87. /**
  88.  
  89. * @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getWidgetName()
  90.  
  91. */
  92.  
  93. @Override
  94.  
  95. public String getWidgetName() {
  96.  
  97. return "concept";
  98.  
  99. }
  100.  
  101.  
  102.  
  103. /**
  104.  
  105. * @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getWidgetConfiguration()
  106.  
  107. */
  108.  
  109. @Override
  110.  
  111. public Map<String, Object> getWidgetConfiguration() {
  112.  
  113. MessageSourceService mss = Context.getMessageSourceService();
  114.  
  115. Map<String, Object> ret = new HashMap<String, Object>();
  116.  
  117. ret.put("isNullable", "false");
  118.  
  119. ret.put("trueLabel", mss.getMessage("general.true"));
  120.  
  121. ret.put("falseLabel", mss.getMessage("general.false"));
  122.  
  123. return ret;
  124.  
  125. }
  126.  
  127.  
  128.  
  129. /**
  130.  
  131. * @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getValue(org.openmrs.customdatatype.CustomDatatype, javax.servlet.http.HttpServletRequest, java.lang.String)
  132.  
  133. */
  134.  
  135. @Override
  136.  
  137. public Concept getValue(org.openmrs.customdatatype.datatype.ConceptDatatype datatype, HttpServletRequest request,
  138.  
  139. String formFieldName) throws InvalidCustomValueException {
  140.  
  141. String result = request.getParameter(formFieldName);
  142.  
  143. if (StringUtils.isBlank(result))
  144.  
  145. return null;
  146.  
  147. try {
  148.  
  149. return new Concept();
  150.  
  151. }
  152.  
  153. catch (Exception e) {
  154.  
  155. throw new InvalidCustomValueException("Invalid concept: " + result);
  156.  
  157. }
  158.  
  159. }
  160.  
  161.  
  162.  
  163. /**
  164.  
  165. * @see org.openmrs.web.attribute.handler.HtmlDisplayableDatatypeHandler#toHtmlSummary(org.openmrs.customdatatype.CustomDatatype, java.lang.String)
  166.  
  167. */
  168.  
  169. @Override
  170.  
  171. public CustomDatatype.Summary toHtmlSummary(CustomDatatype<Concept> datatype, String valueReference) {
  172.  
  173. return new CustomDatatype.Summary(valueReference, true);
  174.  
  175. }
  176.  
  177.  
  178.  
  179. /**
  180.  
  181. * @see org.openmrs.web.attribute.handler.HtmlDisplayableDatatypeHandler#toHtml(org.openmrs.customdatatype.CustomDatatype, java.lang.String)
  182.  
  183. */
  184.  
  185. @Override
  186.  
  187. public String toHtml(CustomDatatype<Concept> datatype, String valueReference) {
  188.  
  189. return valueReference;
  190.  
  191. }
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment