Implement login for patients from different projec...
# support
t
Hello. I 'm trying to implement a custom practitioner portal, where any practitioner could log in from there and see the resources of their projects (app.medplum.com currently works in this way). What would be the recommended flow? On the other hand, we have a react native application for patients and we have a similar case. Patients from different projects should be able to log in from the same application. I'm not sure if creating a client with super admin access would be useful to implement something like this, possibly not (besides some security issues). Do you have any recommendations, examples or documentation that could be useful? Thank you very much in advance.
p
Hi @tinho_14 ,as far as I know, I think you can create Project from super admin with required Access policies, and within that you can create clients. These client credentails you can use inside web and mobile app with defined policies. Also add patients/practiioners within this project with granular access policies. Hope it helps.
t
Hello @pravinu , thanks for your response. I think I've solved the authentication for the web portal for practitioners. However, I still have issues in the mobile app. I was testing the OAuth2 flow but the clients that I create in the super admin project only see patients within the scope of the project, for any other patient it returns "user not found".
@rahul1 could you please help me? I'm not sure what approach I should follow. I guess I could use auth0 and implement SSO so that patients from different projects can log in. Is there a way to make patients server-scoped and be able to use the login in a similar way to practitioners? Sorry for the inconvenience but I'm stuck here and I need clarifications before continuing with the development. thanks in advance!
r
Hi @tinho_14 , the best reference I can point you to is our
SignInForm
react component: https://github.com/medplum/medplum/blob/main/packages/react/src/auth/SignInForm.tsx. Specifically here, we show a "ChooseProfileForm" when a Login results in multiple ProjectMemberships: https://github.com/medplum/medplum/blob/main/packages/react/src/auth/SignInForm.tsx#L131-L132
I strongly recommend creating any SuperAdmin clients for this workflow
For patients, the server does automatically create Patient Users as project-scoped, as that is the typical use case. A super admin can manually change this by removing the
User.project
field, but this is not recommended. What is the use case for having patients in multiple projects?
t
@rahul1 In our business, we can have several practices (one per project), where each one has a set of users/practitioners and its own resources. Practitioners can manage medications/medicationRequests and observations from the web portal, on the other hand, patients can view their medications, prescriptions, track, etc. from a react native mobile app. Since the mobile application is the same for all patients, even when they are from different projects, we cannot have a single client id for all of them. I understand that by default patients are project-scoped and, although this restriction makes sense, it's not helpful in our use case.
r
@tinho_14 given the desire to share patients across projects, as well your previous question regarding global resources, it seems like
Projects
are not the best way to model the isolation between your clinics. This might better be accomplished via access policies
t
@rahul1 We would like to replace our backend with medplum. In our first version the medications were global, however we have no problems adapting this to the medplum model (at this point we will go with that approach). We don't need to share patients between projects, just find a simple and secure way to be able to log in for patients, without having to specify a client id in our mobile app.
r
(forgot to include this in my previous message) The "Healthcare Partnerships" access policy example here: is probably the best example of separating patients by Organziation https://www.medplum.com/docs/access/access-policies#example-access-policies
> just find a simple and secure way to be able to log in for patients For this, does the username / password flow suffice?
t
@rahul1 yes, totally. The application will have the classic login form with username and password. that would be enough
@rahul1 Thank you for your help and your quick response, let me know if you have any ideas on how to implement this scenario. I'd like to know if you have any type of paid personalized support.
r
@tinho_14 my best advice would be to study the implementation of the "AuthenticationForm". While this component has a bit more complexity than you need, the key call it makes is the
startLogin
call: https://github.com/medplum/medplum/blob/main/packages/react/src/auth/AuthenticationForm.tsx#L142-L151
This is the simple un/pw authentication flow for Medplum
And yes, we do offer paid support! In our enterprise plan, we offer a shared slack channel as well as training workshops https://www.medplum.com/pricing
t
@rahul1 thanks, I'll take a look