@Test
  public void testCreateDuplicateIdFails() {
    String methodName = "testCreateDuplocateIdFailsText";

    Patient p = new Patient();
    p.addIdentifier().setSystem("urn:system").setValue(methodName);
    p.setId("Patient/" + methodName);
    IdDt id = ourPatientDao.create(p).getId();
    ourLog.info("Created patient, got it: {}", id);

    p = new Patient();
    p.addIdentifier().setSystem("urn:system").setValue(methodName);
    p.addName().addFamily("Hello");
    p.setId("Patient/" + methodName);
    try {
      ourPatientDao.create(p);
      fail();
    } catch (UnprocessableEntityException e) {
      assertThat(
          e.getMessage(),
          containsString(
              "Can not create entity with ID["
                  + methodName
                  + "], a resource with this ID already exists"));
    }
  }
  @Test
  public void testCreateDuplicateCodeSystemUri() {
    CodeSystem codeSystem = new CodeSystem();
    codeSystem.setUrl(CS_URL);
    codeSystem.setContent(CodeSystemContentMode.NOTPRESENT);
    IIdType id =
        myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified();

    ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong());

    TermCodeSystemVersion cs = new TermCodeSystemVersion();
    cs.setResource(table);
    cs.setResourceVersionId(table.getVersion());

    myTermSvc.storeNewCodeSystemVersion(table.getId(), CS_URL, cs);

    // Update
    cs = new TermCodeSystemVersion();
    TermConcept parentA = new TermConcept(cs, "ParentA");
    cs.getConcepts().add(parentA);
    id = myCodeSystemDao.update(codeSystem, new ServletRequestDetails()).getId().toUnqualified();
    table = myResourceTableDao.findOne(id.getIdPartAsLong());
    cs.setResource(table);
    cs.setResourceVersionId(table.getVersion());
    myTermSvc.storeNewCodeSystemVersion(table.getId(), CS_URL, cs);

    // Try to update to a different resource
    codeSystem = new CodeSystem();
    codeSystem.setUrl(CS_URL);
    codeSystem.setContent(CodeSystemContentMode.NOTPRESENT);
    id = myCodeSystemDao.create(codeSystem, new ServletRequestDetails()).getId().toUnqualified();
    table = myResourceTableDao.findOne(id.getIdPartAsLong());
    cs.setResource(table);
    cs.setResourceVersionId(table.getVersion());
    try {
      myTermSvc.storeNewCodeSystemVersion(table.getId(), CS_URL, cs);
      fail();
    } catch (UnprocessableEntityException e) {
      assertThat(
          e.getMessage(),
          containsString(
              "Can not create multiple code systems with URI \"http://example.com/my_code_system\", already have one with resource ID: CodeSystem/"));
    }
  }