/** * @see org.openmrs.customdatatype.SerializingCustomDatatype#deserialize(String) * @override */ @Override public Location deserialize(String uuid) { if (StringUtils.isBlank(uuid)) { return null; } return Context.getLocationService().getLocationByUuid(uuid); } }
@Override protected Location getObjectByUuid(String uuid) { return Context.getLocationService().getLocationByUuid(uuid); } }
/** * @see LocationService#getLocationByUuid(String) */ @Test public void getLocationByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(Context.getLocationService().getLocationByUuid("some invalid uuid")); }
/** * @see LocationService#getLocationByUuid(String) */ @Test public void getLocationByUuid_shouldFindObjectGivenValidUuid() { String uuid = "f08ba64b-ea57-4a41-b33c-9dfc59b0c60a"; Location location = Context.getLocationService().getLocationByUuid(uuid); Assert.assertEquals(1, (int) location.getLocationId()); }
/** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getLocationByUuid(RestTestConstants1_9.LOCATION_UUID).getActiveAttributes().size(); }
@Override public PageableResult search(String parentUuid, RequestContext context) throws ResponseException { String attributeType = context.getParameter("attributeType"); if (StringUtils.isBlank(attributeType) || StringUtils.isBlank(parentUuid)) { return new EmptySearchResult(); } Location parentLocation = Context.getLocationService().getLocationByUuid(parentUuid); List<LocationAttribute> results = new ArrayList<LocationAttribute>(); for (LocationAttribute activeAttribute : parentLocation.getActiveAttributes()) { if (activeAttribute.getAttributeType().getUuid().equals(attributeType)) { results.add(activeAttribute); } } return new AlreadyPaged<LocationAttribute>(context, results, false); } }
/** * Fetches a location by uuid, if no match is found, it tries to look up one with a matching * name with the assumption that the passed parameter is a location name * * @see DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public Location getByUniqueId(String uuid) { Location location = Context.getLocationService().getLocationByUuid(uuid); //We assume the caller was fetching by name if (location == null) location = Context.getLocationService().getLocation(uuid); return location; }
/** * Sets the location for a patient identifier. * * @param instance * @param location * @throws org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException */ @PropertySetter("location") public void setLocation(PatientIdentifier instance, Location location) { instance.setLocation(Context.getLocationService().getLocationByUuid(location.getUuid())); }
@Override public Location newObject() { return Context.getLocationService().getLocationByUuid(getUuidProperty()); }
@Override public Location newObject() { return Context.getLocationService().getLocationByUuid(getUuidProperty()); }
@Test public void shouldAddAttributeToLocation() throws Exception { int before = service.getLocationByUuid(RestTestConstants1_9.LOCATION_UUID).getAttributes().size(); String json = "{\"attributeType\":\"9516cc50-6f9f-132r-5433-001e378eb67f\", \"value\":\"2012-05-05\"}"; handle(newPostRequest(getURI(), json)); int after = service.getLocationByUuid(RestTestConstants1_9.LOCATION_UUID).getAttributes().size(); Assert.assertEquals(before + 1, after); }
@Test public void shouldOverwriteAListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location); String json = "{ \"childLocations\": [] }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Location updatedLocation = service.getLocationByUuid(getUuid()); Assert.assertNotNull(updatedLocation); Assert.assertTrue(updatedLocation.getChildLocations().isEmpty()); }
Assert.assertFalse(dependencies.contains(Context.getLocationService().getLocationByUuid( "dc5c1fcc-0459-4201-bf70-0b90535ba362"))); Assert.assertFalse(dependencies.contains(Context.getLocationService().getLocationByUuid( "9356400c-a5a2-4532-8f2b-2361b3446eb8")));
@Test public void shouldIncludeTheListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); Assert.assertEquals(0, location.getChildLocations().size()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location); MockHttpServletRequest httpReq = request(RequestMethod.GET, getURI() + "/" + getUuid()); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(httpReq)); Assert.assertEquals(1, ((Collection) PropertyUtils.getProperty(result, "childLocations")).size()); }
@Test public void shouldGetALocationByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); Location location = service.getLocationByUuid(getUuid()); Assert.assertNotNull(result); Assert.assertEquals(location.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(location.getName(), PropertyUtils.getProperty(result, "name")); }
@Test public void shouldEditALocation() throws Exception { final String editedName = "Xanadu edited"; String json = "{ \"name\":\"" + editedName + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Location editedLocation = service.getLocationByUuid(getUuid()); Assert.assertNotNull(editedLocation); Assert.assertEquals(editedName, editedLocation.getName()); }
@Test public void shouldUnretireALocation() throws Exception { Location location = service.getLocation(3); Assert.assertTrue(location.isRetired()); String json = "{ \"retired\": false }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Location updatedLocation = service.getLocationByUuid(getUuid()); Assert.assertTrue(!updatedLocation.isRetired()); }
@Test public void shouldIncludeTheParentLocation() throws Exception { Location location = service.getLocationByUuid(getUuid()); location.setParentLocation(service.getLocation(2)); service.saveLocation(location); MockHttpServletRequest httpReq = request(RequestMethod.GET, getURI() + "/" + getUuid()); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(httpReq)); Assert.assertNotNull(result); Assert.assertNotNull(PropertyUtils.getProperty(result, "parentLocation")); }
/** * See RESTWS-418 - Allow REST POST requests to accept un-updatable properties if they haven't * been updated */ @Test public void shouldAllowYouToPostANonUpdatablePropertyWithAnUnchangedValue() throws Exception { MockHttpServletRequest get = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject location = deserialize(handle(get)); location.put("name", "New York"); MockHttpServletRequest post = newPostRequest(getURI() + "/" + getUuid(), location); handle(post); Location updatedLocation = service.getLocationByUuid(getUuid()); assertThat(updatedLocation.getName(), is("New York")); }
private void setupMappings() { MetadataSource metadataSource = new MetadataSource(); metadataSource.setName("source"); metadataSource.setDateCreated(new Date()); metadataSource.setRetired(false); metadataSource.setId(1); metadataSource = Context.getService(MetadataMappingService.class).saveMetadataSource(metadataSource); MetadataTermMapping metadataTermMapping1 = new MetadataTermMapping(metadataSource, "DataClerk", Context.getUserService().getRole("Data Clerk")); metadataTermMapping1.setName("mapping1"); Context.getService(MetadataMappingService.class).saveMetadataTermMapping(metadataTermMapping1); MetadataTermMapping metadataTermMapping2 = new MetadataTermMapping(metadataSource, "ROLE", Context.getUserService().getRole("Provider")); metadataTermMapping2.setName("mapping2"); Context.getService(MetadataMappingService.class).saveMetadataTermMapping(metadataTermMapping2); MetadataTermMapping metadataTermMapping3 = new MetadataTermMapping(metadataSource, "Location", Context.getLocationService().getLocationByUuid("9356400c-a5a2-4532-8f2b-2361b3446eb8")); metadataTermMapping3.setName("mapping3"); Context.getService(MetadataMappingService.class).saveMetadataTermMapping(metadataTermMapping3); MetadataTermMapping metadataTermMapping4 = new MetadataTermMapping(metadataSource, "MDR-TB PROGRAM", Context.getProgramWorkflowService().getProgramByName("MDR-TB PROGRAM")); metadataTermMapping4.setName("mapping4"); Context.getService(MetadataMappingService.class).saveMetadataTermMapping(metadataTermMapping4); MetadataTermMapping metadataTermMapping5 = new MetadataTermMapping(metadataSource, "1", Context.getPatientService().getPatientIdentifierType(1)); metadataTermMapping5.setName("mapping5"); Context.getService(MetadataMappingService.class).saveMetadataTermMapping(metadataTermMapping5); Context.flushSession(); }