Search in sources :

Example 1 with Property

use of org.hl7.fhir.dstu2016may.model.Property in project cqf-ruler by DBCG.

the class Reflections method getPrimitiveFunction.

/**
 * Generates a function to access a primitive property of the given
 * BaseType.
 *
 * @param <BaseType>       an IBase type
 * @param <ReturnType>     a return type for the Functions
 * @param theBaseTypeClass the class of a the IBase type
 * @param theChildName     to create a function for
 * @return a function for accessing the "theChildName" property of the
 *         BaseType
 */
@SuppressWarnings("unchecked")
public static <BaseType extends IBase, ReturnType> Function<BaseType, ReturnType> getPrimitiveFunction(final Class<? extends BaseType> theBaseTypeClass, String theChildName) {
    checkNotNull(theBaseTypeClass);
    checkNotNull(theChildName);
    IAccessor accessor = getAccessor(theBaseTypeClass, theChildName);
    return r -> {
        Optional<IBase> value = accessor.getFirstValueOrNull(r);
        if (!value.isPresent()) {
            return null;
        } else {
            return ((IPrimitiveType<ReturnType>) value.get()).getValue();
        }
    };
}
Also used : List(java.util.List) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor) FhirContext(ca.uhn.fhir.context.FhirContext) IBase(org.hl7.fhir.instance.model.api.IBase) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType) Optional(java.util.Optional) RuntimeResourceDefinition(ca.uhn.fhir.context.RuntimeResourceDefinition) Function(java.util.function.Function) Optional(java.util.Optional) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor)

Example 2 with Property

use of org.hl7.fhir.dstu2016may.model.Property in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveDiagnosticReport.

private DiagnosticReport resolveDiagnosticReport(ActivityDefinition activityDefinition, String patientId) {
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
    diagnosticReport.setSubject(new Reference(patientId));
    if (activityDefinition.hasCode()) {
        diagnosticReport.setCode(activityDefinition.getCode());
    } else {
        throw new ActivityDefinitionApplyException("Missing required ActivityDefinition.code property for DiagnosticReport");
    }
    if (activityDefinition.hasRelatedArtifact()) {
        List<Attachment> presentedFormAttachments = new ArrayList<>();
        for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
            Attachment attachment = new Attachment();
            if (artifact.hasUrl()) {
                attachment.setUrl(artifact.getUrl());
            }
            if (artifact.hasDisplay()) {
                attachment.setTitle(artifact.getDisplay());
            }
            presentedFormAttachments.add(attachment);
        }
        diagnosticReport.setPresentedForm(presentedFormAttachments);
    }
    return diagnosticReport;
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) Attachment(org.hl7.fhir.dstu3.model.Attachment) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact)

Example 3 with Property

use of org.hl7.fhir.dstu2016may.model.Property in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveMedicationRequest.

private MedicationRequest resolveMedicationRequest(ActivityDefinition activityDefinition, String patientId) throws ActivityDefinitionApplyException {
    // intent, medication, and subject are required
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setIntent(MedicationRequest.MedicationRequestIntent.ORDER);
    medicationRequest.setSubject(new Reference(patientId));
    if (activityDefinition.hasProduct()) {
        medicationRequest.setMedication(activityDefinition.getProduct());
    } else {
        throw new ActivityDefinitionApplyException("Missing required product property");
    }
    if (activityDefinition.hasDosage()) {
        medicationRequest.setDosageInstruction(activityDefinition.getDosage());
    }
    if (activityDefinition.hasBodySite()) {
        throw new ActivityDefinitionApplyException("BodySite does not map to " + activityDefinition.getKind());
    }
    if (activityDefinition.hasCode()) {
        throw new ActivityDefinitionApplyException("Code does not map to " + activityDefinition.getKind());
    }
    if (activityDefinition.hasQuantity()) {
        throw new ActivityDefinitionApplyException("Quantity does not map to " + activityDefinition.getKind());
    }
    return medicationRequest;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) Reference(org.hl7.fhir.dstu3.model.Reference)

Example 4 with Property

use of org.hl7.fhir.dstu2016may.model.Property in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveServiceRequest.

private ServiceRequest resolveServiceRequest(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId) throws ActivityDefinitionApplyException {
    // status, intent, code, and subject are required
    ServiceRequest serviceRequest = new ServiceRequest();
    serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.DRAFT);
    serviceRequest.setIntent(ServiceRequest.ServiceRequestIntent.PROPOSAL);
    String patientReferenceString = patientId;
    URI patientIdAsUri = URI.create(patientReferenceString);
    if (!patientIdAsUri.isAbsolute() && patientIdAsUri.getFragment() == null && !patientReferenceString.startsWith("Patient/")) {
        patientReferenceString = "Patient/" + patientId;
    }
    serviceRequest.setSubject(new Reference(patientReferenceString));
    if (practitionerId != null) {
        serviceRequest.setRequester(new Reference(practitionerId));
    } else if (organizationId != null) {
        serviceRequest.setRequester(new Reference(organizationId));
    }
    if (activityDefinition.hasExtension()) {
        serviceRequest.setExtension(activityDefinition.getExtension());
    }
    if (activityDefinition.hasCode()) {
        serviceRequest.setCode(activityDefinition.getCode());
    } else // code can be set as a dynamicValue
    if (!activityDefinition.hasCode() && !activityDefinition.hasDynamicValue()) {
        throw new ActivityDefinitionApplyException("Missing required code property");
    }
    if (activityDefinition.hasBodySite()) {
        serviceRequest.setBodySite(activityDefinition.getBodySite());
    }
    if (activityDefinition.hasProduct()) {
        throw new ActivityDefinitionApplyException("Product does not map to " + activityDefinition.getKind());
    }
    if (activityDefinition.hasDosage()) {
        throw new ActivityDefinitionApplyException("Dosage does not map to " + activityDefinition.getKind());
    }
    return serviceRequest;
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) URI(java.net.URI) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest)

Example 5 with Property

use of org.hl7.fhir.dstu2016may.model.Property in project quality-measure-and-cohort-service by Alvearie.

the class PathCaptureContext method reportProperty.

public void reportProperty(Property elm) {
    // Log guarding to prevent some of the parameter resolution logic from getting called unnecessarily
    if (LOG.isTraceEnabled()) {
        LOG.trace("Property {} source {}", elm.getPath(), elm.getSource() != null ? elm.getSource().getClass().getSimpleName() : null);
    }
    Set<QName> modelTypeNames = null;
    if (elm.getScope() != null || elm.getSource() instanceof AliasRef) {
        String aliasName = (elm.getScope() != null) ? elm.getScope() : ((AliasRef) elm.getSource()).getName();
        QueryAliasContext aliasContext = getCurrentQueryContext().resolveAlias(aliasName);
        if (aliasContext == null) {
            aliasContext = getCurrentExpressionContext().resolveAlias(aliasName);
        }
        modelTypeNames = ElmUtils.getModelTypeNames(aliasContext.getAliasedQuerySource().getExpression());
    } else if (elm.getSource() instanceof QueryLetRef) {
        String letName = ((QueryLetRef) elm.getSource()).getName();
        QueryLetContext letContext = getCurrentQueryContext().resolveLet(letName);
        if (letContext == null) {
            letContext = getCurrentExpressionContext().resolveLet(letName);
        }
        modelTypeNames = ElmUtils.getModelTypeNames(letContext.getLetClause().getExpression());
    } else {
        // There are times when the scope is null. I've noticed this particularly when referencing properties
        // of another expression result
        modelTypeNames = ElmUtils.getModelTypeNames(elm.getSource());
    }
    LOG.trace("ModelTypeNames {}", modelTypeNames);
    if (modelTypeNames != null) {
        for (QName qname : modelTypeNames) {
            pathsByQName.computeIfAbsent(qname, key -> new HashSet<>()).add(elm.getPath());
        }
    }
}
Also used : Property(org.hl7.elm.r1.Property) Logger(org.slf4j.Logger) VersionedIdentifier(org.hl7.elm.r1.VersionedIdentifier) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) UsingDef(org.hl7.elm.r1.UsingDef) HashMap(java.util.HashMap) Deque(java.util.Deque) HashSet(java.util.HashSet) AliasRef(org.hl7.elm.r1.AliasRef) Retrieve(org.hl7.elm.r1.Retrieve) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) QueryLetRef(org.hl7.elm.r1.QueryLetRef) QName(javax.xml.namespace.QName) ArrayDeque(java.util.ArrayDeque) ByColumn(org.hl7.elm.r1.ByColumn) ExpressionDef(org.hl7.elm.r1.ExpressionDef) AliasRef(org.hl7.elm.r1.AliasRef) QName(javax.xml.namespace.QName) QueryLetRef(org.hl7.elm.r1.QueryLetRef) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)35 FHIRException (org.hl7.fhir.exceptions.FHIRException)35 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)30 JsonElement (com.google.gson.JsonElement)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)21 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)15 JsonObject (com.google.gson.JsonObject)14 List (java.util.List)14 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)11 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)8 SpecialElement (org.hl7.fhir.r4b.elementmodel.Element.SpecialElement)8 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)8 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)8