### Eclipse Workspace Patch 1.0
#P webservices.rest19ext
Index: omod/src/test/resources/conceptMappingTestDataset.xml
===================================================================
--- omod/src/test/resources/conceptMappingTestDataset.xml (revision 0)
+++ omod/src/test/resources/conceptMappingTestDataset.xml (revision 0)
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptReferenceTermMapController.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptReferenceTermMapController.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptReferenceTermMapController.java (revision 0)
@@ -0,0 +1,38 @@
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptReferenceTermMap;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.RestUtil;
+import org.openmrs.module.webservices.rest.web.annotation.WSDoc;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseSubResourceController;
+import org.openmrs.module.webservices.rest19ext.ConceptService19;
+import org.openmrs.module.webservices.rest19ext.web.v1_0.resource.ConceptMapResource;
+import org.openmrs.module.webservices.rest19ext.web.v1_0.resource.ConceptReferenceTermMapResource;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * Controller for REST web service access to ConceptReferenceTermMaps.
+ */
+@Controller
+@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/conceptreferenceterm/{parentUuid}/termmap")
+public class ConceptReferenceTermMapController extends BaseSubResourceController {
+
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptReferenceTermMapResource.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptReferenceTermMapResource.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptReferenceTermMapResource.java (revision 0)
@@ -0,0 +1,212 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.resource;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+
+import org.openmrs.Concept;
+import org.openmrs.ConceptName;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptReferenceTermMap;
+import org.openmrs.ConceptMapType;
+import org.openmrs.ConceptSource;
+import org.openmrs.LocationTag;
+import org.openmrs.ProviderAttribute;
+import org.openmrs.annotation.Handler;
+import org.openmrs.api.ConceptService;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.annotation.PropertySetter;
+import org.openmrs.module.webservices.rest.web.annotation.Resource;
+import org.openmrs.module.webservices.rest.web.annotation.SubResource;
+import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.AlreadyPaged;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.ConceptResource;
+import org.openmrs.module.webservices.rest19ext.ConceptService19;
+
+/**
+ * {@link Resource} for ConceptMaps, supporting standard CRUD operations
+ */
+@SubResource(parent = ConceptReferenceTermResource.class, path = "termmap")
+@Handler(supports = ConceptReferenceTermMap.class, order = 0)
+public class ConceptReferenceTermMapResource extends DelegatingSubResource {
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
+ */
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("conceptReferenceTermA", Representation.REF);
+ description.addProperty("mapType", Representation.REF);
+ description.addProperty("conceptReferenceTermB", Representation.REF);
+ description.addSelfLink();
+ description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
+ return description;
+ } else if (rep instanceof FullRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("TermA", Representation.FULL);
+ description.addProperty("mapType", Representation.REF);
+ description.addProperty("TermB", Representation.FULL);
+ description.addProperty("auditInfo", findMethod("getAuditInfo"));
+ description.addSelfLink();
+ return description;
+ }
+ return null;
+ }
+
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addRequiredProperty("TermA");
+ description.addRequiredProperty("mapType");
+ description.addRequiredProperty("TermB");
+ return description;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getUpdatableProperties() {
+ return getCreatableProperties();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object)
+ */
+ @Override
+ public ConceptReferenceTerm getParent(ConceptReferenceTermMap instance) {
+ return instance.getTermA();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate()
+ */
+ @Override
+ public ConceptReferenceTermMap newDelegate() {
+ return new ConceptReferenceTermMap();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptReferenceTermMap getByUniqueId(String uniqueId) {
+ return Context.getService(ConceptService19.class).getConceptReferenceTermMapByUuid(uniqueId);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object)
+ */
+ @Override
+ public ConceptReferenceTermMap save(ConceptReferenceTermMap delegate) {
+ if (delegate == null)
+ return null;
+ ConceptReferenceTerm parent = delegate.getTermA();
+ ConceptReferenceTermMap found = null;
+ Collection cm = parent.getConceptReferenceTermMaps();
+ for (ConceptReferenceTermMap m : cm)
+ if (m.equals(delegate)) {
+ found = m;
+ break;
+ }
+ if (found != null)
+ parent.removeConceptReferenceTermMap(found);
+ parent.addConceptReferenceTermMap(delegate);
+ Context.getConceptService().saveConceptReferenceTerm(parent);
+ return delegate;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected void delete(ConceptReferenceTermMap delegate, String reason, RequestContext context) throws ResponseException {
+ this.purge(delegate, context);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void purge(ConceptReferenceTermMap delegate, RequestContext context) throws ResponseException {
+ if (delegate == null)
+ return;
+ try {
+ delegate.getTermA().removeConceptReferenceTermMap(delegate);
+ }
+ catch (Exception e) {}
+ ;
+ ConceptReferenceTerm parent = delegate.getTermA();
+ Context.getConceptService().saveConceptReferenceTerm(parent);
+ return;
+ }
+
+ /**
+ * Gets the display string.
+ *
+ * @param cm the concept map.
+ * @return crt.name:c.name (non-default maptype)
+ */
+ public String getDisplayString(ConceptReferenceTermMap cm) {
+ ConceptService cs = Context.getConceptService();
+ StringBuilder s = new StringBuilder();
+ if (cm.getTermA() != null)
+ s.append(cm.getTermA().getName());
+ s.append(":");
+ if (cm.getTermB() != null)
+ s.append(cm.getTermB().getName());
+ if (cm.getConceptMapType() != null)
+ if (!cm.getConceptMapType().equals(Context.getConceptService().getDefaultConceptMapType()))
+ s.append(" (" + cm.getConceptMapType().getName() + ")");
+ return s.toString();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
+ */
+ @Override
+ public String getResourceVersion() {
+ return "1.9";
+ }
+
+ @Override
+ public void setParent(ConceptReferenceTermMap instance, ConceptReferenceTerm parent) {
+ instance.setTermA(parent);
+ }
+
+ @Override
+ public PageableResult doGetAll(ConceptReferenceTerm parent, RequestContext context) throws ResponseException {
+ return new NeedsPaging(
+ (List) parent.getConceptReferenceTermMaps(), context);
+ }
+
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptSourceResource.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptSourceResource.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptSourceResource.java (revision 0)
@@ -0,0 +1,205 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License Version
+ * 1.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.resource;
+
+import java.util.List;
+import org.openmrs.ConceptSource;
+import org.openmrs.annotation.Handler;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.annotation.Resource;
+import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.impl.AlreadyPaged;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
+import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+
+/**
+ * {@link Resource} for ConceptSource, supporting standard CRUD operations
+ */
+@Resource("conceptsource")
+@Handler(supports = ConceptSource.class, order = 100)
+public class ConceptSourceResource extends MetadataDelegatingCrudResource {
+
+ public ConceptSourceResource() {
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
+ */
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display", findMethod("getDisplayString"));
+ description.addProperty("description");
+ description.addProperty("hl7code");
+ description.addProperty("terms");
+ description.addProperty("retired");
+ description.addSelfLink();
+ description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
+ return description;
+ } else if (rep instanceof FullRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display", findMethod("getDisplayString"));
+ description.addProperty("description");
+ description.addProperty("hl7code");
+ description.addProperty("terms", Representation.FULL);
+ description.addProperty("retired");
+ description.addProperty("auditInfo", findMethod("getAuditInfo"));
+ description.addSelfLink();
+ return description;
+ }
+ return null;
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addRequiredProperty("uuid");
+ description.addRequiredProperty("name");
+ description.addProperty("description");
+ description.addProperty("hl7code");
+ description.addProperty("terms");
+ return description;
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getUpdatableProperties() {
+ return getCreatableProperties();
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate()
+ */
+ @Override
+ public ConceptSource newDelegate() {
+ return new ConceptSource();
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(java.lang.Object)
+ */
+ @Override
+ public ConceptSource save(ConceptSource conceptSource) {
+ return Context.getConceptService().saveConceptSource(conceptSource);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptSource getByUniqueId(String uuid) {
+ return Context.getConceptService().getConceptSourceByUuid(uuid);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void delete(ConceptSource conceptSource, String reason, RequestContext context) throws ResponseException {
+ if (conceptSource.isRetired()) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getConceptService().retireConceptSource(conceptSource, reason);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void purge(ConceptSource conceptSource, RequestContext context) throws ResponseException {
+ if (conceptSource == null) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getConceptService().purgeConceptSource(conceptSource);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(java.lang.String,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected AlreadyPaged doSearch(String query, RequestContext context) {
+ List conceptSources = Context.getConceptService().getAllConceptSources();
+ for (int i = conceptSources.size() - 1; i == 0; i--) {
+ if (!(conceptSources.get(i).getName().startsWith(query))
+ || (conceptSources.get(i).getDescription().startsWith(query))) {
+ conceptSources.remove(i);
+ }
+ }
+ int i = 0;
+ if (context.getStartIndex() > 0) {
+ i = context.getStartIndex();
+ }
+ int j = conceptSources.size();
+ if (context.getStartIndex() > 0) {
+ j = context.getLimit() + i;
+ }
+ return new AlreadyPaged(context, conceptSources.subList(i, j - 1), false);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(java.lang.String,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected NeedsPaging doGetAll(RequestContext context) throws ResponseException {
+ return new NeedsPaging(Context.getConceptService().getAllConceptSources(), context);
+ }
+
+ /**
+ * @param conceptSource
+ * @return identifier + name (for concise display purposes)
+ */
+ @Override
+ public String getDisplayString(ConceptSource conceptSource) {
+ if (conceptSource.getName() == null) {
+ return "";
+ }
+ return conceptSource.getName();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
+ */
+ @Override
+ public String getResourceVersion() {
+ return "1.9";
+ }
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptResource19.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptResource19.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptResource19.java (revision 0)
@@ -0,0 +1,78 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.resource;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.commons.lang.StringUtils;
+import org.openmrs.Concept;
+import org.openmrs.ConceptClass;
+import org.openmrs.ConceptDatatype;
+import org.openmrs.ConceptMap;
+import org.openmrs.ConceptSearchResult;
+import org.openmrs.annotation.Handler;
+import org.openmrs.api.ConceptService;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.web.ConversionUtil;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.annotation.Resource;
+import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.AlreadyPaged;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ConversionException;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.ConceptResource;
+import org.openmrs.module.webservices.rest19ext.ConceptService19;
+import org.openmrs.util.LocaleUtility;
+
+/**
+ * {@link Resource} for {@link Concept}, supporting standard CRUD operations
+ * This extension handles maps, search and reps for 1.9
+ */
+@Resource("concept")
+@Handler(supports = Concept.class, order = 50)
+public class ConceptResource19 extends ConceptResource {
+
+ protected PageableResult doSearch(String query, RequestContext context) {
+ ConceptService19 service = Context.getService(ConceptService19.class);
+
+ // Collect information for source and maptype queries
+ String source = context.getRequest().getParameter("source");
+ String maptype = context.getRequest().getParameter("maptype");
+ String q = query;
+ int i = q.indexOf(":");
+ if (i >= 0) {
+ source = q.substring(i + 1);
+ q = q.substring(0, i - 1);
+ }
+
+ // Do source and maptype queries
+ if (!source.isEmpty() && source != null) {
+ // TODO: Waiting on RESTWS-272
+ // return new NeedsPaging(service.getConceptsBySource(source, q, maptype, Context.getIncludeAll()),context);
+ return new NeedsPaging(service.getConceptsBySource(source, q, maptype, false), context);
+ }
+
+ if (!maptype.isEmpty() && maptype != null) {
+ // TODO: Waiting on RESTWS-272
+ // return new NeedsPaging(service.getConceptsByRefTerm(query, maptype, Context.getIncludeAll()),context);
+ return new NeedsPaging(service.getConceptsByRefTerm(query, maptype, false), context);
+ }
+ return super.doSearch(query, context);
+ }
+
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptMapController.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptMapController.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptMapController.java (revision 0)
@@ -0,0 +1,30 @@
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.RestUtil;
+import org.openmrs.module.webservices.rest.web.annotation.WSDoc;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
+import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseSubResourceController;
+import org.openmrs.module.webservices.rest19ext.web.v1_0.resource.ConceptMapResource;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * Controller for REST web service access to ConceptMaps. Supports CRUD on the resource itself.
+ */
+@Controller
+@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/concept/{parentUuid}/conceptmap")
+public class ConceptMapController extends BaseSubResourceController {
+
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptSourceController.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptSourceController.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptSourceController.java (revision 0)
@@ -0,0 +1,30 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudController;
+import org.openmrs.module.webservices.rest19ext.web.v1_0.resource.ConceptSourceResource;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * Controller for REST web service access to the ConceptSource resource. Supports CRUD on the resource
+ * itself, and listing and addition of some subresources.
+ */
+@Controller
+@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/conceptsource")
+public class ConceptSourceController extends BaseCrudController {
+
+}
Index: api/src/main/java/org/openmrs/module/webservices/rest19ext/db/hibernate/HibernateConcept19DAO.java
===================================================================
--- api/src/main/java/org/openmrs/module/webservices/rest19ext/db/hibernate/HibernateConcept19DAO.java (revision 0)
+++ api/src/main/java/org/openmrs/module/webservices/rest19ext/db/hibernate/HibernateConcept19DAO.java (revision 0)
@@ -0,0 +1,103 @@
+package org.openmrs.module.webservices.rest19ext.db.hibernate;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Criteria;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.transform.DistinctRootEntityResultTransformer;
+import org.openmrs.Concept;
+import org.openmrs.ConceptMap;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptReferenceTermMap;
+import org.openmrs.api.db.DAOException;
+import org.openmrs.api.db.hibernate.HibernateConceptDAO;
+import org.openmrs.module.webservices.rest19ext.db.Concept19DAO;
+
+public class HibernateConcept19DAO extends HibernateConceptDAO implements Concept19DAO {
+
+ protected final Log log = LogFactory.getLog(getClass());
+
+ private SessionFactory sessionFactory;
+
+ /**
+ * Sets the session factory
+ *
+ * @param sessionFactory
+ */
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
+ /**
+ * @see org.openmrs.api.db.ConceptDAO#getConceptsByMapping(java.lang.String, java.lang.String)
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public List getConceptsByMapping(String code, String sourceName, Integer maptype, boolean includeRetired) {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptMap.class);
+
+ // make this criteria return a list of concepts
+ criteria.setProjection(Projections.property("concept"));
+
+ //join to the conceptReferenceTerm table
+ criteria.createAlias("conceptReferenceTerm", "term");
+
+ // match the term code or name to the passed code
+ criteria.add(Restrictions.or(Restrictions.eq("term.code", code), Restrictions.eq("term.name", code)));
+
+ // join to concept reference source and match to the h17Code or source name
+ criteria.createAlias("term.conceptSource", "source");
+ criteria.add(Restrictions.or(Restrictions.eq("source.name", sourceName), Restrictions.eq("source.hl7Code",
+ sourceName)));
+
+ criteria.createAlias("concept", "concept");
+
+ if (maptype != null) {
+ criteria.add(Restrictions.eq("maptype", maptype));
+ }
+
+ if (!includeRetired) {
+ // ignore retired concepts
+ criteria.add(Restrictions.eq("concept.retired", false));
+ } else {
+ // sort retired concepts to the end of the list
+ criteria.addOrder(Order.asc("concept.retired"));
+ }
+
+ // we only want distinct concepts
+ criteria.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
+
+ return (List) criteria.list();
+ }
+
+ /**
+ * @see org.openmrs.api.db.Concept19DAO#getConceptReferenceTermMap(java.lang.Integer)
+ */
+ @Override
+ public ConceptReferenceTermMap getConceptReferenceTermMap(Integer conceptReferenceTermMapId) throws DAOException {
+ return (ConceptReferenceTermMap) sessionFactory.getCurrentSession().get(ConceptReferenceTermMap.class,
+ conceptReferenceTermMapId);
+ }
+
+ /**
+ * @see org.openmrs.api.db.Concept19DAO#getConceptMapTypeByUuid(java.lang.String)
+ */
+ @Override
+ public ConceptReferenceTermMap getConceptReferenceTermMapByUuid(String uuid) throws DAOException {
+ return (ConceptReferenceTermMap) sessionFactory.getCurrentSession().createQuery(
+ "from ConceptReferenceTermMapType crtm where crtm.uuid = :uuid").setString("uuid", uuid).uniqueResult();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public List getConceptReferenceTermCrossmaps(ConceptReferenceTerm crt) {
+ return (List) sessionFactory.getCurrentSession().createQuery(
+ "from ConceptReferenceTermMap crtm where crtm.termB = :crt").setString("crt", crt.getId().toString()).list();
+ }
+
+}
Index: api/src/main/java/org/openmrs/module/webservices/rest19ext/impl/ConceptService19Impl.java
===================================================================
--- api/src/main/java/org/openmrs/module/webservices/rest19ext/impl/ConceptService19Impl.java (revision 0)
+++ api/src/main/java/org/openmrs/module/webservices/rest19ext/impl/ConceptService19Impl.java (revision 0)
@@ -0,0 +1,48 @@
+package org.openmrs.module.webservices.rest19ext.impl;
+
+import java.util.List;
+
+import org.openmrs.Concept;
+import org.openmrs.ConceptMapType;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptReferenceTermMap;
+import org.openmrs.api.context.Context;
+import org.openmrs.api.db.DAOException;
+import org.openmrs.api.impl.ConceptServiceImpl;
+import org.openmrs.module.webservices.rest19ext.db.Concept19DAO;
+
+public class ConceptService19Impl extends ConceptServiceImpl {
+
+ Concept19DAO concept19DAO = null;
+
+ public Concept19DAO getConcept19DAO() {
+ return concept19DAO;
+ }
+
+ public void setConcept19DAO(Concept19DAO concept19DAO) {
+ this.concept19DAO = concept19DAO;
+ }
+
+ public List getConceptsBySource(String source, String term, String maptype, boolean includeRetired) {
+ ConceptMapType m = Context.getConceptService().getConceptMapTypeByName(maptype);
+ if (m == null)
+ m = Context.getConceptService().getConceptMapTypeByUuid(maptype);
+ Integer i = null;
+ if (m != null)
+ i = m.getId();
+
+ return concept19DAO.getConceptsByMapping(term, source, i, includeRetired);
+ }
+
+ public ConceptReferenceTermMap getConceptReferenceTermMap(Integer conceptReferenceTermMapId) throws DAOException {
+ return concept19DAO.getConceptReferenceTermMap(conceptReferenceTermMapId);
+ }
+
+ public ConceptReferenceTermMap getConceptReferenceTermMapByUuid(String uuid) throws DAOException {
+ return concept19DAO.getConceptReferenceTermMapByUuid(uuid);
+ }
+
+ public List getConceptReferenceTermCrossmaps(ConceptReferenceTerm crt) {
+ return concept19DAO.getConceptReferenceTermCrossmaps(crt);
+ }
+}
Index: omod/src/test/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/Concept19ControllerTest.java
===================================================================
--- omod/src/test/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/Concept19ControllerTest.java (revision 0)
+++ omod/src/test/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/Concept19ControllerTest.java (revision 0)
@@ -0,0 +1,170 @@
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openmrs.Concept;
+import org.openmrs.api.ConceptService;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.module.webservices.rest.test.Util;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.response.ConversionException;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudControllerTest;
+import org.openmrs.module.webservices.rest19ext.ConceptService19;
+import org.openmrs.module.webservices.rest19ext.test.Rest19ExtTestConstants;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.web.context.request.WebRequest;
+
+public class Concept19ControllerTest extends BaseCrudControllerTest {
+
+ @Before
+ public void before() throws Exception {
+ executeDataSet(Rest19ExtTestConstants.CONCEPT_MAPPING_DATASET);
+ }
+
+ /**
+ * @see ConceptController19#createConcept19(SimpleObject,WebRequest)
+ * @verifies create a new Concept
+ */
+ @Ignore
+ @Test
+ public void createConcept19_shouldCreateANewConcept() throws Exception {
+ int before = Context.getService(ConceptService19.class).getAllConcepts().size();
+ String json = "{ \"person\": \"da7f524f-27ce-4bb2-86d6-6d1d05312bd5\", \"identifier\":\"abc123ez\" }";
+ SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class);
+ Object newConcept19 = new ConceptController19().create(post, new MockHttpServletRequest(),
+ new MockHttpServletResponse());
+ Util.log("Created Concept", newConcept19);
+ Assert.assertEquals(before + 1, Context.getService(ConceptService19.class).getAllConcepts().size());
+ }
+
+ /**
+ * @see ConceptController19#getConcept19(Concept,WebRequest)
+ * @verifies get a default representation of a Concept
+ */
+ @Test
+ public void getConcept19_shouldGetADefaultRepresentationOfAConcept19() throws Exception {
+ Object result = new ConceptController19().retrieve(Rest19ExtTestConstants.CONCEPT_UUID_3,
+ new MockHttpServletRequest());
+ Assert.assertNotNull(result);
+ Util.log("Concept fetched (default)", result);
+ Assert.assertEquals(Rest19ExtTestConstants.PROVIDER_UUID, PropertyUtils.getProperty(result, "uuid"));
+ }
+
+ /**
+ * @see ConceptController19#getConcept19(String,WebRequest)
+ * @verifies get a full representation of a Concept
+ */
+ @Test
+ public void getConcept19_shouldGetAFullRepresentationOfAConcept19() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
+ Object result = new ConceptController19().retrieve(Rest19ExtTestConstants.CONCEPT_UUID_3, req);
+ Assert.assertNotNull(result);
+ Assert.assertEquals(Rest19ExtTestConstants.PROVIDER_UUID, PropertyUtils.getProperty(result, "uuid"));
+ Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
+ Util.log("Concept fetched (full)", result);
+ }
+
+ /**
+ * @see ConceptController19#updateConcept19(Concept,SimpleObject,WebRequest)
+ * @verifies should fail when changing a person property on a Concept
+ */
+ @Ignore
+ @Test(expected = ConversionException.class)
+ public void updateConcept19_shouldFailWhenChangingAPersonPropertyOnAConcept19() throws Exception {
+ Date now = new Date();
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ SimpleObject post = new ObjectMapper().readValue("{\"birthdate\":\"" + df.format(now) + "\"}", SimpleObject.class);
+ new ConceptController19().update(Rest19ExtTestConstants.PROVIDER_UUID, post, new MockHttpServletRequest(),
+ new MockHttpServletResponse());
+ }
+
+ /**
+ * @see ConceptController19#voidConcept19(Concept,String,WebRequest)
+ * @verifies void a Concept
+ */
+ @Test
+ public void voidConcept19_shouldRetireAConcept19() throws Exception {
+ Concept pat = Context.getService(ConceptService19.class).getConcept(4);
+ Assert.assertFalse(pat.isRetired());
+ new ConceptController19().delete(Rest19ExtTestConstants.CONCEPT_UUID_4, "unit test", new MockHttpServletRequest(),
+ new MockHttpServletResponse());
+ pat = Context.getService(ConceptService19.class).getConcept(4);
+ Assert.assertTrue(pat.isRetired());
+ Assert.assertEquals("unit test", pat.getRetireReason());
+ }
+
+ /**
+ * @see ConceptController19#findConcept19s(String,WebRequest,HttpServletResponse)
+ * @verifies return no results if there are no matching Concept19s
+ */
+ @Ignore
+ @Test
+ public void findConcept19s_shouldReturnNoResultsIfThereAreNoMatchingConcept19s() throws Exception {
+ List> results = (List>) new ConceptController19().search("zzzznobody", new MockHttpServletRequest(),
+ new MockHttpServletResponse()).get("results");
+ Assert.assertEquals(0, results.size());
+ }
+
+ /**
+ * @see ConceptController19#findConcept19s(String,WebRequest,HttpServletResponse)
+ * @verifies find matching Concept19s
+ */
+ @Ignore
+ @Test
+ public void findConcept19s_shouldFindMatchingConcept19s() throws Exception {
+ List> results = (List>) new ConceptController19().search("Hornblower", new MockHttpServletRequest(),
+ new MockHttpServletResponse()).get("results");
+ Assert.assertEquals(1, results.size());
+ Util.log("Found " + results.size() + " Concept(s)", results);
+ Object result = results.get(0);
+ Assert.assertEquals(Rest19ExtTestConstants.PROVIDER_UUID, PropertyUtils.getProperty(result, "uuid"));
+ Assert.assertNotNull(PropertyUtils.getProperty(result, "links"));
+ Assert.assertNotNull(PropertyUtils.getProperty(result, "display"));
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudControllerTest#getURI()
+ */
+ @Override
+ public String getURI() {
+ return "concept";
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudControllerTest#getUuid()
+ */
+ @Override
+ public String getUuid() {
+ return Rest19ExtTestConstants.CONCEPT_UUID_4;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudControllerTest#getAllCount()
+ */
+ @Override
+ public long getAllCount() {
+ return 2;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudControllerTest#shouldGetAll()
+ */
+ @Override
+ @Test
+ public void shouldGetAll() throws Exception {
+ super.shouldGetAll();
+ }
+}
Index: omod/src/test/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptSourceControllerTest.java
===================================================================
--- omod/src/test/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptSourceControllerTest.java (revision 0)
+++ omod/src/test/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptSourceControllerTest.java (revision 0)
@@ -0,0 +1,32 @@
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import org.junit.Before;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudControllerTest;
+import org.openmrs.module.webservices.rest19ext.test.Rest19ExtTestConstants;
+
+public class ConceptSourceControllerTest extends BaseCrudControllerTest {
+
+ @Before
+ public void before() throws Exception {
+ executeDataSet(Rest19ExtTestConstants.CONCEPT_MAPPING_DATASET);
+ }
+
+ @Override
+ public String getURI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getUuid() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public long getAllCount() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
Index: api/src/main/resources/moduleApplicationContext.xml
===================================================================
--- api/src/main/resources/moduleApplicationContext.xml (revision 0)
+++ api/src/main/resources/moduleApplicationContext.xml (revision 0)
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+ org.openmrs.module.webservices.rest19ext.ConceptService19
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: api/src/main/java/org/openmrs/module/webservices/rest19ext/db/Concept19DAO.java
===================================================================
--- api/src/main/java/org/openmrs/module/webservices/rest19ext/db/Concept19DAO.java (revision 0)
+++ api/src/main/java/org/openmrs/module/webservices/rest19ext/db/Concept19DAO.java (revision 0)
@@ -0,0 +1,21 @@
+package org.openmrs.module.webservices.rest19ext.db;
+
+import java.util.List;
+
+import org.openmrs.Concept;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptReferenceTermMap;
+import org.openmrs.api.db.ConceptDAO;
+import org.openmrs.api.db.DAOException;
+
+public interface Concept19DAO extends ConceptDAO {
+
+ public List getConceptsByMapping(String code, String sourceName, Integer maptype, boolean includeRetired);
+
+ public ConceptReferenceTermMap getConceptReferenceTermMap(Integer conceptReferenceTermMapId) throws DAOException;
+
+ public ConceptReferenceTermMap getConceptReferenceTermMapByUuid(String uuid) throws DAOException;
+
+ public List getConceptReferenceTermCrossmaps(ConceptReferenceTerm crt);
+
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptMapTypeController.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptMapTypeController.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptMapTypeController.java (revision 0)
@@ -0,0 +1,45 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.RestUtil;
+import org.openmrs.module.webservices.rest.web.annotation.WSDoc;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
+import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudController;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.EncounterResource;
+import org.openmrs.module.webservices.rest19ext.web.v1_0.resource.ConceptMapTypeResource;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * Controller for REST web service access to the ConceptMapType resource. Supports CRUD on the resource
+ * itself, and listing and addition of some subresources.
+ */
+@Controller
+@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/conceptmaptype")
+public class ConceptMapTypeController extends BaseCrudController {
+
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptMapTypeResource.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptMapTypeResource.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptMapTypeResource.java (revision 0)
@@ -0,0 +1,208 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License Version
+ * 1.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.resource;
+
+import java.util.List;
+import org.openmrs.ConceptMapType;
+import org.openmrs.annotation.Handler;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.annotation.Resource;
+import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.impl.AlreadyPaged;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
+import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+
+/**
+ * {@link Resource} for ConceptMapType, supporting standard CRUD operations
+ */
+@Resource("conceptmaptype")
+@Handler(supports = ConceptMapType.class, order = 100)
+public class ConceptMapTypeResource extends MetadataDelegatingCrudResource {
+
+ public ConceptMapTypeResource() {
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
+ */
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display", findMethod("getDisplayString"));
+ description.addProperty("description");
+ description.addProperty("retired");
+ description.addSelfLink();
+ description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
+ return description;
+ } else if (rep instanceof FullRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display", findMethod("getDisplayString"));
+ description.addProperty("description");
+ description.addProperty("hidden");
+ description.addProperty("retired");
+ description.addProperty("auditInfo", findMethod("getAuditInfo"));
+ description.addSelfLink();
+ return description;
+ }
+ return null;
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addRequiredProperty("uuid");
+ description.addRequiredProperty("name");
+ description.addProperty("description");
+ description.addProperty("hidden");
+ return description;
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getUpdatableProperties() {
+ return getCreatableProperties();
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate()
+ */
+ @Override
+ public ConceptMapType newDelegate() {
+ return new ConceptMapType();
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(java.lang.Object)
+ */
+ @Override
+ public ConceptMapType save(ConceptMapType conceptMapType) {
+ return Context.getConceptService().saveConceptMapType(conceptMapType);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptMapType getByUniqueId(String uuid) {
+ return Context.getConceptService().getConceptMapTypeByUuid(uuid);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void delete(ConceptMapType conceptMapType, String reason, RequestContext context) throws ResponseException {
+ if (conceptMapType.isRetired()) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getConceptService().retireConceptMapType(conceptMapType, reason);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void purge(ConceptMapType conceptMapType, RequestContext context) throws ResponseException {
+ if (conceptMapType == null) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getConceptService().purgeConceptMapType(conceptMapType);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(java.lang.String,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected AlreadyPaged doSearch(String query, RequestContext context) {
+ // TODO: Waiting on RESTWS-272
+ // List conceptMapTypes = Context.getConceptService().getConceptMapTypes(context.getIncludeAll(), true);
+ List conceptMapTypes = Context.getConceptService().getConceptMapTypes(false, true);
+ for (int i = conceptMapTypes.size() - 1; i == 0; i--) {
+ if (!(conceptMapTypes.get(i).getName().startsWith(query))
+ || (conceptMapTypes.get(i).getDescription().startsWith(query))) {
+ conceptMapTypes.remove(i);
+ }
+ }
+ if (context.getStartIndex() > 0) {
+ for (int i = context.getStartIndex() - 1; i == 0; i--) {
+ conceptMapTypes.remove(i);
+ }
+ }
+ if (conceptMapTypes.size() > context.getLimit()) {
+ for (int i = conceptMapTypes.size() - 1; i == context.getLimit(); i--) {
+ conceptMapTypes.remove(i);
+ }
+ }
+ return new AlreadyPaged(context, conceptMapTypes, false);
+
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(java.lang.String,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected NeedsPaging doGetAll(RequestContext context) throws ResponseException {
+ return new NeedsPaging(
+ // TODO: Waiting on RESTWS-272
+ // Context.getConceptService().getConceptMapTypes(context.getIncludeAll(), true), context);
+ Context.getConceptService().getConceptMapTypes(false, true), context);
+ }
+
+ /**
+ * @param conceptMapType
+ * @return identifier + name (for concise display purposes)
+ */
+ public String getDisplayString(ConceptMapType conceptMapType) {
+ if (conceptMapType.getName() == null) {
+ return "";
+ }
+ return conceptMapType.getName();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
+ */
+ @Override
+ public String getResourceVersion() {
+ return "1.9";
+ }
+}
Index: omod/src/test/java/org/openmrs/module/webservices/rest19ext/test/Rest19ExtTestConstants.java
===================================================================
--- omod/src/test/java/org/openmrs/module/webservices/rest19ext/test/Rest19ExtTestConstants.java (revision 28836)
+++ omod/src/test/java/org/openmrs/module/webservices/rest19ext/test/Rest19ExtTestConstants.java (working copy)
@@ -21,4 +21,29 @@
public final static String PROVIDER_ATTRIBUTE2_UUID = "3a2bdb18-6aan-kwf3-6e62-001e378eb67e";
public final static String TEST_DATASET = "customTestDataset.xml";
+
+ public final static String SOURCE_UUID_1 = "85f6a536-f03e-11e1-beed-0024e8c61285";
+
+ public final static String SOURCE_UUID_2 = "24498c81-f03f-11e1-beed-0024e8c61285";
+
+ public final static String REFTERM_UUID_1 = "1884342a-f040-11e1-beed-0024e8c61285";
+
+ public final static String REFTERM_UUID_2 = "b8724331-f040-11e1-beed-0024e8c61285";
+
+ public final static String REFTERM_UUID_3 = "d65f4848-f090-11e1-beed-0024e8c61285";
+
+ public final static String REFTERMMAP_UUID_1 = "72dbba88-f091-11e1-beed-0024e8c61285";
+
+ public final static String MAPTYPE_UUID_1 = "43ac5109-7d8c-11e1-909d-c80aa9edcf4e";
+
+ public final static String MAPTYPE_UUID_2 = "72dbba88-f091-11e1-beed-0024e8c61285";
+
+ public final static String CONCEPT_UUID_3 = "0cbe2ed3-cd5f-4f46-9459-26127c9265ab";
+
+ public final static String CONCEPT_UUID_4 = "89ca642a-dab6-4f20-b712-e12ca4fc6d36";
+
+ public final static String CONCEPTMAP_UUID_1 = "49df9740-f099-11e1-beed-0024e8c61285";
+
+ public final static String CONCEPT_MAPPING_DATASET = "conceptMappingTestDataset.xml";
+
}
Index: api/src/main/java/org/openmrs/module/webservices/rest19ext/ConceptService19.java
===================================================================
--- api/src/main/java/org/openmrs/module/webservices/rest19ext/ConceptService19.java (revision 0)
+++ api/src/main/java/org/openmrs/module/webservices/rest19ext/ConceptService19.java (revision 0)
@@ -0,0 +1,36 @@
+package org.openmrs.module.webservices.rest19ext;
+
+import java.util.List;
+
+import org.openmrs.Concept;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptReferenceTermMap;
+import org.openmrs.annotation.Authorized;
+import org.openmrs.api.ConceptService;
+import org.openmrs.api.context.Context;
+import org.openmrs.util.PrivilegeConstants;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public interface ConceptService19 extends ConceptService {
+
+ @Transactional(readOnly = true)
+ @Authorized(PrivilegeConstants.VIEW_CONCEPTS)
+ public List getConceptsBySource(String source, String term, String maptype, boolean includeRetired);
+
+ @Transactional(readOnly = true)
+ @Authorized(PrivilegeConstants.VIEW_CONCEPTS)
+ public List getConceptsByRefTerm(String query, String maptype, boolean includeRetired);
+
+ @Transactional(readOnly = true)
+ @Authorized(PrivilegeConstants.VIEW_CONCEPTS)
+ public ConceptReferenceTermMap getConceptReferenceTermMap(Integer conceptReferenceTermMapId);
+
+ @Transactional(readOnly = true)
+ @Authorized(PrivilegeConstants.VIEW_CONCEPTS)
+ public ConceptReferenceTermMap getConceptReferenceTermMapByUuid(String uuid);
+
+ @Transactional(readOnly = true)
+ @Authorized(PrivilegeConstants.VIEW_CONCEPTS)
+ public List getConceptReferenceTermCrossmaps(ConceptReferenceTerm crt);
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptReferenceTermResource.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptReferenceTermResource.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptReferenceTermResource.java (revision 0)
@@ -0,0 +1,265 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License Version
+ * 1.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.resource;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.openmrs.Concept;
+import org.openmrs.ConceptAnswer;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptReferenceTermMap;
+import org.openmrs.ConceptSource;
+import org.openmrs.Drug;
+import org.openmrs.annotation.Handler;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
+import org.openmrs.module.webservices.rest.web.annotation.PropertySetter;
+import org.openmrs.module.webservices.rest.web.annotation.Resource;
+import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.impl.AlreadyPaged;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
+import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest19ext.ConceptService19;
+
+/**
+ * {@link Resource} for ConceptReferenceTerm, supporting standard CRUD operations
+ */
+@Resource("conceptreferenceterm")
+@Handler(supports = ConceptReferenceTerm.class, order = 0)
+public class ConceptReferenceTermResource extends MetadataDelegatingCrudResource {
+
+ public ConceptReferenceTermResource() {
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
+ */
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("conceptSource", Representation.REF);
+ description.addProperty("name");
+ description.addProperty("code");
+ description.addProperty("conceptMaps", Representation.REF);
+ description.addProperty("retired");
+ description.addSelfLink();
+ description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
+ return description;
+ } else if (rep instanceof FullRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("conceptSource", Representation.DEFAULT);
+ description.addProperty("name");
+ description.addProperty("code");
+ description.addProperty("version");
+ description.addProperty("conceptMaps", Representation.FULL);
+ description.addProperty("conceptReferenceTermMaps", Representation.FULL);
+ description.addProperty("conceptReferenceTermCrossmaps", Representation.FULL);
+ description.addProperty("retired");
+ description.addProperty("auditInfo", findMethod("getAuditInfo"));
+ description.addSelfLink();
+ return description;
+ }
+ return null;
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("conceptSource");
+ description.addProperty("name");
+ description.addProperty("code");
+ description.addProperty("version");
+ description.addProperty("conceptMaps");
+ description.addProperty("conceptReferenceTermMaps");
+ description.addProperty("retired");
+ return description;
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getUpdatableProperties() {
+ return getCreatableProperties();
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate()
+ */
+ @Override
+ public ConceptReferenceTerm newDelegate() {
+ return new ConceptReferenceTerm();
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(java.lang.Object)
+ */
+ @Override
+ public ConceptReferenceTerm save(ConceptReferenceTerm conceptReferenceTerm) {
+ return Context.getConceptService().saveConceptReferenceTerm(conceptReferenceTerm);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptReferenceTerm getByUniqueId(String uuid) {
+ return Context.getConceptService().getConceptReferenceTermByUuid(uuid);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void delete(ConceptReferenceTerm conceptReferenceTerm, String reason, RequestContext context)
+ throws ResponseException {
+ if (conceptReferenceTerm.isRetired()) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getConceptService().retireConceptReferenceTerm(conceptReferenceTerm, reason);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void purge(ConceptReferenceTerm conceptReferenceTerm, RequestContext context) throws ResponseException {
+ if (conceptReferenceTerm == null) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getConceptService().purgeConceptReferenceTerm(conceptReferenceTerm);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(java.lang.String,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected AlreadyPaged doSearch(String query, RequestContext context) {
+ List terms = null;
+ String s = (String) context.getRequest().getParameterMap().get("source");
+ // if there is a source parameter, this is a search by source, else by code/name (normal q search)
+ // if there is both a q and a source param, query may contain the q, so use s instead
+ if ((s == null) || (s.isEmpty())) {
+ // terms = Context.getConceptService().getConceptReferenceTerms(query, (ConceptSource) null,
+ // context.getStartIndex(), context.getLimit(), context.getIncludeAll());
+ // TODO: Waiting on RESTWS-272
+ terms = Context.getConceptService().getConceptReferenceTerms(query, (ConceptSource) null,
+ context.getStartIndex(), context.getLimit(), true);
+ } else {
+ ConceptSource cs = Context.getConceptService().getConceptSourceByUuid(s);
+ if (cs != null)
+ // terms = Context.getConceptService().getConceptReferenceTerms(null, cs, context.getStartIndex(),
+ // context.getLimit(), context.getIncludeAll());
+ // TODO: Waiting on RESTWS-272
+ terms = Context.getConceptService().getConceptReferenceTerms(null, cs, context.getStartIndex(),
+ context.getLimit(), true);
+ }
+ return new AlreadyPaged(context, terms, false);
+ }
+
+ /**
+ * @see
+ * org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(java.lang.String,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected NeedsPaging doGetAll(RequestContext context) throws ResponseException {
+ return new NeedsPaging(Context.getConceptService().getAllConceptReferenceTerms(), context);
+ }
+
+ /**
+ * @param conceptReferenceTerm
+ * @return identifier + name (for concise display purposes)
+ */
+ @Override
+ public String getDisplayString(ConceptReferenceTerm conceptReferenceTerm) {
+ StringBuilder s = new StringBuilder();
+ if (conceptReferenceTerm.getConceptSource() != null) {
+ s.append(conceptReferenceTerm.getConceptSource().getName());
+ s.append(":");
+ }
+ if (conceptReferenceTerm.getCode() != null) {
+ s.append(conceptReferenceTerm.getCode());
+ }
+ if (conceptReferenceTerm.getVersion() != null) {
+ s.append(" (");
+ s.append(conceptReferenceTerm.getVersion());
+ s.append(")");
+ }
+ return s.toString();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
+ */
+ @Override
+ public String getResourceVersion() {
+ return "1.9";
+ }
+
+ /**
+ * @param instance
+ * @return the list of Concepts or Drugs
+ */
+ @PropertyGetter("conceptReferenceTermCrossmaps")
+ public static Object getCrossmaps(ConceptReferenceTerm instance) {
+ List terms = new ArrayList();
+ if (instance != null)
+ terms = Context.getService(ConceptService19.class).getConceptReferenceTermCrossmaps(instance);
+ return terms;
+ }
+
+ /**
+ * @param instance
+ * @param crossmapUuids the list of ConceptReferenceMaps
+ * @throws ResourceDoesNotSupportOperationException
+ */
+ @PropertySetter("conceptReferenceTermCrossmaps")
+ public static void setCrossmaps(Concept instance, List crossmapUuids)
+ throws ResourceDoesNotSupportOperationException {
+
+ throw new ResourceDoesNotSupportOperationException("ReferenceTermMaps may not be set via crossmaps");
+ }
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptReferenceTermController.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptReferenceTermController.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptReferenceTermController.java (revision 0)
@@ -0,0 +1,86 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.RestUtil;
+import org.openmrs.module.webservices.rest.web.annotation.WSDoc;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
+import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudController;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.EncounterResource;
+import org.openmrs.module.webservices.rest19ext.web.v1_0.resource.ConceptReferenceTermResource;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * Controller for REST web service access to the ConceptReferenceTerm resource. Supports CRUD on the resource
+ * itself, and listing and addition of some subresources.
+ */
+@Controller
+@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/conceptreferenceterm")
+public class ConceptReferenceTermController extends BaseCrudController {
+
+ /**
+ * Fetch terms for a given concept source
+ * @param ConceptSource uuid
+ * @param request
+ * @param response
+ * @return terms for a given concept source
+ * @throws ResponseException
+ */
+ @RequestMapping(method = RequestMethod.GET, params = "source")
+ @WSDoc("Fetch all non-retired/all terms for a concept source with the given uuid")
+ @ResponseBody
+ public SimpleObject searchByConceptSource(@RequestParam("source") String source, HttpServletRequest request,
+ HttpServletResponse response) throws ResponseException {
+ Searchable searchable;
+ try {
+ searchable = (Searchable) getResource();
+ }
+ catch (ClassCastException ex) {
+ throw new ResourceDoesNotSupportOperationException(getResource().getClass().getSimpleName()
+ + " is not Searchable", null);
+ }
+ RequestContext context = RestUtil.getRequestContext(request, Representation.REF);
+ return searchable.search(source, context);
+ }
+
+ @RequestMapping(value = "/{uuid}", method = RequestMethod.GET, params = "termmap")
+ @WSDoc("Fetch mapped terms for a term with the given map type, use * for any map type")
+ @ResponseBody
+ public SimpleObject getConceptReferenceTermMappedTerms(@RequestParam("termmap") String termmap,
+ HttpServletRequest request, HttpServletResponse response) throws ResponseException {
+ Searchable searchable;
+ try {
+ searchable = (Searchable) getResource();
+ }
+ catch (ClassCastException ex) {
+ throw new ResourceDoesNotSupportOperationException(getResource().getClass().getSimpleName()
+ + " is not Searchable", null);
+ }
+ RequestContext context = RestUtil.getRequestContext(request, Representation.REF);
+ return searchable.search(request.getParameter("uuid"), context);
+ }
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptController19.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptController19.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/controller/ConceptController19.java (revision 0)
@@ -0,0 +1,41 @@
+package org.openmrs.module.webservices.rest19ext.web.v1_0.controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestUtil;
+import org.openmrs.module.webservices.rest.web.annotation.WSDoc;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.Searchable;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.ConceptController;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+public class ConceptController19 extends ConceptController {
+
+ @RequestMapping(method = RequestMethod.GET, params = { "q", "source" })
+ @WSDoc("?q=term code/name or source uuid/name:term code/name, ?source is source uuid/name")
+ @ResponseBody
+ public SimpleObject getConceptForSource(@RequestParam("q") String query, HttpServletRequest request,
+ HttpServletResponse response) throws ResponseException {
+ Searchable searchable = (Searchable) getResource();
+ RequestContext context = RestUtil.getRequestContext(request, Representation.REF);
+ return searchable.search(query, context);
+ }
+
+ @RequestMapping(method = RequestMethod.GET, params = { "q", "maptype" })
+ @WSDoc("?q=term code/name (param required, value optional), ?maptype specifies map type by uuid or name")
+ @ResponseBody
+ public SimpleObject getConceptForMapType(@RequestParam("q") String query, HttpServletRequest request,
+ HttpServletResponse response) throws ResponseException {
+ Searchable searchable = (Searchable) getResource();
+ RequestContext context = RestUtil.getRequestContext(request, Representation.REF);
+ return searchable.search(query, context);
+ }
+
+}
Index: omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptMapResource.java
===================================================================
--- omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptMapResource.java (revision 0)
+++ omod/src/main/java/org/openmrs/module/webservices/rest19ext/web/v1_0/resource/ConceptMapResource.java (revision 0)
@@ -0,0 +1,210 @@
+/**
+ * The contents of this file are subject to the OpenMRS Public License
+ * Version 1.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://license.openmrs.org
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * Copyright (C) OpenMRS, LLC. All Rights Reserved.
+ */
+package org.openmrs.module.webservices.rest19ext.web.v1_0.resource;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+
+import org.openmrs.Concept;
+import org.openmrs.ConceptName;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptMap;
+import org.openmrs.ConceptMapType;
+import org.openmrs.ConceptSource;
+import org.openmrs.LocationTag;
+import org.openmrs.ProviderAttribute;
+import org.openmrs.annotation.Handler;
+import org.openmrs.api.ConceptService;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+import org.openmrs.module.webservices.rest.web.RestConstants;
+import org.openmrs.module.webservices.rest.web.annotation.PropertySetter;
+import org.openmrs.module.webservices.rest.web.annotation.Resource;
+import org.openmrs.module.webservices.rest.web.annotation.SubResource;
+import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.ConceptResource;
+
+/**
+ * {@link Resource} for ConceptMaps, supporting standard CRUD operations
+ */
+@SubResource(parent = ConceptResource.class, path = "conceptmap")
+@Handler(supports = ConceptMap.class, order = 0)
+public class ConceptMapResource extends DelegatingSubResource {
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
+ */
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("conceptReferenceTerm", Representation.REF);
+ description.addProperty("mapType", Representation.REF);
+ description.addProperty("concept", Representation.REF);
+ description.addSelfLink();
+ description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
+ return description;
+ } else if (rep instanceof FullRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("conceptReferenceTerm", Representation.FULL);
+ description.addProperty("mapType", Representation.REF);
+ description.addProperty("concept", Representation.FULL);
+ description.addProperty("auditInfo", findMethod("getAuditInfo"));
+ description.addSelfLink();
+ return description;
+ }
+ return null;
+ }
+
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addRequiredProperty("conceptReferenceTerm");
+ description.addRequiredProperty("mapType");
+ description.addRequiredProperty("concept");
+ return description;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getUpdatableProperties() {
+ return getCreatableProperties();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object)
+ */
+ @Override
+ public Concept getParent(ConceptMap instance) {
+ return instance.getConcept();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate()
+ */
+ @Override
+ public ConceptMap newDelegate() {
+ return new ConceptMap();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptMap getByUniqueId(String uniqueId) {
+ return Context.getConceptService().getConceptMapByUuid(uniqueId);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object)
+ */
+ @Override
+ public ConceptMap save(ConceptMap delegate) {
+ if (delegate == null)
+ return null;
+ Concept parent = delegate.getConcept();
+ ConceptMap found = null;
+ Collection cm = parent.getConceptMappings();
+ for (ConceptMap m : cm)
+ if (m.equals(delegate)) {
+ found = m;
+ break;
+ }
+ if (found != null)
+ parent.removeConceptMapping(found);
+ parent.addConceptMapping(delegate);
+ Context.getConceptService().saveConcept(parent);
+ return delegate;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected void delete(ConceptMap delegate, String reason, RequestContext context) throws ResponseException {
+ this.purge(delegate, context);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void purge(ConceptMap delegate, RequestContext context) throws ResponseException {
+ if (delegate == null)
+ return;
+ try {
+ delegate.getConcept().removeConceptMapping(delegate);
+ }
+ catch (Exception e) {}
+ ;
+ Concept parent = delegate.getConcept();
+ Context.getConceptService().saveConcept(parent);
+ return;
+ }
+
+ /**
+ * Gets the display string.
+ *
+ * @param cm the concept map.
+ * @return crt.name:c.name (non-default maptype)
+ */
+ public String getDisplayString(ConceptMap cm) {
+ ConceptService cs = Context.getConceptService();
+ StringBuilder s = new StringBuilder();
+ if (cm.getConceptReferenceTerm() != null)
+ s.append(cm.getConceptReferenceTerm().getName());
+ s.append(":");
+ if (cm.getConcept() != null) {
+ s.append(cs.getConceptName(cm.getConcept().getConceptId()).getName());
+ }
+ if (cm.getConceptMapType() != null)
+ if (!cm.getConceptMapType().equals(Context.getConceptService().getDefaultConceptMapType()))
+ s.append(" (" + cm.getConceptMapType().getName() + ")");
+ return s.toString();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
+ */
+ @Override
+ public String getResourceVersion() {
+ return "1.9";
+ }
+
+ @Override
+ public void setParent(ConceptMap instance, Concept parent) {
+ instance.setConcept(parent);
+ }
+
+ @Override
+ public PageableResult doGetAll(Concept parent, RequestContext context) throws ResponseException {
+ return new NeedsPaging((List) parent.getConceptMappings(), context);
+ }
+
+}