Advertisement
Guest User

Untitled

a guest
Apr 29th, 2020
23
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.85 KB | None
  1. package org.openmrs.module.openmrslearningrest.resource;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. import org.openmrs.api.context.Context;
  7. import org.openmrs.module.openmrslearningrest.Laboratory;
  8. import org.openmrs.module.webservices.rest.web.RequestContext;
  9. import org.openmrs.module.webservices.rest.web.RestConstants;
  10. import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
  11. import org.openmrs.module.webservices.rest.web.annotation.PropertySetter;
  12. import org.openmrs.module.webservices.rest.web.annotation.Resource;
  13. import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
  14. import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
  15. import org.openmrs.module.webservices.rest.web.representation.RefRepresentation;
  16. import org.openmrs.module.webservices.rest.web.representation.Representation;
  17. import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
  18. import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
  19. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
  20. import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult;
  21. import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
  22. import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
  23. import org.openmrs.module.webservices.rest.web.response.ResponseException;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25.  
  26. import io.swagger.models.Model;
  27. import io.swagger.models.ModelImpl;
  28. import io.swagger.models.properties.BooleanProperty;
  29. import io.swagger.models.properties.IntegerProperty;
  30. import io.swagger.models.properties.RefProperty;
  31. import io.swagger.models.properties.StringProperty;
  32.  
  33. @Resource(name = RestConstants.VERSION_2 + "/laboratory", supportedClass = Laboratory.class, supportedOpenmrsVersions = {
  34. "2.0.*", "2.1.*", "2.2.*", "2.3.*", "2.4.*" })
  35. public class LaboratoryResource extends DataDelegatingCrudResource<Laboratory>{
  36.  
  37.  
  38. private static final Class<? extends Laboratory> LaboratoryService = null;
  39.  
  40. @Autowired
  41. org.openmrs.module.openmrslearningrest.api.LaboratoryService laboratoryService;
  42.  
  43. /**
  44. * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
  45. */
  46. public String getResourceVersion() {
  47. return RestConstants.PROPERTY_FOR_RESOURCE_VERSION;
  48. }
  49.  
  50. public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
  51. if (rep instanceof DefaultRepresentation) {
  52. DelegatingResourceDescription description = new DelegatingResourceDescription();
  53. description.addProperty("display");
  54. description.addProperty("voided");
  55. description.addProperty("uuid");
  56. description.addProperty("name");
  57. description.addProperty("Equipments", Representation.REF);
  58. description.addSelfLink();
  59. description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  60. return description;
  61.  
  62. }
  63. else if (rep instanceof FullRepresentation) {
  64. DelegatingResourceDescription description = new DelegatingResourceDescription();
  65. description.addProperty("display");
  66. description.addProperty("voided");
  67. description.addProperty("uuid");
  68. description.addProperty("name");
  69. description.addProperty("id");
  70. description.addProperty("auditInfo");
  71. description.addProperty("Equipments", Representation.FULL);
  72. description.addSelfLink();
  73. return description;
  74.  
  75. }
  76. else if (rep instanceof RefRepresentation) {
  77. DelegatingResourceDescription description = new DelegatingResourceDescription();
  78. description.addProperty("uuid");
  79. description.addProperty("display");
  80. description.addSelfLink();
  81. return description;
  82.  
  83. }
  84. return null;
  85. }
  86.  
  87. @Override
  88. public DelegatingResourceDescription getCreatableProperties() {
  89. DelegatingResourceDescription description = new DelegatingResourceDescription();
  90. description.addRequiredProperty("name");
  91. description.addRequiredProperty("id");
  92. description.addProperty("Equipments");
  93. return description;
  94.  
  95. }
  96.  
  97. public Model getGetModel(Representation rep) {
  98. ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep));
  99. if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) {
  100. modelImpl
  101. .property("uuid", new StringProperty())
  102. .property("display", new StringProperty())
  103. .property("name", new StringProperty())
  104. .property("voided", new BooleanProperty())
  105. .property("Equipments", new StringProperty())
  106. .property("Equipments", new RefProperty("#/definitions/EquipmentGetRef"));
  107.  
  108. }
  109. if (rep instanceof DefaultRepresentation) {
  110. modelImpl
  111. .property("uuid", new StringProperty())
  112. .property("display", new StringProperty())
  113. .property("name", new StringProperty())
  114. .property("voided", new BooleanProperty())
  115. .property("parentLaboratory", new RefProperty("#/definitions/parentLaboratoryGetRef"))
  116. .property("equipments", new StringProperty())
  117. .property("Equipments", new RefProperty("#/definitions/EquipmentGetRef"));
  118.  
  119. }
  120. else if (rep instanceof FullRepresentation) {
  121. modelImpl
  122.  
  123. .property("uuid", new StringProperty())
  124. .property("display", new StringProperty())
  125. .property("voided", new BooleanProperty())
  126. .property("auditInfo", new StringProperty())
  127. .property("id", new IntegerProperty())
  128. .property("name", new StringProperty())
  129. .property("Laboratory", new RefProperty("#/definitions/LaboratoryGetRef"))
  130. .property("equipments", new StringProperty())
  131. .property("Equipments", new RefProperty("#/definitions/EquipmentGet"));
  132.  
  133. } else if (rep instanceof RefRepresentation) {
  134. modelImpl
  135. .property("display", new StringProperty())
  136. .property("uuid", new StringProperty());
  137.  
  138. }
  139. return modelImpl;
  140.  
  141. }
  142.  
  143. public Model getCREATEModel(Representation representation) {
  144. ModelImpl model = new ModelImpl()
  145. .property("equipment", new StringProperty())
  146. .property("name", new StringProperty())
  147. .property("id", new StringProperty())
  148. .property("Equipements", new RefProperty("#/definitions/LaboratoryEquipmentsCreate"));
  149. return model;
  150. }
  151.  
  152. public Model getUPDATEModel(Representation representation) {
  153. return new ModelImpl()
  154. .property("Name", new StringProperty());
  155. }
  156.  
  157. @Override
  158. public Laboratory newDelegate() {
  159. return new Laboratory();
  160.  
  161. }
  162.  
  163. @PropertyGetter("display")
  164. public String getDisplayString(Laboratory laboratory) {
  165. return laboratory.getName();
  166. }
  167.  
  168. @PropertyGetter("auditInfo")
  169. public String getAudit(Laboratory laboratory) {
  170. return laboratory.getName() + "Auditor";
  171. }
  172.  
  173. @PropertyGetter("name")
  174. public String getName(Laboratory laboratory) {
  175. return laboratory.getName() + "name";
  176. }
  177.  
  178. @PropertyGetter("auditInfo")
  179. public String id(Laboratory laboratory) {
  180. return laboratory.getUuid() + "Uuid";
  181. }
  182.  
  183. @Override
  184. protected void delete(Laboratory delegate, String reason, RequestContext context) throws ResponseException {
  185. throw new ResourceDoesNotSupportOperationException();
  186.  
  187. }
  188.  
  189. @PropertySetter("Equipments")
  190. public static void setMappings(Laboratory instance, List<Laboratory> laboratory) {
  191. for (Laboratory lab : laboratory) {
  192. lab.setId(instance.getId());
  193. }
  194. }
  195.  
  196. @Override
  197. public List<String> getPropertiesToExposeAsSubResources() {
  198. return Arrays.asList("Laboratory");
  199. }
  200.  
  201. @Override
  202. public Laboratory save(Laboratory delegate) {
  203. throw new ResourceDoesNotSupportOperationException();
  204. }
  205.  
  206. @Override
  207. public Laboratory getByUniqueId(String uniqueId) {
  208. String laboratory = Context.getService(LaboratoryService).getUuid();
  209.  
  210. return null;
  211. }
  212.  
  213. @Override
  214. public void purge(Laboratory delegate, RequestContext context) throws ResponseException {
  215.  
  216. }
  217. @Override
  218. protected PageableResult doSearch(RequestContext context) {
  219. List<Laboratory> laboratories = Context.getService(LaboratoryService).getLaboratories(context.getParameter("q"));
  220. // .getCohorts(context.getParameter("q"));
  221. return new NeedsPaging<Laboratory>(laboratories, context);
  222. // String LaboratoryUuid = context.getRequest().getParameter("LaboratoryUuid");
  223. // if(LaboratoryUuid!= null) {
  224. // Laboratory laboratory = Context.getService(Laboratory.class).getResourceSupportedByClass(Laboratory.class).getByUniqueId(LaboratoryUuid);
  225. // if(laboratory==null) {
  226. // return new EmptySearchResult();
  227. // return new NeedsPaging<Laboratory>(Context.getService(LaboratoryService.getClass(),context);
  228. //// return new NeedsPaging<Laboratory>(Context.getPatientService().getAllergies(patient), context);
  229. // }
  230.  
  231. }
  232.  
  233. }
Advertisement
RAW Paste Data Copied
Advertisement