Esempio n. 1
0
def evaluate(resource, path, context={}, model=None):
    """
    Evaluates the "path" FHIRPath expression on the given resource, using data
    from "context" for variables mentioned in the "path" expression.

    Parameters:
    resource (dict|list): FHIR resource, bundle as js object or array of resources This resource will be modified by this function to add type information.
    path (string): fhirpath expression, sample 'Patient.name.given'
    context (dict): a hash of variable name/value pairs.
    model (dict): The "model" data object specific to a domain, e.g. R4.

    Returns:
    int: Description of return value

    """
    node = parse(path)
    return apply_parsed_path(resource, node, context, model)
Esempio n. 2
0
def compile(path, model=None):
    """
    Returns a function that takes a resource and an optional context hash (see
    "evaluate"), and returns the result of evaluating the given FHIRPath
    expression on that resource.  The advantage of this function over "evaluate"
    is that if you have multiple resources, the given FHIRPath expression will
    only be parsed once.

    Parameters:
    path (string) - the FHIRPath expression to be parsed.
    model (dict) - The "model" data object specific to a domain, e.g. R4.

    For example, you could pass in the result of require("fhirpath/fhir-context/r4")
    """
    node = parse(path)

    def func(resource, context={}):
        return apply_parsed_path(resource, node, context, model)

    return func
Esempio n. 3
0
def parse_non_valid_test():
    with pytest.raises(LexerNoViableAltException):
        parse("!")
Esempio n. 4
0
def output_correct_ast_test(expression):
    assert are_ast_equal(parse(expression), load_ast_fixture(expression))
Esempio n. 5
0
def parse_valid_test(expression):
    assert parse(expression) != {}