Upload Practitioners and Organizations via CSV files

This feature will allow bulk import and will be used when migrating data from the teams module on OpenMRS for current production systems.

Organizations and Organization Locations

This assumes that the organizations will be loaded from DHIS2, CGR, or other sources and organized into a CSV file. The second step would be to run a POST request with the CSV file as an input to the REST API.

Following are the details of the API:

Endpoint: /rest/import/organizations
Method:

POST

Request Parameters:

Multipart File - It should be a CSV file in the below format:

Location Id, Location Name, Organization name, Plan Id (Optional)

The API is responsible to validate the data provided in the CSV files to ensure whether the location Id in the CSV file is actually present in the OpenSRP database or not. If location Id is present, a comparison is also done on the basis of the location Name. Once validation is passed, API converts the data from the CSV files into the OpenSRP Organization domain Entity after mapping of fields. The converted organization entity is later persisted in the database.

If an organization already exists in the database, figured out by finding organization by Name in the database, the organization is then updated. Later, organization_location is also persisted in the database.

A summary of the whole process is returned in a CSV file as a response. The summary contains a count of rows in the actual CSV, the number of rows processed by the server, and a list of failed records.

Use the ‘file’ as a key when adding a CSV file as a requestParam in a POST request. Attached is a snapshot of postman for reference:

Following is the sample of the response:

Practitioners and Practitioner Roles

To upload practitioners and practitioner roles, run a POST request with the CSV file as an input to the REST API.

Following are the details of the API:

Endpoint: /rest/import/practitioners
Method:

POST

Request Parameters:

Multipart File - The file should be a CSV file with the below format:

Organization id, Organization name, User Id, Username, Name (Optional), Role (Optional)

The API is responsible to validate the data provided in the CSV files to ensure whether the organization exists against the given organization Id, the system further validates the organization name on the sheet should match with the organization in the Opensrp database. Once validation is passed, API converts the data from the CSV files into the OpenSRP Practitioner domain entity after mapping of fields. The converted practitioner entity is later persisted in the database.

If a practitioner already exists in the database, figured out by finding a practitioner by User Name in the database, the practitioner is then updated. Later, practitioner roles are also assigned and persisted in the database.

Use the ‘file’ as a key when adding a CSV file as a requestParam in a POST request. Attached is a snapshot of postman for reference:

Following is the sample of the response:

Sample CSV Files Format:

Following are the sample CSV files: (NOTE:- It only holds the test data)