import { CQLPatient } from '../../types/CQLPatient'; import { ELM, ELMEqual, ELMExpression, ELMFunctionRef, ELMAnd, ELMOr, ELMEquivalent, ELMIncludedIn, ELMIn, ELMNot, ELMIsNull, ELMInterval, ELMGreaterOrEqual, ELMGreater, ELMComparator, ELMLess, ELMLessOrEqual } from '../../types/ELMTypes'; import { AndFilter, AnyFilter, ParsedFilterInterval, DuringFilter, EqualsFilter, InFilter, NotNullFilter, OrFilter, QueryInfo, TautologyFilter, UnknownFilter, ValueFilter, ValueFilterComparator, IsNullFilter, QueryParserParams, Filter } from '../../types/QueryFilterTypes'; import { GracefulError } from '../../types/errors/GracefulError'; /** * Parse information about a query. This pulls out information about all sources in the query and attempts to parse * how the query is filtered. * * @param library The library ELM the query resides in. * @param allELM An array of all the ELM libraries accessible to fqm-execution (includes library from library param) * @param queryLocalId The localId for the query we want to get information on. * @param valueComparisonLocalId The localId for the initial expression that contained a comparator. Used for tracking * which clause is the "source" of the comparator in the case of nested expressions outside * of where statements. * @param parameters The parameters used for calculation so they could be reused for re-calculating small bits for CQL. * "Measurement Period" is the only supported parameter at the moment as it is the only parameter * seen in eCQMs. * @param patient The patient resource being calculated for. * @returns Information about the query and how it is filtered. */ export declare function parseQueryInfo(library: ELM, allELM: ELM[], queryLocalId?: string, valueComparisonLocalId?: string, parameters?: QueryParserParams, patient?: CQLPatient): Promise; /** * Interprets an expression into a filter tree. This is the central point where the interpreting occurs. This function * determines the expression type and sends it to the correct place to be parsed. * * @param expression The ELM expression/clause to attempt to interpret into a filter. * @param library The ELM library, in case it is needed for calculating intervals. * @param parameters The parameters used for calculation. * @param patient The patient resource. * @returns The simpler Filter representation of this clause. */ export declare function interpretExpression(expression: ELMExpression, library: ELM, parameters: any, patient?: CQLPatient): Promise; /** * Recursively search an ELM expression for usage of a property on a query source. * * @param expression Expression to search for property use in. * @param unknownLocalId The localId of the parent express that should be identified as the clause we are unable to parse. * @returns An `UnknownFilter` describing the attribute that was accessed or null if none was found. */ export declare function findPropertyUsage(expression: any, unknownLocalId?: string): UnknownFilter | null; /** * Recursively search an ELM expression for usage of a query source alias. * * @param expression Expression to search for alias use in. * @param unknownLocalId The localId of the parent expression that should be identified as the clause we are unable to parse. * @returns An `UnknownFilter` describing the attribute that was accessed or null if none was found. */ export declare function findAliasUsage(expression: any, unknownLocalId?: string): UnknownFilter | null; /** * Parses an `and` expression into a tree of filters. This will flatten directly nested `and` statements. * * @param andExpression The and expression to interpret. * @param library The library the elm is in. * @param parameters The original calculation parameters. * @param patient The patient resource. * @returns The filter tree for this and expression. */ export declare function interpretAnd(andExpression: ELMAnd, library: ELM, parameters: any, patient?: CQLPatient): Promise; /** * Parses an `or` expression into a tree of filters. This will flatten directly nested `or` statements. * * @param orExpression The or expression to interpret. * @param library The library the elm is in. * @param parameters The original calculation parameters. * @param patient The patient resource. * @returns The filter tree for this or expression. */ export declare function interpretOr(orExpression: ELMOr, library: ELM, parameters: any, patient?: CQLPatient): Promise; /** * Attempt to interpret what a FunctionRef is doing. This currently checks to see if it can be treated as a passthrough * to the property accessed in the operand. * * @param functionRef The function ref to look at. * @returns Usually an ELMProperty expression for the operand if it can be considered a passthrough. */ export declare function interpretFunctionRef(functionRef: ELMFunctionRef, library: ELM): any; /** * Interprets a `not` expression into a filter. This currently is able to handle "not null" and superfluous checks * that cql-to-elm adds (i.e. a check to see if the end of "Measurement Period" is not null) * * This is commonly seen in measures as an `Observation.value is not null`. * * @param not The ELM `Not` expression to parse. * @returns The interpreted filter. This may be a TautologyFilter that can be removed. */ export declare function interpretNot(not: ELMNot): NotNullFilter | TautologyFilter | UnknownFilter; /** * Parses an ELM isNull expression into a filter * @param equal The ELM isNull clause to parse. * @param library The library the clause resides in. * @returns The filter representation. */ export declare function interpretIsNull(isNull: ELMIsNull): IsNullFilter | TautologyFilter | UnknownFilter; /** * Parses an ELM equivalent expression into a filter. This currently handles checks against literals and checks against * a concept reference. * * @param equal The ELM equivalent clause to parse. * @param library The library the clause resides in. * @returns The filter representation. */ export declare function interpretEquivalent(equal: ELMEquivalent, library: ELM): EqualsFilter | InFilter | UnknownFilter; /** * Gets a list of codes in a CQL concept reference by name. These are returned as * FHIR Codings. * * @param name Name of the concept. * @param library The library elm the concept should be found in. * @returns A list of codings in the concept */ export declare function getCodesInConcept(name: string, library: ELM): fhir4.Coding[]; /** * Parses an ELM equal expression into a filter. This currently only handles checks against literal values. * * @param equal The equal expression to be parsed. * @returns Filter representing the equal filter. */ export declare function interpretEqual(equal: ELMEqual, library: ELM): EqualsFilter | UnknownFilter; /** * Parses an `IncludedIn` clause to a simpler filter representation. Currently handles comparisons to the * "Measurement Period" parameter. * * @param includedIn IncludedId expression to be parsed. * @param library The library the expression resides in. * @param parameters The original parameters used for calculation. * @returns Filter representation of the IncludedIn clause. */ export declare function interpretIncludedIn(includedIn: ELMIncludedIn, library: ELM, parameters: any): DuringFilter | UnknownFilter; /** * Parses a `in` expression. This may seen in CQL as 'during'. This can handle two situations. * - A value, such as a code, is checked to be if it's in a list of literals. ex. status in { 'complete', 'amended' } * - A time value is being checked if it is during a calculated interval. Usually based on "Measurement Period". * * @param inExpr The `in` expression to parse. * @param library The library the expression resides in. * @param parameters The parameters used for calculation. * @returns Filter representation of the In clause. */ export declare function interpretIn(inExpr: ELMIn, library: ELM, parameters: any): Promise; /** * Calculates an ELM expression that creates a CQL Interval using the cql-execution engine. * This is used to create the periods that are based on the "Measurement Period". * * @param intervalExpr ELM Interval Expression to execute. * @param library The library it belongs in. This is needed to identify parameters. * @param parameters The execution parameters. * @returns A FHIR Period like structure with start and end of the calculated interval. */ export declare function executeIntervalELM(intervalExpr: ELMInterval, library: ELM, parameters: any): Promise; /** * Parses a `GreaterOrEqual` expression. This can handle one situation at the moment. * - A time on a source attribute is expected to happen after the patient's Nth birthDate. * ex: Global."CalendarAgeInYearsAt"(FHIRHelpers.ToDate(Patient.birthDate), start of Global."Normalize Interval"(HPVTest.effective)) >= 30 * * @param greaterOrEqualExpr The GreaterOrEqual expression to interpret. * @param library The library it belongs in. This is needed to identify parameters. * @param parameters The execution parameters. * @param patient The patient we are executing for. This is where the birthDate is fetched if referenced. * @returns Filter representation of the GreaterOrEqual clause. This will be Unknown, During, or Value depending on if it can be parsed or not. */ export declare function interpretGreaterOrEqual(greaterOrEqualExpr: ELMGreaterOrEqual, library: ELM, patient?: CQLPatient): AnyFilter; /** * Parses a `Greater` expression. Currently used as a wrapper for interpretComparator but may become more robust if functionality * specific to 'Greater' expressions is needed * @param greater The Greater expression to interpret. * @param library The library it belongs in. This is needed to identify parameters. * @returns Filter representation of the Greater clause. This will be Unknown or Value depending on if it can be parsed or not. */ export declare function interpretGreater(greater: ELMGreater, library: ELM): ValueFilter | UnknownFilter; /** * Parses a `Less` expression. Currently used as a wrapper for interpretComparator but may become more robust if functionality * specific to 'Less' expressions is needed * @param less The Less expression to interpret. * @param library The library it belongs in. This is needed to identify parameters. * @returns Filter representation of the Less clause. This will be Unknown or Value depending on if it can be parsed or not. */ export declare function interpretLess(less: ELMLess, library: ELM): ValueFilter | UnknownFilter; /** * Parses a `LessOrEqual` expression. Currently used as a wrapper for interpretComparator but may become more robust if functionality * specific to 'LessOrEqual' expressions is needed * @param lessOrEqual The LessOrEqual expression to interpret. * @param library The library it belongs in. This is needed to identify parameters. * @returns Filter representation of the LessOrEqual clause. This will be Unknown or Value depending on if it can be parsed or not. */ export declare function interpretLessOrEqual(lessOrEqual: ELMLessOrEqual, library: ELM): ValueFilter | UnknownFilter; /** * Default code for parsing a miscellaneous comparator expression * @param comparatorELM The elm comparator expression to interpret. * @param library The library it belongs in. This is needed to identify parameters. * @param comparatorString a string determining the type of comparator passed into the function * @returns Filter representation of the comparator clause this will be Unknown or Value depending on if it can be parsed or not. */ export declare function interpretComparator(comparatorELM: ELMComparator, library: ELM, comparatorString: ValueFilterComparator): ValueFilter | UnknownFilter; /** * Map an EqualsFilter or InFilter into a FHIR DataRequirement codeFilter * * @param filter the filter to translate * @returns codeFilter to be put on the DataRequirement */ export declare function generateDetailedCodeFilter(filter: EqualsFilter | InFilter, dataType?: string): fhir4.DataRequirementCodeFilter | null; /** * Map a during filter into a FHIR DataRequirement dateFilter * * @param filter the "during" filter to map * @returns dateFilter for the dateFilter list of dataRequirement */ export declare function generateDetailedDateFilter(filter: DuringFilter): fhir4.DataRequirementDateFilter; /** * Map a filter into a FHIR DataRequirement valueFilter extension * * @param filter the filter to map * @returns extension for the valueFilter list of dataRequirement */ export declare function generateDetailedValueFilter(filter: Filter): fhir4.Extension | GracefulError; /** * Given a fhir dataType as a string and an attribute as a string, returns the url which outlines * the code system used to define the valid inputs for the given attribute for the given dataType * @param dataType * @param attribute * @returns string url for code system */ export declare function codeLookup(dataType: string, attribute: string): string | null; /** * Take any nesting of base filters and AND filters and flatten into one list * * @param filter the root filter to flatten * @returns a list of all filters used by this query at one level */ export declare function flattenFilters(filter: AnyFilter): AnyFilter[];