Guest User

Untitled

a guest
Dec 3rd, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs.module.jsslab.rest.resource;
  15.  
  16. import java.util.List;
  17.  
  18. import org.openmrs.module.jsslab.db.LabInstrument;
  19. import org.openmrs.annotation.Handler;
  20. import org.openmrs.module.jsslab.LabManagementService;
  21. import org.openmrs.api.context.Context;
  22. import org.openmrs.module.webservices.rest.web.RequestContext;
  23. import org.openmrs.module.webservices.rest.web.RestConstants;
  24. import org.openmrs.module.webservices.rest.web.annotation.Resource;
  25. import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
  26. import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
  27. import org.openmrs.module.webservices.rest.web.representation.Representation;
  28. import org.openmrs.module.webservices.rest.web.resource.impl.AlreadyPaged;
  29. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource;
  30. import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
  31. import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
  32. import org.openmrs.module.webservices.rest.web.resource.impl.ServiceSearcher;
  33. import org.openmrs.module.webservices.rest.web.response.ResponseException;
  34.  
  35. /**
  36. * {@link Resource} for {@link Location}, supporting standard CRUD operations
  37. */
  38. @Resource("labInstrument")
  39. @Handler(supports = LabInstrument.class, order = 0)
  40. public class LabInstrumentResource extends MetadataDelegatingCrudResource<LabInstrument> {
  41.  
  42. /**
  43. * @see DelegatingCrudResource#getRepresentationDescription(Representation)
  44. */
  45. @Override
  46. public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
  47. if (rep instanceof DefaultRepresentation) {
  48. DelegatingResourceDescription description = new DelegatingResourceDescription();
  49. description.addProperty("uuid");
  50. description.addProperty("name");
  51. description.addProperty("propertyTag");
  52. description.addProperty("location",Representation.REF);
  53. description.addProperty("retired");
  54. description.addSelfLink();
  55. description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
  56. return description;
  57. } else if (rep instanceof FullRepresentation) {
  58. DelegatingResourceDescription description = new DelegatingResourceDescription();
  59. description.addProperty("uuid");
  60. description.addProperty("propertyTag");
  61. description.addProperty("manufacturer");
  62. description.addProperty("model");
  63. description.addProperty("serialNumber");
  64. description.addProperty("location",Representation.REF);
  65. description.addProperty("receivedDate");
  66. description.addProperty("receivedFrom");
  67. description.addProperty("receivedCost");
  68. description.addProperty("receivedValue");
  69. description.addProperty("conditionDate");
  70. description.addProperty("conditionConcept",Representation.REF);
  71. description.addProperty("maintenanceVendor");
  72. description.addProperty("maintenancePhone");
  73. description.addProperty("maintenanceDescription");
  74. description.addProperty("testSpecimens", Representation.REF);
  75. description.addProperty("auditInfo", findMethod("getAuditInfo"));
  76. description.addSelfLink();
  77. return description;
  78. }
  79. return null;
  80. }
  81.  
  82. /**
  83. * @see DelegatingCrudResource#newDelegate()
  84. */
  85. @Override
  86. public LabInstrument newDelegate() {
  87. return new LabInstrument();
  88. }
  89.  
  90. /**
  91. * @see DelegatingCrudResource#save(java.lang.Object)
  92. */
  93. @Override
  94. public LabInstrument save(LabInstrument labInstrument) {
  95. return Context.getService(LabManagementService.class)
  96. .saveLabInstrument(labInstrument);
  97. }
  98.  
  99. /**
  100. * Fetches a LabInstrument by uuid, if no match is found, it tries to look up one with a matching
  101. * propertyTag or serialNumber
  102. *
  103. * @see DelegatingCrudResource#getByUniqueId(java.lang.String)
  104. */
  105. @Override
  106. public LabInstrument getByUniqueId(String uuid) {
  107. LabInstrument labInstrument = Context.getService(LabManagementService.class).getLabInstrumentByUuid(uuid);
  108. //We assume the caller was fetching by propertyTag or serialNumber
  109. if (labInstrument == null)
  110. labInstrument = Context.getService(LabManagementService.class).getLabInstrument(uuid);
  111.  
  112. return labInstrument;
  113. }
  114.  
  115. /**
  116. * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object,
  117. * org.openmrs.module.webservices.rest.web.RequestContext)
  118. */
  119. @Override
  120. public void purge(LabInstrument labInstrument, RequestContext context) throws ResponseException {
  121. if (labInstrument == null)
  122. return;
  123. Context.getService(LabManagementService.class).purgeLabInstrument(LabInstrument);
  124. }
  125.  
  126. /**
  127. * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext)
  128. */
  129. @Override
  130. protected List<LabInstrument> doGetAll(RequestContext context) {
  131. return Context.getService(LabManagementService.class).getAllLabInstruments(false);
  132. }
  133.  
  134. /**
  135. * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(java.lang.String,
  136. * org.openmrs.module.webservices.rest.web.RequestContext)
  137. */
  138. @Override
  139. protected AlreadyPaged<LabInstrument> doSearch(String query, RequestContext context) {
  140. return new ServiceSearcher<LabInstrument>(LabInstrumentService.class, "getLabInstruments", "getCountOfLabInstruments").search(query,
  141. context);
  142. }
  143.  
  144. }
  145.  
  146.  
Advertisement
Add Comment
Please, Sign In to add comment