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();
 }
 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();
 }
 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());
     }
   }
 }