Stream: hapi
Topic: Select fields from two resources
Kishore Karanam (Aug 24 2021 at 06:42):
Hi All,
How do I query the Patient Phone number from Patient Resource along with the Appointment resource?. In case of _include, it returns whole resource, instead can't we get phone field as part of Appointment response?
I am looking for a response like below, selecting the fields from Patient and Appointment resources by joining patient id
select p.id, p.name, p.phone, a.starttime, a.endtime, a.practitioner from patient p, appointment a where p.patientid = a.patientid
Daniel Venton (Aug 24 2021 at 13:01):
Fhir doesn't define a way for you to retrieve attributes independent of the resource that contains them, you only query resources, you only _include resources. You can query by the value of an attribute, but you don't retrieve an attribute. (Unless you dive into custom operations where you define the return fields, Attribute X from Resource A, Attribute Y from Resource B....).
Let's take that scenario, You get a list of Appointments for the day and the phone number of the patient. When your desk person calls the patient, who do they ask for if they only have the phone number available? FHIR is a sip protocol, you only retrieve the data at the time you need it. Retrieve the list of appointments, If you need Patient data (to put on the screen, print a signin roster, call to reschedule) retrieve the pt resource at that moment.
Kishore Karanam (Aug 24 2021 at 13:24):
Hm..I have a requirement to show the list of appointments with "Patient Name" and "Phone Number" together on the screen ( attached the screen). We can retrieve the Patient name from Subject -> Display Name, but the phone number will be residing in the Patient resource. As per your suggestion, if we click on the appointment and then call the patient resource to show the phone number will be a lengthy process.
Do we have any other solution out of the box to achieve the same?
Daniel Venton (Aug 24 2021 at 14:26):
The patient resource is not a large resource. If you think it is too lengthy to retrieve a single resource JIT, and too large a data lift to retrieve the whole Patient resource when you retrieve the Appointment resource, then you are going to have to do something custom. Whether that is a custom operation or a custom extension to hold the list of pt phone numbers on the Appointment resource. Personally I think you need to retrieve the full patient resource (either JIT or pre-load). If you go down the route of customization, you are going to be customizing forever. 1) Personally I don't trust that the reference.display is always populated. 2) tomorrow they'll want the gender, do you add another extension to appointment to hold pt gender? 3) Day after, they'll want pt birthdate, is that another custom extension? 4) Next week, they'll want the gender pronouns, another custom extension? 5) Oh wait, the pt is a minor, we need an extension to hold the Parents names, genders, pronouns too... How many extensions do you add before it would've been easier just to _include the Patient (and minor RelatedPerson) resource(s)?
SQL server lets you take nibbles, just the attribute(s) you want. Base FHIR is bite sized chunks. If you want nibbles you are into custom land.
Kishore Karanam (Aug 24 2021 at 15:03):
Yaah true and make sense. Just a final question, can we get each appointment along with the patient associated in the single entry? As of now when I use _include, I am getting first appointments and then a list of patients. If I get each "Apppintment+Patient" as a single entry, it will be helpful to parse and show, otherwise will have to iterate and parse.
If this is possible, please provide an example for the same so that it helps alot.
Daniel Venton (Aug 24 2021 at 18:47):
Each entry in a bundle can only contain 1 resource (or other info, but never 2 resources).
John Silva (Aug 25 2021 at 15:29):
The _include option seems to be the way to go since it's FHIR standard. Not sure but it seems like code (an associative array/dictionary) can be used to link each Appointment with the Patient resources that are returns in the bundle.entry[] array.
Last updated: Apr 12 2022 at 19:14 UTC