private void cardinality(Subject subject, String min, String max) {
   if ("0".equals(min) && "1".equals(max)) subject.predicate("os:occurs", "os:Zero-or-one");
   else if ("0".equals(min) && "*".equals(max)) subject.predicate("os:occurs", "os:Zero-or-many");
   else if ("1".equals(min) && "1".equals(max)) subject.predicate("os:occurs", "os:Exactly-one");
   else if ("1".equals(min) && "*".equals(max)) subject.predicate("os:occurs", "os:One-or-many");
   else throw new Error("Unhandled cardinality combination (" + min + "/" + max + ")");
 }
  private void genExtension(StructureDefinition extension) throws FHIRException {
    // for now, only simple extensions
    if (extension.getSnapshot().getElement().size() == 5
        && !hasSection("Extension: " + tail(extension.getUrl()))) {
      ElementDefinition base = extension.getSnapshot().getElement().get(0);
      ElementDefinition valueX = extension.getSnapshot().getElement().get(4);
      Section section = section("Extension: " + tail(extension.getUrl()));
      Subject subject = section.subject("ex:birthplace");
      subject.predicate("a", "fhir:ExtensionDefinition");
      subject.label(extension.getTitle());
      subject.comment(extension.getDescription());
      if (extension.hasVersion())
        subject.predicate("fhir:version", literal(extension.getVersion()));
      if (extension.hasCopyright())
        subject.predicate("dc:rights", literal(extension.getCopyright()));
      subject.predicate(
          "fhir:status",
          complex()
              .predicate(
                  "a", "fhir:conformance-resource-status\\#" + extension.getStatus().toCode()));
      subject.predicate(
          "fhir:canonicalStatus",
          complex()
              .predicate(
                  "a", getCanonicalStatus("ValueSet.status", extension.getStatus().toCode())));
      for (UsageContext cc : extension.getUseContext())
        codedTriple(subject, "fhir:useContext", cc.getValueCodeableConcept());
      if (extension.hasDate())
        subject.predicate("dc:date", literal(extension.getDateElement().asStringValue()));

      subject.predicate("rdfs:range", processType(valueX.getType().get(0).getCode()));
      if (base.getIsModifier()) subject.predicate("fhir:flag", "fhir:isModifier");
    }
  }
 private void gen(PrimitiveType t) {
   Section section = section(t.getCode());
   section.triple("fhir:" + t.getCode(), "rdfs:subClassOf", "fhir:Primitive");
   section.comment("fhir:" + t.getCode(), t.getDefinition());
   nilInstance.predicate("a", "fhir:" + t.getCode());
   section.triple("fhir:" + t.getCode() + ".value", "rdfs:subPropertyOf", "fhir:Primitive.value");
   section.triple("fhir:" + t.getCode() + ".value", "rdfs:domain", "fhir:" + t.getCode());
   if (t.getSchemaType().endsWith("+")) {
     section.triple(
         "fhir:" + t.getCode() + ".value",
         "rdfs:range",
         "xs:" + t.getSchemaType().substring(0, t.getSchemaType().length() - 1));
     section.triple(
         "fhir:" + t.getCode() + ".value",
         "owl:withRestriction",
         complex().predicate("xs:pattern", literal(t.getRegex())));
   } else if (t.getSchemaType().contains(",")) {
     section.triple(
         "fhir:" + t.getCode() + ".value",
         "rdfs:range",
         complex()
             .predicate("a", "owl:Class")
             .predicate("owl:unionOf", "(" + t.getSchemaType().replace(",", "") + ")"),
         "xs:union of " + t.getSchemaType());
   } else
     section.triple("fhir:" + t.getCode() + ".value", "rdfs:range", "xs:" + t.getSchemaType());
 }
 protected void codedTriple(Subject subject, String predicate, CodeableConcept cc) {
   for (Coding c : cc.getCoding()) {
     String s = getLinkedForm(c);
     if (s != null)
       subject.predicate(
           predicate, new StringType(s), c.hasDisplay() ? c.getDisplay() : cc.getText());
   }
 }
  private void gen(ProfiledType t) throws Exception {
    Section section = section(t.getName());
    section.triple("fhir:" + t.getName(), "rdfs:subClassOf", "fhir:" + t.getBaseType());
    nilInstance.predicate("a", "fhir:" + t.getName());

    section.label("fhir:" + t.getName(), t.getDescription());
    section.comment("fhir:" + t.getName(), t.getDefinition());
    if (!Utilities.noString(t.getInvariant().getTurtle()))
      section.importTtl(t.getInvariant().getTurtle());
  }
 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(DefinedStringPattern t) {
   Section section = section(t.getCode());
   section.triple("fhir:" + t.getCode(), "rdfs:subClassOf", "fhir:" + t.getBase());
   section.comment("fhir:" + t.getCode(), t.getDefinition());
   nilInstance.predicate("a", "fhir:" + t.getCode());
   section.triple(
       "fhir:" + t.getCode() + ".value", "rdfs:subPropertyOf", "fhir:" + t.getBase() + ".value");
   if (t.getSchema().endsWith("+")) {
     section.triple(
         "fhir:" + t.getCode() + ".value",
         "rdfs:range",
         t.getSchema().substring(0, t.getSchema().length() - 1));
     section.triple(
         "fhir:" + t.getCode() + ".value",
         "owl:withRestriction",
         complex().predicate("xs:pattern", literal(t.getRegex())));
   } else section.triple("fhir:" + t.getCode() + ".value", "rdfs:range", t.getSchema());
 }