@Test
 public void testGetForPatientWithoutAllergiesSpecified() throws Exception {
   SimpleObject response =
       toSimpleObject(
           handle(request(RequestMethod.GET, "allergies/5946f880-b197-400b-9caa-a3c661d23041")));
   assertThat((String) response.get("status"), is(Allergies.UNKNOWN));
   assertThat(((List) response.get("allergies")).size(), is(0));
 }
  @Test
  public void shouldEditAConceptSource() throws Exception {
    final String newName = "updated name";
    SimpleObject conceptSource = new SimpleObject();
    conceptSource.add("name", newName);

    String json = new ObjectMapper().writeValueAsString(conceptSource);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid());
    req.setContent(json.getBytes());
    handle(req);
    Assert.assertEquals(newName, service.getConceptSourceByUuid(getUuid()).getName());
  }
  @Test
  public void shouldCreateAConceptSource() throws Exception {
    long originalCount = getAllCount();

    SimpleObject conceptSource = new SimpleObject();
    conceptSource.add("name", "test name");
    conceptSource.add("description", "test description");

    String json = new ObjectMapper().writeValueAsString(conceptSource);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI());
    req.setContent(json.getBytes());

    SimpleObject newConceptSource = deserialize(handle(req));

    Assert.assertNotNull(PropertyUtils.getProperty(newConceptSource, "uuid"));
    Assert.assertEquals(originalCount + 1, getAllCount());
  }
 @Test
 public void testGetForPatientWithAllergies() throws Exception {
   SimpleObject response =
       toSimpleObject(
           handle(request(RequestMethod.GET, "allergies/da7f524f-27ce-4bb2-86d6-6d1d05312bd5")));
   assertThat((String) response.get("status"), is(Allergies.SEE_LIST));
   List<SimpleObject> allergies = (List<SimpleObject>) response.get("allergies");
   assertThat(
       allergies,
       containsInAnyOrder(
           allergyMatcher(
               conceptService.getConcept(792),
               conceptService.getConcept(23),
               conceptService.getConcept(3),
               conceptService.getConcept(4)),
           allergyMatcher(
               conceptService.getConcept(5089),
               conceptService.getConcept(23),
               conceptService.getConcept(5),
               conceptService.getConcept(6)),
           allergyMatcher(conceptService.getConcept(5497), conceptService.getConcept(23)),
           allergyMatcher(conceptService.getConcept(88), conceptService.getConcept(23))));
 }
 /**
  * Gets a catalog of all available resources.
  *
  * @return
  * @throws Exception
  */
 @RequestMapping(method = RequestMethod.GET)
 @ResponseBody
 public Object getResourceCatalog(
     @RequestParam(value = "q", required = false) final String resourceName,
     HttpServletRequest request)
     throws Exception {
   List<ResourceDoc> resourceDocList = new ArrayList<ResourceDoc>();
   SimpleObject resourceCatalog = new SimpleObject();
   String prefix = RestConstants.URI_PREFIX;
   // strip the ending string '/rest/' because it will be added by ResourceDocCreator.create
   if (StringUtils.isNotBlank(prefix) && prefix.endsWith("/rest/"))
     prefix = prefix.substring(0, prefix.lastIndexOf("/rest/"));
   if (resourceName == null) {
     resourceDocList = ResourceDocCreator.create(prefix);
   } else {
     for (ResourceDoc resourceDoc : ResourceDocCreator.create(prefix)) {
       if (resourceDoc.getName().toLowerCase().contains(resourceName.toLowerCase())) {
         resourceDocList.add(resourceDoc);
       }
     }
   }
   resourceCatalog.put("catalog", resourceDocList);
   return new LinkedHashMap<String, Object>(resourceCatalog);
 }