nathan-watkins-unityai
05/16/2025, 9:32 PMOrganization compartment on a Task resource so that it could be used as a filter in a graphql query. It appears that was removed in [4.0.4](https://github.com/medplum/medplum/pull/6145) in favor of using the meta.accounts key to apply arbitrary compartments wherever the [patient compartment](https://hl7.org/fhir/R4/compartmentdefinition-patient.html) is also applied. Since `Task`s don't have an inclusion criteria for the patient compartment, is there a recommended way to achieve the same functionality? If I recall correctly, we had at one time used _tag as a filter for graphql queries but noticed relatively slow performance. Memory of that is a bit hazy though.finnbergquist
05/16/2025, 10:28 PMR4/Task/123 PUT
{
"resourceType": "Task",
"status": "accepted",
"intent": "unknown",
"id": "123",
"meta": {
"project": "123",
"compartment": [
{
"reference": "Project/123"
}
],
"accounts": [
{
"reference": "Organization/123"
}
],
//...
}
and then that Organization will be added to meta.compartment
Please let me know if I am wrong here, but I assume that the ideal behavior for you would be for you to add the Organization to the compartment of the Patient, and then it automatically updates all the compartment of the resources in the [patient compartment ](https://hl7.org/fhir/R4/compartmentdefinition-patient.html).
Then, you could manage the compartments for all the other resources by just updating the Patient, and your queries would all look the same:
await medplum.searchResources('<ResourceType>', {
_compartment: 'Organization/<your-org-id>',
});
This is currently achievable for all the resources in the Patient's compartment definition using the patient [$set-accounts](https://www.medplum.com/docs/api/fhir/operations/patient-set-accounts) operation.
As you noted, unfortunately, the Task resource is not in the Patient compartment definition. Interestingly, it did get included in the [Patient R5 CompartmentDefinition](https://hl7.org/fhir/R5/compartmentdefinition-patient.html), so this must be a use case that others have come across. In the future, this is something we could add to the automatic propagation.nathan-watkins-unityai
05/16/2025, 10:43 PM$set-accounts operation always have to be called to propagate a patient's accounts -> compartments? Or is that for retroactively applying them? In other words, if the Patient.accounts is populated with an Organization reference (for example), do subsequently created resources within the compartment definition automatically add it to the compartments or only after the $set-accounts operation is run?finnbergquist
05/16/2025, 10:55 PMfinnbergquist
05/16/2025, 10:58 PMfinnbergquist
05/16/2025, 11:00 PM