When creating users we first create the Keycloak user via the Keycloak api and then create several FHIR resources for the same user via the FHIR api. Some times one api is available while the other is not leading to incomplete tasks.
This PR is trying to cover some of the edge cases
The edge cases considered are:
no user exists in Keycloak with the provided username and email, no Practitioner id provided -> create user in Keycloak and necessary FHIR resources, generate uuid for Practitioner
no user exists in Keycloak with the provided username and email, Practitioner id provided -> check that not Practitioner exists with provided id. If found log error and exist, otherwise create user in Keycloak and necessary
a user exists in Keycloak with the same username but different email -> log error and exit
a user exists in Keycloak with the same email but different username -> log error and exit
a user exists in Keycloak with the same username and email, Practitioner id is not provided, and a Practitioner resource does not exist -> create Practitioner and other linked FHIR resources
a user exists in Keycloak with the same username and email, Practitioner id is provided, but a Practitioner resource does not exist -> create Practitioner and other linked FHIR resources
a user exists in Keycloak with the same username and email, Practitioner id is provided, a Practitioner resource also exists with a secondary identifier same as the Keycloak user -> do nothing, exit
a user exists in Keycloak with the same username and email, Practitioner id is provided, a Practitioner resource also exists but with a secondary identifier different from the Keycloak user -> log error and exit
a user exists in Keycloak with the same username and email, Practitioner id is not provided -> Search for practitioner with keycloak user_id, if exists exit, if doesn't exist, create
IMPORTANT: Where possible all PRs must be linked to a Github issue
Fixes https://github.com/onaio/fhir-tooling/issues/49
When creating users we first create the Keycloak user via the Keycloak api and then create several FHIR resources for the same user via the FHIR api. Some times one api is available while the other is not leading to incomplete tasks. This PR is trying to cover some of the edge cases
The edge cases considered are: