예제 #1
0
 private ValidationResult verifyCodeInCodeSystem(
     CodeSystem cs, String system, String code, String display) throws Exception {
   ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
   if (cc == null)
     if (cs.getContent().equals(CodeSystem.CodeSystemContentMode.COMPLETE))
       return new ValidationResult(
           IssueSeverity.ERROR, "Unknown Code " + code + " in " + cs.getUrl());
     else if (!cs.getContent().equals(CodeSystem.CodeSystemContentMode.NOTPRESENT))
       return new ValidationResult(
           IssueSeverity.WARNING,
           "Unknown Code " + code + " in partial code list of " + cs.getUrl());
     else
       return verifyCodeExternal(
           null, new Coding().setSystem(system).setCode(code).setDisplay(display), false);
   //
   //        return new ValidationResult(IssueSeverity.WARNING, "A definition was found for
   // "+cs.getUrl()+", but it has no codes in the definition");
   //      return new ValidationResult(IssueSeverity.ERROR, "Unknown Code "+code+" in
   // "+cs.getUrl());
   if (display == null) return new ValidationResult(cc);
   CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
   if (cc.hasDisplay()) {
     b.append(cc.getDisplay());
     if (display.equalsIgnoreCase(cc.getDisplay())) return new ValidationResult(cc);
   }
   for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
     b.append(ds.getValue());
     if (display.equalsIgnoreCase(ds.getValue())) return new ValidationResult(cc);
   }
   return new ValidationResult(
       IssueSeverity.WARNING,
       "Display Name for " + code + " must be one of '" + b.toString() + "'",
       cc);
 }
  @Test
  public void testStoreCodeSystemInvalidCyclicLoop() {
    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());

    TermConcept parent = new TermConcept();
    parent.setCodeSystem(cs);
    parent.setCode("parent");
    cs.getConcepts().add(parent);

    TermConcept child = new TermConcept();
    child.setCodeSystem(cs);
    child.setCode("child");
    parent.addChild(child, RelationshipTypeEnum.ISA);

    child.addChild(parent, RelationshipTypeEnum.ISA);

    try {
      myTermSvc.storeNewCodeSystemVersion(table.getId(), "http://foo", cs);
      fail();
    } catch (InvalidRequestException e) {
      assertEquals("CodeSystem contains circular reference around code parent", e.getMessage());
    }
  }
  private IIdType createCodeSystem() {
    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());

    TermConcept parentA = new TermConcept(cs, "ParentA");
    cs.getConcepts().add(parentA);

    TermConcept childAA = new TermConcept(cs, "childAA");
    parentA.addChild(childAA, RelationshipTypeEnum.ISA);

    TermConcept childAAA = new TermConcept(cs, "childAAA");
    childAA.addChild(childAAA, RelationshipTypeEnum.ISA);

    TermConcept childAAB = new TermConcept(cs, "childAAB");
    childAA.addChild(childAAB, RelationshipTypeEnum.ISA);

    TermConcept childAB = new TermConcept(cs, "childAB");
    parentA.addChild(childAB, RelationshipTypeEnum.ISA);

    TermConcept parentB = new TermConcept(cs, "ParentB");
    cs.getConcepts().add(parentB);

    myTermSvc.storeNewCodeSystemVersion(table.getId(), "http://foo", cs);
    return id;
  }
예제 #4
0
 private String cacheValue(CodeSystem cs) throws IOException {
   CodeSystem csid = new CodeSystem();
   csid.setId(cs.getId());
   csid.setVersion(cs.getVersion());
   csid.setContent(cs.getContent());
   csid.setHierarchyMeaning(CodeSystemHierarchyMeaning.GROUPEDBY);
   for (ConceptDefinitionComponent cc : cs.getConcept())
     csid.getConcept().add(processCSConcept(cc));
   JsonParser parser = new JsonParser();
   parser.setOutputStyle(OutputStyle.NORMAL);
   ByteArrayOutputStream b = new ByteArrayOutputStream();
   parser.compose(b, csid);
   b.close();
   return new String(b.toByteArray(), Charsets.UTF_8);
 }
  @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/"));
    }
  }
예제 #6
0
 @Override
 public boolean supportsSystem(String system) throws TerminologyServiceException {
   if (codeSystems.containsKey(system)) return true;
   else if (nonSupportedCodeSystems.contains(system)) return false;
   else if (system.startsWith("http://example.org")
       || system.startsWith("http://acme.com")
       || system.startsWith("http://hl7.org/fhir/valueset-")
       || system.startsWith("urn:oid:")) return false;
   else {
     if (noTerminologyServer) return false;
     if (bndCodeSystems == null) {
       try {
         log("Terminology server: Check for supported code systems for " + system);
         bndCodeSystems =
             txServer.fetchFeed(
                 txServer.getAddress()
                     + "/CodeSystem?content=not-present&_summary=true&_count=1000");
       } catch (Exception e) {
         if (canRunWithoutTerminology) {
           noTerminologyServer = true;
           log("==============!! Running without terminology server !!==============");
           return false;
         } else throw new TerminologyServiceException(e);
       }
     }
     if (bndCodeSystems != null) {
       for (BundleEntryComponent be : bndCodeSystems.getEntry()) {
         CodeSystem cs = (CodeSystem) be.getResource();
         if (!codeSystems.containsKey(cs.getUrl())) {
           codeSystems.put(cs.getUrl(), null);
         }
       }
     }
     if (codeSystems.containsKey(system)) return true;
   }
   nonSupportedCodeSystems.add(system);
   return false;
 }
예제 #7
0
  private String gen(Section section, CodeSystem cs, ValueSet vs) {
    String bn = getPNameForUri(cs.getUrl());
    if (!bn.startsWith("<")) {
      section.triple(bn + ".system", "a", "fhir:CodeSystem");
      if (cs.hasVersion()) section.triple(bn + ".system", "fhir:version", literal(cs.getVersion()));
      if (vs.hasName()) section.label(bn + ".system", vs.getName());
      if (vs.hasDescription())
        section.comment(
            bn + ".system",
            vs.getDescription()
                .replace("value set", "code system")
                .replace("Value Set", "Code System")
                .replace("Value set", "Code system"));
      if (vs.hasCopyright())
        section.triple(bn + ".system", "dc:rights", literal(vs.getCopyright()));
      if (vs.hasDate()) section.triple(bn + ".system", "dc:date", literal(vs.getDate().toString()));

      section.triple(bn, "a", "fhir:Concept");

      gen(section, bn, bn, cs.getConcept());
    }
    return bn;
  }