private void scan(ElementDefn e, String path) throws Exception {
   if (e.hasBinding()) {
     BindingSpecification cd = e.getBinding();
     if (!txusages.containsKey(cd)) {
       txusages.put(cd, new ArrayList<CDUsage>());
       c++;
       txusages.get(cd).add(new CDUsage(String.valueOf(c), null));
     }
     txusages.get(cd).add(new CDUsage(path, e));
   }
   for (ElementDefn c : e.getElements()) {
     scan(c, path + "." + c.getName());
   }
 }
Exemplo n.º 2
0
  private void genRange(
      Section section, String tn, String en, ElementDefn e, TypeRef tr, boolean datatype)
      throws Exception {
    // metadata
    if (e.isModifier())
      section.triple(
          "fhir:" + tn + "." + en, "fhir:hasFlag", complex().predicate("a", "fhir:isModifier"));
    if (e.isXmlAttribute())
      section.triple(
          "fhir:" + tn + "." + en, "fhir:hasFlag", complex().predicate("a", "fhir:isXmlAtribute"));
    if (e.hasMustSupport() && e.isMustSupport())
      section.triple(
          "fhir:" + tn + "." + en, "fhir:hasFlag", complex().predicate("a", "fhir:isMustSupport"));
    if (e.hasSummaryItem() && e.isSummaryItem())
      section.triple(
          "fhir:" + tn + "." + en, "fhir:hasFlag", complex().predicate("a", "fhir:isSummaryItem"));
    if (!Utilities.noString(e.getW5()))
      section.triple(
          "fhir:" + tn + "." + en, "fhir:w5", complex().predicate("a", "fhir:w5\\#" + e.getW5()));
    if (e.hasMeaningWhenMissing())
      section.triple(
          "fhir:" + tn + "." + en, "fhir:missingMeaning", literal(e.getMeaningWhenMissing()));

    // cardinality
    cardinality(
        section,
        "fhir:" + tn + "." + en,
        e.getMinCardinality().toString(),
        e.getMaxCardinality() == Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString());
    //    section.triple("fhir:"+tn+"."+en, "fhir:minCardinality",
    // literal(e.getMinCardinality().toString()));
    //    section.triple("fhir:"+tn+"."+en, "fhir:maxCardinality", literal(e.getMaxCardinality() ==
    // Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString()));

    // now in OWL:
    if (e.getMinCardinality() > 0)
      section.triple(
          "fhir:" + tn,
          "rdfs:subClassOf",
          complex()
              .predicate("a", "owl:Restriction")
              .predicate("owl:onProperty", "fhir:" + tn + "." + en)
              .predicate(
                  "owl:minCardinality",
                  literalTyped(e.getMinCardinality().toString(), "nonNegativeInteger")));
    if (e.getMaxCardinality() < Integer.MAX_VALUE)
      section.triple(
          "fhir:" + tn,
          "rdfs:subClassOf",
          complex()
              .predicate("a", "owl:Restriction")
              .predicate("owl:onProperty", "fhir:" + tn + "." + en)
              .predicate(
                  "owl:maxCardinality",
                  literalTyped(e.getMaxCardinality().toString(), "nonNegativeInteger")));

    // define
    if (tr == null) {
      section.triple("fhir:" + tn + "." + en, "rdfs:range", "fhir:" + e.getDeclaredTypeName());
      anonTypes.push(new AnonTypeInfo(section, e.getDeclaredTypeName(), e, datatype));
    } else if (tr.getName().startsWith("@")) {
      ElementDefn r = getElementForPath(tr.getName().substring(1));
      section.triple("fhir:" + tn + "." + en, "rdfs:range", "fhir:" + r.getDeclaredTypeName());
    } else {
      if (e.hasBinding()) {
        BindingSpecification bs = e.getBinding();
        if (bs.getValueSet() != null) {
          String bn = getPNameForUri(bs.getValueSet().getUrl());
          section.triple("fhir:" + tn + "." + en, "rdfs:range", processType(tr.getName()));
          section.triple("fhir:" + tn + "." + en, "fhir:binding", bn);
          if (!bn.startsWith("vs:")) // a v3 valueset
          valuesets.put(bn, bs.getValueSet());
        } else if (!Utilities.noString(bs.getReference())) {
          section.triple("fhir:" + tn + "." + en, "rdfs:range", processType(tr.getName()));
          section.triple("fhir:" + tn + "." + en, "fhir:binding", "<" + bs.getReference() + ">");
        }
        //        if (bs.hasMax())
        // need to figure out how this should be represented in Turtle
        section.triple(
            "fhir:" + tn + "." + en,
            "fhir:bindingStrength",
            complex().predicate("a", "fhir:binding-strength\\#" + bs.getStrength().toCode()));
      } else section.triple("fhir:" + tn + "." + en, "rdfs:range", processType(tr.getName()));
    }
    if (e.getDefaultValue() != null) {
      if (e.getDefaultValue() instanceof DecimalType)
        section.triple(
            "fhir:" + tn + "." + en,
            "fhir:default",
            complex()
                .predicate("a", "fhir:decimal")
                .predicate(
                    "fhir:value", literal(((DecimalType) e.getDefaultValue()).asStringValue())));
      else if (e.getDefaultValue() instanceof BooleanType)
        section.triple(
            "fhir:" + tn + "." + en,
            "fhir:default",
            complex()
                .predicate("a", "fhir:boolean")
                .predicate(
                    "fhir:value", literal(((BooleanType) e.getDefaultValue()).asStringValue())));
      else if (e.getDefaultValue() instanceof IntegerType)
        section.triple(
            "fhir:" + tn + "." + en,
            "fhir:default",
            complex()
                .predicate("a", "fhir:integer")
                .predicate(
                    "fhir:value", literal(((IntegerType) e.getDefaultValue()).asStringValue())));
      else if (e.getDefaultValue() instanceof CodeType)
        section.triple(
            "fhir:" + tn + "." + en,
            "fhir:default",
            complex()
                .predicate("a", "fhir:integer")
                .predicate(
                    "fhir:value", literal(((CodeType) e.getDefaultValue()).asStringValue())));
      else
        throw new Error(
            "default of type " + e.getDefaultValue().getClass().getName() + " not handled yet");
    }
  }