/** * 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())); }
/** * @verifies return location by tag uuid * @see LocationSearchHandler#getSearchConfig() */ @Test public void getSearchConfig_shouldReturnLocationByTagUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("tag", "0940c6d4-47ed-11df-bc8b-001e378eb67e"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(2, hits.size()); List<Location> locations = service.getAllLocations(); Assert.assertEquals(service.getLocation(1).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); Assert.assertEquals(service.getLocation(2).getUuid(), PropertyUtils.getProperty(hits.get(1), "uuid")); }
@Test public void shouldEditAPatientIdentifier() throws Exception { final String newLocationUuid = RestTestConstants1_8.LOCATION_UUID; PatientIdentifier patientIdentifierType = service.getPatientIdentifierByUuid(getUuid()); assertFalse(newLocationUuid.equals(patientIdentifierType.getLocation().getUuid())); SimpleObject patientIdentifier = new SimpleObject(); patientIdentifier.add("location", newLocationUuid); String json = new ObjectMapper().writeValueAsString(patientIdentifier); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); assertEquals(newLocationUuid, patientIdentifierType.getLocation().getUuid()); }
@Test public void shouldSearchAndReturnAListOfLocationsMatchingTheQueryString() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("q", "xan"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(1, hits.size()); Assert.assertEquals(service.getLocation(2).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); }
@Test public void shouldSearchAndReturnListOfLocationsWithSpecifiedTag() throws Exception { executeDataSet(LOCATION_TAG_INITIAL_XML); MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("tag", "001e503a-47ed-11df-bc8b-001e378eb67e"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(1, hits.size()); // should ignore retired location? Assert.assertEquals(service.getLocation(1).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); }
/** * @verifies return location by tag name * @see LocationSearchHandler#getSearchConfig() */ @Test public void getSearchConfig_shouldReturnLocationByTagName() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("tag", "General Hospital"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(1, hits.size()); Assert.assertEquals(service.getLocation(1).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); } }
@Test public void shouldSearchAndReturnListOfLocationsWithSpecifiedTagAndQueryString() throws Exception { executeDataSet(LOCATION_TAG_INITIAL_XML); MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("tag", "0940c6d4-47ed-11df-bc8b-001e378eb67e"); req.addParameter("q", "Xan"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(1, hits.size()); // should ignore retired location? Assert.assertEquals(service.getLocation(2).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); }
@Test public void shouldGetALocationByName() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/Xanadu"); SimpleObject result = deserialize(handle(req)); Location location = service.getLocation("Xanadu"); Assert.assertNotNull(result); Assert.assertEquals(location.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(location.getName(), PropertyUtils.getProperty(result, "name")); }
@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 testLocation() throws Exception { VelocityFunctions functions = setupFunctionsForPatient(7); String locationIdIdentifier = new Integer(2).toString(); Assert.assertNotNull(functions.location(locationIdIdentifier)); Assert.assertEquals(locationIdIdentifier, functions.location(locationIdIdentifier).getId().toString()); String locationUuidIdentifier = "8d6c993e-c2cc-11de-8d13-0010c6dffd0f"; Assert.assertNotNull(functions.location(locationUuidIdentifier)); Assert.assertEquals(locationUuidIdentifier, functions.location(locationUuidIdentifier).getUuid()); String locationNameIdentifier = "Xanadu"; Assert.assertNotNull(functions.location(locationNameIdentifier)); Assert.assertEquals(locationNameIdentifier, functions.location(locationNameIdentifier).getName()); } }
@Test public void shouldPurgeARetiredLocation() throws Exception { Location location = service.getLocation(3); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + location.getUuid()); req.addParameter("purge", "true"); handle(req); Assert.assertNull(service.getLocation(3)); }
@Test public void setValue_shouldSetProperAttributableIdIfFound() { PersonAttributeType type = new PersonAttributeType(); type.setFormat("org.openmrs.Location"); type.setName("Second Home"); type.setDescription("Testing Attributable domain objects"); type.setSortWeight(5.5); type.setSearchable(false); type = personService.savePersonAttributeType(type); //Get the first location in from the list Location location = locationService.getAllLocations().get(0); PersonAttribute attribute = new PersonAttribute(type, null); attribute.setAttributeType(type); Assert.assertNull(attribute.getValue()); resource.setValue(attribute, location.getUuid()); Assert.assertEquals(location.getUuid(), attribute.getValue()); }
@Test public void convert_shouldConvertASimpleObjectThatIncludesAUuid() { final String uuid = "91f6c840-da25-11e8-ae91-0242ac110002"; SimpleObject so = new SimpleObject(); so.add("uuid", uuid); so.add("name", "Location name"); so.add("description", "Location description"); DelegatingCrudResource<Location> resource = new LocationResource1_8(); Location location = resource.convert(so); Assert.assertEquals(uuid, location.getUuid()); }
Assert.assertFalse(newLocationUuid.equalsIgnoreCase(visit.getLocation().getUuid())); Assert.assertFalse(newIndicationConceptUuid.equalsIgnoreCase(visit.getIndication().getUuid())); Assert.assertFalse(newStartDatetime.equals(visit.getStartDatetime())); Assert.assertNotNull(updated); Assert.assertEquals(newVisitTypeUuid, updated.getVisitType().getUuid()); Assert.assertEquals(newLocationUuid, updated.getLocation().getUuid()); Assert.assertEquals(newIndicationConceptUuid, updated.getIndication().getUuid()); Assert.assertEquals(newStartDatetime, updated.getStartDatetime());
@Test public void shouldRetireALocation() throws Exception { Location location = service.getLocation(2); Assert.assertFalse(location.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + location.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "random reason"); handle(req); Location retiredLocation = service.getLocation(2); Assert.assertTrue(retiredLocation.isRetired()); Assert.assertEquals("random reason", retiredLocation.getRetireReason()); }
Assert.assertTrue(rep.keySet().contains("value")); rep = (SimpleObject) rep.get("value"); Assert.assertEquals("location", location.getUuid(), rep.get("uuid")); clearAndSetValue(obs, ObsType.TEXT, location.getUuid()); obs.setComment("org.openmrs.Location"); rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); Assert.assertTrue(rep.keySet().contains("value")); rep = (SimpleObject) rep.get("value"); Assert.assertEquals("location", location.getUuid(), rep.get("uuid"));
TestUtil.assertFuzzyContains("<encounterLocation default=\"9356400c-a5a2-4532-8f2b-2361b3446eb8\" order=\"" + location1.getUuid() + ",9356400c-a5a2-4532-8f2b-2361b3446eb8,Never Never Land\"",form.getXmlData()); TestUtil.assertFuzzyContains("<encounterProvider role=\"Provider\" default=\"c04ee3c8-b68f-43cc-bff3-5a831ee7225f\"", form.getXmlData());