use of org.hl7.fhir.r4.elementmodel.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();
}
};
}
use of org.hl7.fhir.r4.elementmodel.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;
}
use of org.hl7.fhir.r4.elementmodel.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;
}
use of org.hl7.fhir.r4.elementmodel.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;
}
use of org.hl7.fhir.r4.elementmodel.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());
}
}
}
Aggregations