コード例 #1
0
 private static SupportedAssociation createSupportedAssociation(
     String uri, String localId, String content) {
   SupportedAssociation sa = new SupportedAssociation();
   sa.setUri(uri);
   sa.setLocalId(localId);
   sa.setContent(content);
   return sa;
 }
  private void add(
      EntityReference entityReference,
      ValueSetDefinitionEntry cts2Entry,
      org.LexGrid.valueSets.ValueSetDefinition lexEvsVSD) {
    URIAndEntityName uriAndName = new URIAndEntityName();
    uriAndName.setName(entityReference.getEntityCode());

    String namespace = entityReference.getEntityCodeNamespace();
    if (StringUtils.isBlank(namespace)) {
      namespace = lexEvsVSD.getDefaultCodingScheme();
    }

    uriAndName.setNamespace(namespace);

    SupportedNamespace supportedNamespace = this.findNamespace(lexEvsVSD.getMappings(), namespace);

    if (supportedNamespace == null) {
      log.warn(
          "EntityRefernece: "
              + entityReference.getEntityCodeNamespace()
              + ":"
              + entityReference.getEntityCode()
              + " does not have a valid namespace.");

      try {
        CodingScheme cs = this.lexBigService.resolveCodingScheme(namespace, null);
        SupportedNamespace sns = new SupportedNamespace();
        sns.setContent(cs.getCodingSchemeName());
        sns.setEquivalentCodingScheme(cs.getCodingSchemeName());
        sns.setLocalId(cs.getCodingSchemeName());
        sns.setUri(cs.getCodingSchemeURI());

        supportedNamespace = sns;
      } catch (LBException e) {
        log.info(e);

        // we have to punt here
        SupportedNamespace sns = new SupportedNamespace();
        sns.setContent("unknown");
        sns.setEquivalentCodingScheme("unknown");
        sns.setLocalId("unknown");
        sns.setUri("unknown");
      }
    }

    uriAndName.setUri(
        UriUtils.combine(supportedNamespace.getUri(), entityReference.getEntityCode()));

    if (entityReference.getReferenceAssociation() != null) {
      AssociatedEntitiesReference ref = new AssociatedEntitiesReference();
      ref.setReferencedEntity(uriAndName);
      ref.setDirection(
          entityReference.getTargetToSource()
              ? AssociationDirection.TARGET_TO_SOURCE
              : AssociationDirection.SOURCE_TO_TARGET);

      String cs = supportedNamespace.getEquivalentCodingScheme();
      SupportedCodingScheme supportedCodingScheme = this.findCodingScheme(lexEvsVSD, cs);

      CodeSystemReference codingSchemeRef =
          this.getTransformUtils()
              .toCodeSystemReference(
                  supportedCodingScheme.getLocalId(), supportedCodingScheme.getUri());

      ref.setCodeSystem(codingSchemeRef);

      ref.setTransitivity(
          entityReference.getTransitiveClosure()
              ? TransitiveClosure.TRANSITIVE_CLOSURE
              : TransitiveClosure.DIRECTLY_ASSOCIATED);

      ref.setLeafOnly(
          entityReference.getLeafOnly() ? LeafOrAll.LEAF_ONLY : LeafOrAll.ALL_INTERMEDIATE_NODES);

      String association = entityReference.getReferenceAssociation();
      PredicateReference predicate = new PredicateReference();
      predicate.setName(association);

      // namespace for a predicate is not guaranteed in LexEVS... not sure
      // how we want to handle this. For now, assume the same namespace
      // as the starting entity.
      SupportedAssociation supportedAssociation =
          this.findAssociation(lexEvsVSD.getMappings(), association);

      if (supportedAssociation == null) {
        predicate.setNamespace(supportedCodingScheme.getLocalId());
        predicate.setUri(UriUtils.combine(supportedCodingScheme.getUri(), association));
      } else {
        predicate.setNamespace(supportedAssociation.getEntityCodeNamespace());
        if (StringUtils.isNotBlank(supportedAssociation.getUri())) {
          predicate.setUri(supportedAssociation.getUri());
        } else {
          predicate.setUri(UriUtils.combine(supportedCodingScheme.getUri(), association));
        }
      }

      ref.setPredicate(predicate);

      cts2Entry.setAssociatedEntities(ref);
    } else {
      SpecificEntityList sel = new SpecificEntityList();

      sel.addReferencedEntity(uriAndName);

      cts2Entry.setEntityList(sel);
    }
  }