Support for _revinclude in graphql?
# support
y
Hi there! We're modeling caregiver->patient relationships in Medplum using Patient.link -> RelatedPerson -> Patient. @rahul1 provided us with some FHIR queries that we can use to go from Caregiver to Patient, and vice versa: Parent -> child
Patient?_id=[id]&_include=Patient:link&_include:iterate=RelatedPerson:patient
Child -> parent
Patient?_id=[id]&_revinclude=RelatedPerson:patient&_revinclude:iterate=Patient:link
The first one (Parent -> Child), we can implement in Graphql using the following:
Copy code
{
  Patient(id: $id) {
    link {
      other {
        resource {
          ... on RelatedPerson {
            id
            resourceType
            patient {
              resource {
                ... on Patient {
                  id
                  resourceType
                  ...BasePatientInfo
                }
              }
            }
            relationship {
              coding {
                code
                display
              }
            }
          }
        }
      }
    }
  }
}
However, we're struggling to query in the opposite direction, from a patient to see a list of their caregivers. Is this currently possible using the Graphql API?
c
Hi @yaaaaale - great question! I think this is what you're looking for?
Copy code
{
  PatientList(name: "simpson") {
    resourceType
    id
    name {
      given
      family
    }
    RelatedPersonList(_reference: patient) {
      resourceType
      id
      relationship {
        coding {
          code
          display
        }
      }
      PatientList(_reference: link) {
        resourceType
        id
        name {
          given
          family
        }
      }
    }
  }
}
(EDIT: Oops, the previous version was incorrect. This one correctly follows the link)
The special syntax is here:
RelatedPersonList(_reference: patient)
See: https://www.medplum.com/docs/graphql/basic-queries#searching-reverse-references-using-the-_reference-keyword
y
Perfect @cody , that's exactly what we were looking for. Thank you!
162 Views