Documented AccessPolicy for Multi-Tenant example d...
# support
s
Hi all, In the docs here https://www.medplum.com/docs/access/multi-tenant-access-policy#1-create-the-access-policy the AccessPolicy uses the criteria below for Practitioners however this returns
Unknown search parameter: organization
(self hosted server v4.4.1)
Copy code
{
  "resourceType": "Practitioner",
  "criteria": "Practitioner?organization=%current_organization"
}
Related to this, the docs also state Chained searches are not allowed. So what is the recommended criteria query for all Practitioners belonging to an Organization? And if this is best achieved by compartments, are there any examples anywhere? Or am I missing something simple here? Any help would be great! Thanks Simon
i
@simonj, this is interesting to hear. This did used to work but I think this exact pattern may be deprecated. Can you try this pattern instead?
Copy code
{
  "resourceType": "Practitioner",
  "criteria": "Practitioner?
_compartment=Organization/%current_organization"
}
s
Thanks for your reply @Ian Plunkett , unfortunately this does not work, and when I look at my project-scoped Practitioner (see below) there is no Organization compartment. Also below is the corresponding PractitionerRole. As I mentioned above, chained queries do work but the docs say not to use them, so it would be great to have an updated recommended implementation for the multi-tenant scenario. Goal: Practitioners in Organization Hospital A should only be able to see fellow Practitioners in Hospital A, not Hospital n
Copy code
{
  "resourceType": "Practitioner",
  "meta": {
    "project": "f6f0a5ac-f02e-426d-bd1c-3c78cd5d24f8",
    "versionId": "a708c7ee-fc68-406a-b9bc-99646aecbc0c",
    "lastUpdated": "2025-10-03T15:07:20.885Z",
    "author": {
      "reference": "system"
    },
    "compartment": [
      {
        "reference": "Project/f6f0a5ac-f02e-426d-bd1c-3c78cd5d24f8"
      }
    ]
  },
  "name": [
    {
      "given": [
        "GeneralPrac"
      ],
      "family": "GeneralPrac"
    }
  ],
  "telecom": [
    {
      "system": "email",
      "use": "work",
      "value": "general-prac@example.com"
    }
  ],
  "id": "d98fbbf2-a75f-4b4b-91cb-0840e18c9b57"
}
Copy code
{
  "resourceType": "PractitionerRole",
  "practitioner": {
    "reference": "Practitioner/d98fbbf2-a75f-4b4b-91cb-0840e18c9b57",
    "display": "GeneralPrac GeneralPrac"
  },
  "organization": {
    "reference": "Organization/1fe19c53-0d7e-4de2-9ba0-6a9e16fc263e",
    "display": "Hospital A"
  },
  "id": "f3b30c2d-588e-4270-b1bf-5e299a1a0305",
  "meta": {
    "versionId": "27ed0e7a-9714-410b-8735-fb5b2e9941b6",
    "lastUpdated": "2025-10-03T15:07:20.899Z",
    "author": {
      "reference": "ClientApplication/b32e12e7-95a7-4731-979c-8ce4f625d8f6",
      "display": "cmhq-dev-project Default Client"
    },
    "project": "f6f0a5ac-f02e-426d-bd1c-3c78cd5d24f8",
    "compartment": [
      {
        "reference": "Project/f6f0a5ac-f02e-426d-bd1c-3c78cd5d24f8"
      }
    ]
  }
}
f
Hi @simonj , for this type of design pattern where you compartmentalize your resources by Organization, I would recommend you take a look at [this blog post](https://www.medplum.com/blog/multi-tenant-mso) There is also a demo app [here](https://github.com/medplum/medplum-mso-demo) that shows how build this tenancy model
Copy code
{
  "resourceType": "Practitioner",
  "criteria": "Practitioner?
_compartment=Organization/%current_organization"
}
Will work if you call the [set-accounts](https://www.medplum.com/docs/api/fhir/operations/patient-set-accounts) operation on your Practitioner resources first, and pass
%current_organization
as a parameter on your AccessPolicy. All of this is explained in detail in that blog post
s
@finnbergquist thanks for the info - exactly what I was looking for! I was expecting
$set-accounts
to be used for billing and not access control which is why I may have missed it. Is the
$set-accounts
worth a mention at the "Multi-Tenant Access Control" docs page above along with removing the
Practitioner?organization=%current_organization
example? If so I can create a PR if that's helpful?
f
Sure, that would be awesome!
62 Views