Пример #1
0
 private void gen(TypeDefn t) throws Exception {
   Section section = section(t.getName());
   if (t.getTypes().isEmpty()) section.triple("fhir:" + t.getName(), "a", "rdfs:Class");
   else section.triple("fhir:" + t.getName(), "rdfs:subClassOf", "fhir:Element");
   section.label("fhir:" + t.getName(), t.getShortDefn());
   section.comment("fhir:" + t.getName(), t.getDefinition());
   if (t.getName().equals("Reference"))
     section.triple(
         "fhir:" + t.getName(),
         "a",
         "fhir:Resource"); // This is so that a reference can be replaced by a direct reference to
   // it's target
   nilInstance.predicate("a", "fhir:" + t.getName());
   processMappings(section, "fhir:" + t.getName(), t);
   for (ElementDefn e : t.getElements()) {
     if (e.getName().endsWith("[x]")) {
       String cn = e.getName().substring(0, e.getName().length() - 3);
       section.triple("fhir:" + t.getName() + "." + cn, "a", "rdf:Property");
       section.label("fhir:" + t.getName() + "." + cn, e.getShortDefn());
       section.comment("fhir:" + t.getName() + "." + cn, e.getDefinition());
       processMappings(section, "fhir:" + t.getName() + "." + cn, e);
       for (TypeRef tr : e.typeCode().equals("*") ? getAnyTypes() : e.getTypes()) {
         String en = cn + Utilities.capitalize(tr.getName());
         section.triple(
             "fhir:" + t.getName() + "." + en,
             "rdfs:subPropertyOf",
             "fhir:" + t.getName() + "." + cn);
         section.triple("fhir:" + t.getName() + "." + en, "rdfs:domain", "fhir:" + t.getName());
         genRange(section, t.getName(), en, e, tr, true);
       }
     } else {
       section.triple("fhir:" + t.getName() + "." + e.getName(), "a", "rdf:Property");
       section.comment("fhir:" + t.getName() + "." + e.getName(), e.getDefinition());
       section.triple(
           "fhir:" + t.getName() + "." + e.getName(), "rdfs:domain", "fhir:" + t.getName());
       processMappings(section, "fhir:" + t.getName() + "." + e.getName(), e);
       genRange(
           section,
           t.getName(),
           e.getName(),
           e,
           e.getTypes().isEmpty() ? null : e.getTypes().get(0),
           true);
     }
   }
   processAnonTypes();
 }
Пример #2
0
 private void gen(ResourceDefn rd) throws Exception {
   Section section = section(rd.getName());
   ElementDefn t = rd.getRoot();
   if (t.getTypes().isEmpty()) section.triple("fhir:" + t.getName(), "a", "rdfs:Class");
   else section.triple("fhir:" + t.getName(), "rdfs:subClassOf", processType(t.typeCode()));
   section.comment("fhir:" + t.getName(), rd.getDefinition());
   if (!Utilities.noString(t.getW5()))
     section.triple(
         "fhir:" + t.getName(), "fhir:w5", complex().predicate("a", "fhir:w5\\#" + t.getW5()));
   processMappings(section, "fhir:" + rd.getName(), rd.getRoot());
   for (ElementDefn e : t.getElements()) {
     if (e.getName().endsWith("[x]")) {
       String cn = e.getName().substring(0, e.getName().length() - 3);
       section.triple("fhir:" + t.getName() + "." + cn, "a", "rdf:Property");
       section.comment("fhir:" + t.getName() + "." + cn, e.getDefinition());
       processMappings(section, "fhir:" + t.getName() + "." + cn, e);
       for (TypeRef tr : e.typeCode().equals("*") ? getAnyTypes() : e.getTypes()) {
         String en = cn + Utilities.capitalize(tr.getName());
         section.triple(
             "fhir:" + t.getName() + "." + en,
             "rdfs:subPropertyOf",
             "fhir:" + t.getName() + "." + cn);
         section.triple("fhir:" + t.getName() + "." + en, "rdfs:domain", "fhir:" + rd.getName());
         genRange(section, t.getName(), en, e, tr, false);
       }
     } else {
       section.triple("fhir:" + t.getName() + "." + e.getName(), "a", "rdf:Property");
       section.comment("fhir:" + t.getName() + "." + e.getName(), e.getDefinition());
       section.triple(
           "fhir:" + t.getName() + "." + e.getName(), "rdfs:domain", "fhir:" + rd.getName());
       processMappings(section, "fhir:" + t.getName() + "." + e.getName(), e);
       genRange(
           section,
           t.getName(),
           e.getName(),
           e,
           e.getTypes().isEmpty() ? null : e.getTypes().get(0),
           false);
     }
   }
   processAnonTypes();
 }
Пример #3
0
 private void genAnon(AnonTypeInfo at) throws Exception {
   if (at.isType()) at.getSection().triple("fhir:" + at.getName(), "a", "fhir:Element");
   else at.getSection().triple("fhir:" + at.getName(), "a", "fhir:BackboneElement");
   at.getSection().comment("fhir:" + at.getName(), at.getDefn().getDefinition());
   processMappings(at.getSection(), "fhir:" + at.getName(), at.getDefn());
   for (ElementDefn e : at.getDefn().getElements()) {
     if (e.getName().endsWith("[x]")) {
       String cn = e.getName().substring(0, e.getName().length() - 3);
       at.getSection().triple("fhir:" + at.getName() + "." + cn, "a", "rdf:Property");
       at.getSection().comment("fhir:" + at.getName() + "." + cn, e.getDefinition());
       processMappings(at.getSection(), "fhir:" + at.getName() + "." + cn, e);
       for (TypeRef tr : e.typeCode().equals("*") ? getAnyTypes() : e.getTypes()) {
         String en = cn + Utilities.capitalize(tr.getName());
         at.getSection()
             .triple(
                 "fhir:" + at.getName() + "." + en,
                 "rdfs:subPropertyOf",
                 "fhir:" + at.getName() + "." + cn);
         at.getSection()
             .triple("fhir:" + at.getName() + "." + en, "rdfs:domain", "fhir:" + at.getName());
         genRange(at.getSection(), at.getName(), en, e, tr, at.isType());
       }
     } else {
       at.getSection().triple("fhir:" + at.getName() + "." + e.getName(), "a", "rdf:Property");
       at.getSection().comment("fhir:" + at.getName() + "." + e.getName(), e.getDefinition());
       processMappings(at.getSection(), "fhir:" + at.getName() + "." + e.getName(), e);
       at.getSection()
           .triple(
               "fhir:" + at.getName() + "." + e.getName(), "rdfs:domain", "fhir:" + at.getName());
       genRange(
           at.getSection(),
           at.getName(),
           e.getName(),
           e,
           e.getTypes().isEmpty() ? null : e.getTypes().get(0),
           at.isType());
     }
   }
 }
Пример #4
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");
    }
  }