Charlie from Imagine
09/14/2023, 7:49 PMCharlie from Imagine
09/14/2023, 7:49 PMrahul1
09/14/2023, 9:14 PMPatient *- If your client is first making the RelatedPerson, and then populating Patient.link, you could establish the convention that the caregiver does not have access until the Patient.link is established. There would still be still be a small window where the caregiver does not have access, until the bot has completed executing, but it should be on the order of milliseconds. Conversely on removal, there were would be a brief window where the caregiver retains access before the bot has completed. You can actually subscribe to changes to only changes on the Patient.link element by using Expression Based criteria (https://www.medplum.com/docs/subscriptions/subscription-extensions#expression-based-criteria)
2.* Subscribe to RelatedPerson *- Option will not cover the case where RelatedPerson.patient is modified. This is uncommon, because what you're saying is that the caregiver retains the same relationship, but to a different patient (e.g. Marge is the mother of Lisa -> Marge is the mother of Bart). Typically, you would create a new RelatedPerson for this. A more realistic example, is when customer service fixes clerical errors in the RelatedPerson (e.g Marge is the mother of Lisa -> Marge is the Foster Mother of Lisa). Depending on how this affects access, you may want to listen to these changes
3. Subscribe to both RelatedPerson and Patient.link - If you need to cover both changes in #1 and #2. You can have 2 subscriptions point to the same Bot. In that case, you can treat the type of event.input as Patient | RelatedPersonrahul1
09/14/2023, 9:14 PM$execute endpoint (https://www.medplum.com/docs/api/fhir/operations/bot-execute) to trigger the Bot as a normal REST endpoint. In this case, your bot could:
a. Create the RelatedPerson.
b. Update the patient link
b. Update the access policy
And in reverse:
a. Remove the access policy
b. Update the patient link
b. Remove the RelatedPerson
This way the Bot can enforce the sequence of the access change.
You can go one step further by adding all 3 of these operations to a Bundle, to have the medplum server execute them all inside a single requestCharlie from Imagine
09/15/2023, 3:20 PMrahul1
09/15/2023, 4:15 PMCharlie from Imagine
09/15/2023, 5:01 PMrahul1
09/15/2023, 5:02 PMrahul1
09/15/2023, 5:02 PMCharlie from Imagine
09/15/2023, 5:03 PMrahul1
09/15/2023, 5:05 PMRun as user. If it is set to true, then it uses the caller's access token and only has access to what the caller has access to.
- Bots also have ProjectMemberships, just like Users. So you can set an arbitrary access policy directly onto the Bot that is not correlated to the calling userCharlie from Imagine
09/15/2023, 5:06 PMCharlie from Imagine
09/15/2023, 5:07 PMrahul1
09/15/2023, 5:07 PMProjectMembership resources by default, so they won't be able to modify their own access policies.
If you run as user, your Bot also won't be able to modify access polciesCharlie from Imagine
09/15/2023, 5:07 PMCharlie from Imagine
09/15/2023, 5:08 PMrahul1
09/15/2023, 5:26 PMCharlie from Imagine
09/15/2023, 5:31 PM