Got feedback or spotted a mistake?

Leave a comment at the end of this page or email contact@krishagni.com

External App Messages API

Purpose

The purpose of this document is to explain the APIs exposed by OpenSpecimen for consuming the external application messages. The external apps like the HL7 based system can submit their messages to OpenSpecimen APIs for patients, visits registration etc

General Characteristics

  1. The APIs will be exposed over HTTPS endpoints using TLS 1.2/1.3 and secure ciphers.

  2. Only authenticated and authorized users can invoke the respective APIs.

  3. The APIs can be invoked only from whitelisted IP addresses.

  4. Throttling will be implemented to avoid DDoS.

  5. HSTS header will be enabled to ensure the API is accessed using only HTTPS.

  6. Only JSON messages (request / response) will be exchanged between the client and OpenSpecimen.

Workflow

The typical workflow involves 3 steps a) Authentication b) Sending Messages and c) Logout as illustrated in the following chart:

Authentication

Sending applications can sign-in to OpenSpecimen by invoking the sessions API with valid credentials:

Method

POST

Endpoint

/rest/ng/sessions

Headers

Content-Type: application/json Accept: application/json

Body

{ "loginName": <valid_login_name>, "password": <secret_password> }

Response

HTTP 200 OK Content-Type: application/json Body: { "token": <session_token> }

The sending application will use an API user provisioned in the OpenSpecimen database. This will ensure the APIs can be invoked only from pre-determined, whitelisted IP addresses.
The login name and password of the API user will be shared with the sending application.

On successful authentication, the sending application will receive an HTTP 200 OK response along with an unique session token. The session token should be used in subsequent API calls to OpenSpecimen.

Send Messages

The sending applications can send one message at a time or send messages in a batch. The latter option is preferred, as it avoids the overhead involved with making HTTP requests. For example, the sending application can send messages in batches of 100. This is much faster/efficient than sending one message at a time.

Method

POST

Endpoint

/rest/ng/external-app-messages

Headers

Body

Response

OpenSpecimen will accept all the messages and persist them in its local queue for processing. OpenSpecimen acknowledges the receipt of messages with an unique transaction ID.

The API will generate an error response only when the request body is malformed or the protocol is not recognised by OpenSpecimen.

The messages are processed by OpenSpecimen asynchronously. This means the sender will not be blocked for a long time. To put another way, the sender will be blocked only for the time required by OpenSpecimen to parse the incoming JSON message and persist in its local queue.

Logout

When the sending application is done with sending messages, it can invoke the signout/logout API to terminate the session with OpenSpecimen.

Method

DELETE

Endpoint

/rest/ng/sessions

Headers

Body

Response

After this the token can no longer be used for sending the messages.

Errors

All the client errors will be responded with HTTP 4xx response messages. The response body includes the actual error.

HTTP 401

Invalid session token or no session token header

HTTP 400

Invalid input / request or malformed message

Body

All the OpenSpecimen related errors will be responded with HTTP 503 response messages.

Examples

Sign-in

Method

POST

Endpoint

https://test.openspecimen.org/rest/ng/sessions

Headers

Body

Response

Sending Messages

Method

POST

Endpoint

https://test.openspecimen.org/rest/ng/external-app-messages

Headers

Body

Response

Logout

Method

DELETE

Endpoint

https://test.openspecimen.org/rest/ng/sessions

Headers

Body

Response

Examples using cURL

Sign-in
Sending Messages
Sign-out

 

Got feedback or spotted a mistake?

Leave a comment at the end of this page or email contact@krishagni.com