access policy on subscription
# support
c
Hi @rahul1 @finnbergquist , we are adding accesspolicy restrictions and recognized out subsctions failing our subscription currently looks like this
Copy code
medplum.subscribeToCriteria(
    `Communication?subject=${groupRef}`
  );
and out AccessPolicy has something like this
Copy code
{
      "resourceType": "Subscription",
      "criteria": "Subscription?type=websocket"
    },
here the group ref is a bit complicated, two groups are created for each user with Group.name=chat- and Group.name=chat- to identify the chats and notifications per user . could you pls help us with appropriate criteria for this .
f
Hello @charithv 👋 , Was the Subscription working as expected before you added the AccessPolicy?
c
Yes
f
Ok, got it. I will investigate
I think that criteria should work. Can you send the whole AccessPolicy?
c
f
Can you double check that { "resourceType": "Communication", "criteria": "Communication?_compartment=%patient", "readonly": false }, criteria is met. You can look in the communication resource and confirm that the patient reference is in the compartment field
I tested out
Copy code
{
      "resourceType": "Subscription",
      "criteria": "Subscription?type=websocket"
    },
and was able to get that to work fine
for both creating and consuming websocket subscription
c
Hi @finnbergquist , thanks for noticing the communication criteria we will fix that. i am noticing something weird with the Subscription. the WS get fired when i send message or message get's updated but when someone sends the message on same topic i dont get any WS fired . is there anyhting that you see missing here ?
f
Hmm, I wonder if it has something to do with your* Communication?subject=${groupRef}* criteria. Is your reason for creating two different web-sockets so that you can process notifications and new messages separately? I think the first step to debug is inspect your browser and confirm that the Subscription resource that is created contains the expected criteria. And if that is correct, double check that the new Communication resource should match that criteria.
Is this chat Provider <> Patient or Provider <> Provider?
Hey @charithv, just checking in here. Is this still an outstanding problem?
If you are able to invite me to your dev project, I am happy to help debug further
c
Hi Finn. aplogies for late response. yes we use two subscriptions one for Chat messages b/w patient and provider and another for in-app automated notifications . i will debug further today and if i am unable to i will send you an invite and we could debug together . Thank you Finn.
f
OK sounds good @charithv !
c
Hi @finnbergquist i have invited you
finn@medplum.com
as practitioner on our staging env and assigned you a access policy https://app.medplum.com/AccessPolicy/3461237b-27a5-4efe-90c4-6919a2e1417c to reproduce you can try to play with create a subscription on
Communication?subject=<Group ref >
f
Hey @charithv, ok sounds good. I will take a look
c
Thank you Finn!
f
Hey Charith, I was able to set up a test that got the websockets to fire when the Communication resources met the Communication?subject= criteria, regardless of who the sender was. I am not quite sure what more I can do to help debug unless you give me more information about your FE code. Can you send the payload you see in the network for
Copy code
https://api.medplum.com/fhir/R4/Subscription
Request Method:
POST
and also the JSON for a Communication resource that you did not receive a webhook for. One other thought I had. Can you make sure that the people in the chat have access to the Group and Communication resources in their AccessPolicies
c
Hi Finn , This is in our mobile app that we are facing this issue let me send you the payloads and all in detail today
Hi Finn, the access policy was the problem as you suggested the communication compartment seems to be the issue .
the messages sent by Practitioner does not have patient in compartment of communication seems like that was effecting it . but the searchResources was showing all resources .
i made a change in subscription like this specifically for communication
Copy code
{
      "resourceType": "Communication",
      "criteria": "Communication?recipient=%profile"
    },
    {
      "resourceType": "Communication",
      "criteria": "Communication?sender=%profile"
    },
f
Nice! Glad you were able to get this working
Using %profile is a good way to do this
749 Views