Advanced filters and requests
# support
t
Hello everyone, I'm wondering what would be the strategy you'd recommend if you would like to implement advanced filters in Medplum. Let me explain : We have grids with all our patients. In this grid we have columns in which we display values coming from the extensions or status of a resource linked to the patient but not stored directly in the patient. With the Medplum API, we did not find any ways to have an easy way of adding filtering on these kind of values. What we thought at the moment is to have a database on which we would copy all data we want to query on, do our SQL queries directly on this independant database and then do a Medplum call on all the IDs that have been extracted from our query. What do you think ? Do you already had similar strategies ? Thank you.
a
Hey @thomabig! So for the situation where you need to filter on the
status
field of a linked resource, you should be able to use the
_has
chained search, as that allows you to filter Patients based on properties of resources that reference them. More details on using
_has
can be found [here](https://www.medplum.com/docs/search/chained-search#reverse-chained-search). As for the extension issue–what specific values are you querying on within the extension field? This would impact the best solution.
t
Hi Andy. My understanding is that chained search doesn't work with GraphQL. Maybe it has changed during last year. Let me give you some examples. Example 1 : Patient listing. In the patient listing we retrieve data from a GraphQL query looking like (graphql_patient.query). I would love to have the possibility for example to sort per date of last recording (stored in Procedure). But at the moment I don't see a way to do so. My choices : - Add an extension in Patient : lastRecordingDate and be able to sort or filter on it - Create an external database to store this kind of informations to sql query and retrieve patientIds in the correct order. Example 2 : In our planification view, we want to have the possibility to filter patients to only display patients that are "URGENT". The URGENT patient are defined in an extension with sub extensions. And we don't know how to filter on this. This is why we wanted to add a new proxy which would allow us to handle sql query on what we actually want to query. Sometimes the FHIR standard is missing use cases and we don't know yet how to work without them. Thank @Andy https://cdn.discordapp.com/attachments/1502426866064035870/1503742530607382639/image.png?ex=6a0474dd&is=6a03235d&hm=206b02d8f25dfe0d8add2794eab3f7aab6e8dcd6b94dca15df5d613634f3eaaf& https://cdn.discordapp.com/attachments/1502426866064035870/1503742530829946880/graphql_patient.query?ex=6a0474dd&is=6a03235d&hm=5ac5644467bd4d3273e7b31ee01ce6a006e1ee1b2658a25bfa3807559fb3b32a& https://cdn.discordapp.com/attachments/1502426866064035870/1503742531307831427/image.png?ex=6a0474dd&is=6a03235d&hm=cc7944cc467e458ab28066a1d0c903a8ec0578c7553318eb270e3093f24c2c62&
a
Okay, I didn't realize you were using GraphQL! You are correct that you can't do chained searches in the same way. However, you should be able to use
_filter
and construct a query that accomplishes something similar to
_has
using search parameters, though it'll be a bit more involved to write up the logic. As far as your question about external DB use–this might work, but it sort of defeats much of the purpose of using Medplum as a compliant data store. I would say this should be a last resort move (if it comes to this, we have some data warehouse work in progress that might make the porting of data a bit easier). With that being said, here are two alternative options for your two examples: **Example 1**–Run the same query you sent along, sorting the Procedure resources by
_lastUpdated
, but also add a limit to the count so that you're not getting every procedure returned to the client. Then perform client side sorting on the
lastUpdated
field. This will require you to retrieve all Patient records at once, so client side operations could become tough if you're working with thousands of patients. Example 2-Use the
meta.tag
field to store whether it's URGENT or not within the patient. This allows you to filter directly on the Patient resource using the
_tag
filter. If the extension you mentioned lives on the patient resource, you could accomplish this by simply adding the field wherever you create your Patient resources. However, if it's in an extension of another resource, you'll want to setup a Bot + Subscription to make updates to the Patient's
meta.tag
anytime that resource or value changes. You'll also have to update this on past Patient resources retroactively. I hope this helps!
17 Views