Fhirpath.pg
Why fhirpath?
To search though jsonb resources in database sometimes you need to access deeply nested attributes by specific criteria. For example to search patient by official name you have to do something like this:
Here is the version with fhirpath:
Implement FHIR search with fhirpath
Having fhirpath in your database also is very handy to implement FHIR Search API. In FHIR SearchParameters are described by fhirpath expressions. For example for Patient we have following search parameters:
Name
Type
Expression
active
Patient.active
address
Patient.address
address-city
Patient.address.city
address-country
Patient.address.country
address-postalcode
Patient.address.postalCode
address-state
Patient.address.state
address-use
Patient.address.use
animal-breed
Patient.animal.breed
animal-species
Patient.animal.species
birthdate
Patient.birthDate
death-date
Patient.deceased.as(DateTime)
deceased
Patient.deceased.exists()
Patient.telecom.where(system='email')
family
Patient.name.family
gender
Patient.gender
general-practitioner
given
Patient.name.given
identifier
Patient.identifier
language
Patient.communication.language
link
name
Patient.name
organization
phone
Patient.telecom.where(system='phone')
phonetic
Patient.name
telecom
Patient.telecom
With FHIR search there is one tricky moment - most of expressions return complex types like HumanName or Identifier, which is not easy to search by SQL. So fhirpath provides specialised function to output search friendly results:
Invariants with fhirpath.pg
With fhirpath we can create invariants as PostgreSQL Constraints. Let's add a check that all patients have SSN number:
Now when you will try to add patient without SSN - you will see an ERROR:
Last updated