Search in sources :

Example 1 with FhirResource

use of org.hl7.davinci.endpoint.database.FhirResource in project kindling by HL7.

the class FhirTurtleGenerator method genResourceDefn.

/**
 * Resource Definition generator
 *
 * @param rd Resource Definition to emit
 * @throws Exception
 */
private void genResourceDefn(ResourceDefn rd) throws Exception {
    String resourceName = rd.getName();
    ElementDefn resourceType = rd.getRoot();
    FHIRResource rdRes = fact.fhir_class(resourceName, resourceType.getTypes().isEmpty() ? OWL2.Thing : RDFNamespace.FHIR.resourceRef(resourceType.typeCode())).addDefinition(rd.getDefinition());
    processTypes(resourceName, rdRes, resourceType, resourceName, true);
    if (!Utilities.noString(resourceType.getW5()))
        rdRes.addObjectProperty(RDFS.subClassOf, RDFNamespace.W5.resourceRef(resourceType.getW5()));
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 2 with FhirResource

use of org.hl7.davinci.endpoint.database.FhirResource in project kindling by HL7.

the class FhirTurtleGenerator method processTypes.

private void processTypes(String baseResourceName, FHIRResource baseResource, ElementDefn td, String predicateBase, boolean innerIsBackbone) throws Exception {
    for (ElementDefn ed : td.getElements()) {
        String predicateName = predicateBase + "." + (ed.getName().endsWith("[x]") ? ed.getName().substring(0, ed.getName().length() - 3) : ed.getName());
        FHIRResource predicateResource;
        if (ed.getName().endsWith("[x]")) {
            predicateResource = fact.fhir_objectProperty(predicateName);
            // Choice entry
            if (ed.typeCode().equals("*")) {
                // Wild card -- any element works (probably should be more restrictive but...)
                Resource targetResource = RDFNamespace.FHIR.resourceRef("Element");
                baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource, targetResource, ed.getMinCardinality(), ed.getMaxCardinality()));
                predicateResource.domain(baseResource);
                predicateResource.range(targetResource);
            } else {
                // Create a restriction on the union of possible types
                List<Resource> typeOpts = new ArrayList<Resource>();
                for (TypeRef tr : ed.getTypes()) {
                    // TODO: Figure out how to get the type reference code
                    String trName = tr.getName();
                    if (trName.equals("SimpleQuantity"))
                        trName = "Quantity";
                    String qualifiedPredicateName = predicateName + Utilities.capitalize(trName);
                    Resource targetRes = fact.fhir_class(tr.getName()).resource;
                    FHIRResource qualifiedPredicate = fact.fhir_objectProperty(qualifiedPredicateName, predicateResource.resource).domain(baseResource).range(targetRes);
                    typeOpts.add(fact.fhir_cardinality_restriction(qualifiedPredicate.resource, targetRes, ed.getMinCardinality(), ed.getMaxCardinality()));
                }
                baseResource.restriction(fact.fhir_union(typeOpts));
            }
        } else {
            FHIRResource baseDef;
            if (ed.getTypes().isEmpty()) {
                predicateResource = fact.fhir_objectProperty(predicateName);
                String targetClassName = mapComponentName(baseResourceName, ed.getDeclaredTypeName());
                baseDef = fact.fhir_class(targetClassName, innerIsBackbone ? "BackboneElement" : "Element").addDefinition(ed.getDefinition());
                processTypes(targetClassName, baseDef, ed, predicateName, innerIsBackbone);
            } else {
                TypeRef targetType = ed.getTypes().get(0);
                String targetName = targetType.getName();
                if (targetName.startsWith("@")) {
                    // Link to earlier definition
                    ElementDefn targetRef = getElementForPath(targetName.substring(1));
                    String targetRefName = targetRef.getName();
                    String targetClassName = baseResourceName + Character.toUpperCase(targetRefName.charAt(0)) + targetRefName.substring(1);
                    baseDef = fact.fhir_class(targetClassName, innerIsBackbone ? "BackboneElement" : "Element").addDefinition(ed.getDefinition()).addTitle(ed.getShortDefn());
                    if (!processing.contains(targetRefName)) {
                        processing.add(targetRefName);
                        processTypes(targetClassName, baseDef, targetRef, predicateName, innerIsBackbone);
                        processing.remove(targetRefName);
                    }
                } else {
                    // A placeholder entry.  The rest of the information will be supplied elsewhere
                    baseDef = fact.fhir_class(targetName);
                }
                // XHTML the exception, in that the html doesn't derive from Primitive
                if (targetName.equals("xhtml"))
                    predicateResource = fact.fhir_dataProperty(predicateName);
                else
                    predicateResource = fact.fhir_objectProperty(predicateName);
            }
            predicateResource.addTitle(ed.getShortDefn()).addDefinition(ed.getDefinition()).domain(baseResource);
            baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource, baseDef.resource, ed.getMinCardinality(), ed.getMaxCardinality()));
            predicateResource.range(baseDef.resource);
            if (!Utilities.noString(ed.getW5()))
                predicateResource.addObjectProperty(RDFS.subPropertyOf, RDFNamespace.W5.resourceRef(ed.getW5()));
        }
    }
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) Resource(org.apache.jena.rdf.model.Resource) FHIRResource(org.hl7.fhir.rdf.FHIRResource) ArrayList(java.util.ArrayList)

Example 3 with FhirResource

use of org.hl7.davinci.endpoint.database.FhirResource in project kindling by HL7.

the class FhirTurtleGenerator method genDefinedStringPattern.

/**
 * DefinedStringPattern Generator
 *
 * @param dsp FHIR DefinedStringPattern Type (e.g. id, oid, uuid)
 * @throws Exception
 */
private void genDefinedStringPattern(DefinedStringPattern dsp) throws Exception {
    String dspType = dsp.getSchema();
    String dspTypeName = dspType.endsWith("+") ? dspType.substring(0, dspType.length() - 1) : dspType;
    Resource dspTypeRes = RDFTypeMap.xsd_type_for(dspTypeName, owlTarget);
    FHIRResource dspRes = fact.fhir_class(dsp.getCode(), dsp.getBase()).addDefinition(dsp.getDefinition());
    if (dspRes != null) {
        if (dspType.endsWith("+")) {
            List<Resource> facets = new ArrayList<Resource>(1);
            facets.add(fact.fhir_pattern(dsp.getRegex()));
            dspRes.restriction(fact.fhir_restriction(value, fact.fhir_datatype_restriction(dspTypeRes == XSD.xstring ? XSD.normalizedString : dspTypeRes, facets)));
        } else
            dspRes.restriction(fact.fhir_restriction(value, dspTypeRes));
    }
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource) Resource(org.apache.jena.rdf.model.Resource) FHIRResource(org.hl7.fhir.rdf.FHIRResource) ArrayList(java.util.ArrayList)

Example 4 with FhirResource

use of org.hl7.davinci.endpoint.database.FhirResource in project kindling by HL7.

the class FhirTurtleGenerator method genPrimitiveType.

/* ==============================================
     Generators for various FHIR types
   * ============================================== */
/**
 * PrimitiveType Generator
 *
 * @param pt FHIR Primitive Type (e.g. int, string, dateTime)
 */
// Note: For unknown reasons, getPrimitives returns DefinedCodes, not PrimitiveTypes...
private void genPrimitiveType(DefinedCode pt) {
    String ptName = pt.getCode();
    FHIRResource ptRes = fact.fhir_class(ptName, "Primitive").addDefinition(pt.getDefinition());
    Resource rdfType = RDFTypeMap.xsd_type_for(ptName, owlTarget);
    if (rdfType != null)
        ptRes.restriction(fact.fhir_cardinality_restriction(value, fact.fhir_datatype(rdfType).resource, 1, 1));
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource) Resource(org.apache.jena.rdf.model.Resource) FHIRResource(org.hl7.fhir.rdf.FHIRResource)

Example 5 with FhirResource

use of org.hl7.davinci.endpoint.database.FhirResource in project kindling by HL7.

the class FhirTurtleGenerator method genBaseMetadata.

/**
 * Emit all the basic atoms that are implicit in the actual model
 */
private void genBaseMetadata() {
    // Declare these for now - they will get filled in more completely later on
    FHIRResource Resource = fact.fhir_class("Resource");
    FHIRResource Element = fact.fhir_class("Element");
    FHIRResource Reference = fact.fhir_class("Reference");
    // Primitive isn't in the actual model - added here
    fact.fhir_class("Primitive").addTitle("Types with only a value").addDefinition("Types with only a value and no additional elements as children").restriction(fact.fhir_restriction(value, RDFS.Literal));
    // A resource can have an optional nodeRole
    FHIRResource treeRoot = fact.fhir_class("treeRoot").addTitle("Class of FHIR base documents");
    FHIRResource nodeRole = fact.fhir_objectProperty("nodeRole").addTitle("Identifies role of subject in context of a given document").domain(Resource).range(treeRoot.resource);
    Resource.restriction(fact.fhir_cardinality_restriction(nodeRole.resource, treeRoot.resource, 0, 1));
    // Any element can have an index to assign order in a list
    FHIRResource index = fact.fhir_dataProperty("index").addTitle("Ordering value for list").domain(Element).range(XSD.nonNegativeInteger);
    Element.restriction(fact.fhir_cardinality_restriction(index.resource, XSD.nonNegativeInteger, 0, 1));
    // References have an optional link
    FHIRResource link = fact.fhir_objectProperty("link").addTitle("URI of a reference");
    Reference.restriction(fact.fhir_cardinality_restriction(link.resource, Resource.resource, 0, 1));
    // XHTML is an XML Literal -- but it isn't recognized by OWL so we use string
    FHIRResource NarrativeDiv = fact.fhir_dataProperty("Narrative.div");
    fact.fhir_class("xhtml", "Primitive").restriction(fact.fhir_cardinality_restriction(value, fact.fhir_datatype(XSD.xstring).resource, 1, 1));
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource)

Aggregations

FHIRResource (org.hl7.fhir.rdf.FHIRResource)6 FhirResource (org.hl7.davinci.endpoint.database.FhirResource)4 Resource (org.apache.jena.rdf.model.Resource)3 ArrayList (java.util.ArrayList)2 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)2 IParser (ca.uhn.fhir.parser.IParser)1 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)1 BaseServerResponseException (ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException)1 FhirResourceInfo (org.hl7.davinci.FhirResourceInfo)1 FhirResourceCriteria (org.hl7.davinci.endpoint.database.FhirResourceCriteria)1 TypeRef (org.hl7.fhir.definitions.model.TypeRef)1 ContactComponent (org.hl7.fhir.dstu3.model.Patient.ContactComponent)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 Resource (org.hl7.fhir.r4.model.Resource)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 HttpStatus (org.springframework.http.HttpStatus)1 MediaType (org.springframework.http.MediaType)1