Uploaded image for project: 'Webservices REST Module'
  1. Webservices REST Module
  2. RESTWS-707

RESTWS-707 Fix bug in encounterRole endpoint

    XMLWordPrintable

    Details

    • Complexity:
      Low
    • Sprint:
      Order Entry UI Sprint 4

      Description

      There seem to be a bug in the encounterRole endpoint which cause the API to return an empty set [ ] when a search query is provided.

      /ws/rest/v1/encounterrole?q=Clinician

      Please look into the images below for more context

      Dev Notes:
      Create an EncounterRoleResource1_11 class in https://github.com/openmrs/openmrs-module-webservices.rest/tree/master/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11

      Which looks like

      /**
       * This Source Code Form is subject to the terms of the Mozilla Public License,
       * v. 2.0. If a copy of the MPL was not distributed with this file, You can
       * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
       * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
       *
       * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
       * graphic logo is a trademark of OpenMRS Inc.
       */
      package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11;
      
      import org.openmrs.EncounterRole;
      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.resource.impl.NeedsPaging;
      import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.EncounterRoleResource1_9;
      
      /**
       * {@link Resource} for {@link EncounterRole}, supporting standard CRUD operations
       */
      @Resource(name = RestConstants.VERSION_1 + "/encounterrole", supportedClass = EncounterRole.class, supportedOpenmrsVersions = {
              "1.11.*", "1.12.*", "2.0.*", "2.1.*", "2.2.*" })
      public class EncounterRoleResource1_11 extends EncounterRoleResource1_9 {
      	
      	/**
      	 * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext)
      	 */
      	@Override
      	protected NeedsPaging<EncounterRole> doSearch(RequestContext context) {
      		return new NeedsPaging<EncounterRole>(Context.getEncounterService().getEncounterRolesByName(
      		    context.getParameter("q")),
      		        context);
      	}
      }
      

      Remember to change the base class's supported openmrs versions to be only 1.9.* and 1.10.* here https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java#L29

      Also add a test class EncounterRoleController1_11Test in https://github.com/openmrs/openmrs-module-webservices.rest/tree/master/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_11
      Which looks like below:

      /**
       * This Source Code Form is subject to the terms of the Mozilla Public License,
       * v. 2.0. If a copy of the MPL was not distributed with this file, You can
       * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
       * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
       *
       * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
       * graphic logo is a trademark of OpenMRS Inc.
       */
      package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_11;
      
      import static org.junit.Assert.assertEquals;
      
      import org.apache.commons.beanutils.PropertyUtils;
      import org.junit.Test;
      import org.openmrs.EncounterRole;
      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.RestTestConstants1_9;
      import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest;
      import org.springframework.mock.web.MockHttpServletRequest;
      import org.springframework.web.bind.annotation.RequestMethod;
      
      public class EncounterRoleController1_11Test extends MainResourceControllerTest {
      
      	@Override
      	public String getURI() {
      		return "encounterrole";
      	}
      
      	@Override
      	public String getUuid() {
      		return RestTestConstants1_9.ENCOUNTER_ROLE_UUID;
      	}
      
      	@Override
      	public long getAllCount() {
      		return 1;
      	}
      	
      	@Test
      	public void shouldGetAnEncounterRoleByName() throws Exception {
      		final String ROLE_NAME = "Unknown";
      		
      		MockHttpServletRequest req = request(RequestMethod.GET, getURI());
      		req.setParameter("q", ROLE_NAME);
      		req.setParameter("v", "default");
      		SimpleObject result = deserialize(handle(req));
      		Object encounterRoleObject = Util.getResultsList(result).get(0);
      	
      		EncounterRole encounterRole = Context.getEncounterService().getEncounterRoleByName(ROLE_NAME);
      		assertEquals(encounterRole.getUuid(), PropertyUtils.getProperty(encounterRoleObject, "uuid"));
      		assertEquals(encounterRole.getName(), PropertyUtils.getProperty(encounterRoleObject, "name"));
      		assertEquals(encounterRole.getDescription(), PropertyUtils.getProperty(encounterRoleObject, "description"));
      	}
      }
      

        Gliffy Diagrams

          Attachments

          1. filter.png
            filter.png
            173 kB
          2. Screen Shot 2018-05-10 at 12.36.23 PM.png
            Screen Shot 2018-05-10 at 12.36.23 PM.png
            473 kB
          3. Screen Shot 2018-05-10 at 12.37.07 PM.png
            Screen Shot 2018-05-10 at 12.37.07 PM.png
            398 kB
          4. Screen Shot 2018-05-10 at 9.51.17 PM.png
            Screen Shot 2018-05-10 at 9.51.17 PM.png
            466 kB
          5. webservices.rest-2.23.0-SNAPSHOT.41b70a.omod
            5.64 MB

            Issue Links

              Activity

                People

                Assignee:
                larrystone Lanre Lawal
                Reporter:
                larrystone Lanre Lawal
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: