Description
To enable for patients to register their own visits via a terminal at a clinic, there are a few Webdoc REST API endpoints available that can be utilized to fulfill this self-service.
This tutorial describes the chain of API calls necessary to fulfill a patient visit registration with a created invoice via an arrival terminal at a clinic - in the context of Webdoc (WD). Furthermore, the authorization necessary through this flow is based on the "OAuth 2.0" protocol.
All in all, the REST API endpoints included in this context flow are the following:
-
GET /v1/clinics
(Get an available clinic ID needed in the later request to get clinic bookings.) -
GET /v1/clinics/{clinicId}/bookings?personalNumber=19121212-1212&date=2024-01-11&selfService=true
(Get a clinic patient booking related to a booking type configured for "self-service".) -
POST /v2/visits
(Register a patient visit based on a patient booking.) -
POST /v1/clinics/{clinicId}/invoices
(Create an invoice based on the registered patient visit.)
Prerequisites
- API credentials must be configured in the WD auth server, such as a client ID along with a client secret and scopes, etcetera. These credentials will be setup and provided to you by Carasent.
- The grant_type "client_credentials" must be used in order to request a valid access token for this context.
- To fulfill the necessary API flow for the whole arrival registration using the same access token, the token must be based on the scopes: "clinics:read" and "self-service".
-
A patient booking has been created in Webdoc (either via the WD GUI or via the WD API
endpoint "POST Bookings").
Moreover, the booking needs to be based on a booking type configured for "self-service".
This can be configured via the WD GUI through the following steps:
- Login to Webdoc as a user with permissions to edit booking types and navigate to edit booking types via the WD menu option: "Administratör > Inställningar > [Bokningar] > Ange bokningstyper".
-
On the page to edit booking types with at least one booking type created, you can
then click on the cogwheel for the booking type you want to relate to "self-service".
In the dialog box that will open, you can then tick the "self-service" ("Självbetjäning")
checkbox to "Yes" and save the changes:
Workflow 1 - Steps to receive an access token for self-service registration
-
To issue an access token that can be used through the entire chain of API calls necessary to register a patient visit via an arrival terminal with a created invoice, the following API credentials can be used:
- Grant type: client_credentials
- Scopes: clinics:read, self-service
Furthermore, you need a client ID and client secret, which will be provided to you by Carasent. Below is an example of how this access token can be requested through CURL having <client_id> and <client_secret> replaced with your client ID name and client secret.
Example CURL - Request an access token for this context for your TEST environment:
curl -X \ POST -u "<client_id>:<client_secret>" \ -d "grant_type=client_credentials&scope=clinics:read%20self-service" \ https://auth-integration.carasent.net/oauth/tokenThe requested access token will then be returned in the following JSON format.
Example JSON response - Access token with multiple scopes:
{ "access_token": "dbc5051a41f22a70e43432c0db329cc80fbed103", "expires_in": 3600, "token_type": "Bearer", "scope": "clinics:read self-service" }Note! An issued access token is valid for one hour.
Workflow 2 - Steps to collect required data to register a patient visit via an arrival terminal with created invoice
-
Request clinic ID
Before you can get bookings from the clinic, you need to pass the clinic's ID (UUID) as a path parameter in the "GET Clinic Bookings" request. And once you have received a valid access token to get available clinics from Webdoc, you can request to get the clinic data via "GET Clinics" by attaching the token in an API request as in the below CURL example.
Example CURL request - Get clinics from your WD TEST environment with attached token:
curl https://api-integration.carasent.net/v1/clinics \ -H "Accept: application/json" \ -H "Authorization: Bearer dbc5051a41f22a70e43432c0db329cc80fbed103"As you can see in the below example response, the clinic IDs are returned in UUID format to the parameter "id". If you want to get bookings from the clinic named "Testmottagning", the ID to use for this would simply be "481c97c5-0bd7-4aff-aca2-71ce9003b613":
-
Request patient booking ID
Furthermore, using a valid access token to be able to get clinic bookings with the received clinic ID you want to get bookings from (via step 1), you can then request the bookings via "GET Clinic Bookings" by attaching the access token like in the below example request - having relevant query filters applied to narrow the request.
Example CURL request - Get patient bookings from a clinic via your WD TEST environment with attached token:
curl https://api-integration.carasent.net/v1/clinics/481c97c5-0bd7-4aff-aca2-71ce9003b613/bookings?personalNumber=19121212-1212&date=2024-01-11&selfService=true \ -H "Accept: application/json" \ -H "Authorization: Bearer dbc5051a41f22a70e43432c0db329cc80fbed103"As you can see in the below example response, the booking IDs are returned in UUID format to the parameter "id". Based on the applied query parameters for the patient with identity number "19121212-1212", a booking ID to use for this would be "4f107b4e-d016-40a3-b7c7-be95f3c481ac":
Workflow 3 - Steps to register a patient visit with created invoice based on booking
-
Register patient visit based on booking
Once the patient booking ID is collected (via workflow 2), you can then attach the booking ID in a request to create the patient visit via "POST Visit from booking" as in the below example request.
Example CURL request - Register visit arrival based on patient booking:
curl --location --request POST 'https://api-integration.carasent.net/v2/visits' \ --header 'Authorization: Bearer dbc5051a41f22a70e43432c0db329cc80fbed103' \ --header 'Content-Type: application/json' \ --data \ '{ "bookingId": "4f107b4e-d016-40a3-b7c7-be95f3c481ac", "visitDate": "2024-01-15" }'In a successful visit registration, you can then expect to get the registered visit data in the response, where you can re-use the returned visit ID ("id") and clinic ID to be passed in the latter request to create the invoice:
-
Create clinic invoice based on registered patient visit
Once the patient visit is registered, you can finally create its invoice via "POST Invoice" as in the below example request.
Example CURL request - Create clinic invoice based on patient visit:
curl --location --request POST 'https://api-integration.carasent.net/v1/clinics/481c97c5-0bd7-4aff-aca2-71ce9003b613/invoices' \ --header 'Authorization: Bearer dbc5051a41f22a70e43432c0db329cc80fbed103' \ --header 'Content-Type: application/json' \ --data \ '{ "visitId": "869ccd39-b07c-11ee-ba70-d2e5e41d8a27", "totalPayment": "100" }'Once the invoice is successfully created in Webdoc, you can then expect to receive the created invoice data in the response. You can see an example of the expected JSON response structure via the "POST Invoice" endpoint documentation under "Example Response".