View raw Markdown
type: fhirpath-functionfunction: pathnamecategory: Utility functionssection: 5.10.2source: fhirpath/functions.json

FHIRPath Function: pathname

{:.stu}

Note: The contents of this section are Standard for Trial Use (STU) {: .stu-note }

Returns the direct path of each item of the input collection within the input resource (%rootResource in FHIR implementations), using only element names and indexers. Such that if you used that result on the input resource, you would get that node, and only that node. {:.stu}

If an item in the input collection was derived from computation (e.g. via substring(..), &, or mathematical operations) rather than navigation it is excluded from the result. Items that are outside the input resource, such as those navigated to via resolve() are also excluded from the result, however if resolve() references a resource contained within the input Resource then it is included (such as with FHIR bundles, or contained resources). {:.stu}

The optional short parameter permits excluding array indexers if an element is known to not be an array, either in the model, or in the specific instance at runtime. {:.stu}

If the input collection is empty ({ }), the result is empty. {:.stu}

This function could be used to populate fields in a FHIR OperationOutcome.issue.expression field, or assist in debugging complex expressions using it in conjunction with trace. {:.stu}

For example, validating a FHIR QuestionnaireResponse (against a Questionnaire) could use the following expression to calculate the location of an invalid answer: {:.stu}

item.item.item.where(linkId = 'i508').item.where(linkId='i534').answer.value.pathname()

{:.stu}

would return the following string (which is also a valid fhirpath expression) if only 1 node was at that location in the input QuestionnaireResponse. {:.stu}

'QuestionnaireResponse.item[2].item[8].item[1].item[1].answer[0].value[0]'

{:.stu}

Another example could be the FHIR Observation invariant obs-7 that roughly checks if components are duplicating codings captured at the top level: (not an exact copy of the invariant, but a part of it) {:.stu}

// trace out the pathname of the components that have duplicated codings
component.code.where(coding.intersect(%resource.code.coding).trace('component', pathname()).exists()).empty()

{:.stu} would return the following strings: (simplifying finding the specific component(s) that were duplicated) {:.stu}

'Observation.component[0].code[0].coding[0]'
'Observation.component[23].code[0].coding[0]'

{:.stu}

Summary

Description

Returns the direct path of each element of the input collection within the input resource, using only element names and indexers. If an element was derived from computation rather than navigation it is excluded from the result. Elements outside the input resource are also excluded, unless they are contained resources.

Arguments

Type Mapping

Example

item.item.item.where(linkId = 'i508').item.where(linkId='i534').answer.value.pathname()
// 'QuestionnaireResponse.item[2].item[8].item[1].item[1].answer[0].value[0]'