Skip to content

Commit 9f32748

Browse files
Merge pull request #664 from OpenFn/openmrs-5
OpenMRS: Docs for v5
2 parents 4243310 + 5748000 commit 9f32748

File tree

1 file changed

+151
-10
lines changed

1 file changed

+151
-10
lines changed

adaptors/openmrs.md

Lines changed: 151 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,36 @@ title: OpenMRS Adaptor
44

55
## About OpenMRS
66

7-
[OpenMRS (Open Medical Record System)](https://openmrs.org/) is an open-source platform designed to manage electronic medical records (EMRs) in low-resource environments. It provides a framework that allows developers to extend its core functionality through custom modules and APIs.
7+
[OpenMRS (Open Medical Record System)](https://openmrs.org/) is an open-source
8+
platform designed to manage electronic medical records (EMRs) in low-resource
9+
environments. It provides a framework that allows developers to extend its core
10+
functionality through custom modules and APIs.
811

912
## Integration Options
1013

11-
**1. Rest API:** OpenMRS offers a REST API that enables external applications to interact with its database and perform bulk operations. This option is ideal for applications requiring scheduled or bulk synchronization with OpenMRS. Refer to the OpenMRS REST API [documentation](https://wiki.openmrs.org/) for detailed guidelines on endpoints and payload formats.
14+
**1. Rest API:** OpenMRS offers a REST API that enables external applications to
15+
interact with its database and perform bulk operations. This option is ideal for
16+
applications requiring scheduled or bulk synchronization with OpenMRS. Refer to
17+
the OpenMRS REST API [documentation](https://wiki.openmrs.org/) for detailed
18+
guidelines on endpoints and payload formats.
1219

13-
**2. Webhook:** OpenMRS does not natively support webhooks as a standard feature. However, the platform is highly extensible and allows for customization through its module system. More details can be found on the OpenMRS [documentation page​](https://wiki.openmrs.org/).
20+
**2. Webhook:** OpenMRS does not natively support webhooks as a standard
21+
feature. However, the platform is highly extensible and allows for customization
22+
through its module system. More details can be found on the OpenMRS
23+
[documentation page​](https://wiki.openmrs.org/).
1424

1525
## Authentication
1626

17-
When integrating with OpenMRS via OpenFn, **Basic Authentication** is supported. See this adaptor's [Configuration docs](/adaptors/packages/openmrs-configuration-schema) for more on the required authentication parameters.
27+
When integrating with OpenMRS via OpenFn, **Basic Authentication** is supported.
1828

19-
See platform docs on [managing credentials](documentation/manage-projects/manage-credentials) for how to configure a credential in OpenFn. If working locally or if using a Raw JSON credential type, then your configuration will look something like this:
29+
The `instanceUrl`, `username` an `password` properties are all required to
30+
access your OpenMRS instance.
31+
32+
See [Managing Credentials](documentation/manage-projects/manage-credentials) to
33+
configure a credential in OpenFn.
34+
35+
If working locally or if using a Raw JSON credential type, then your
36+
configuration will look something like this:
2037

2138
```
2239
{
@@ -26,15 +43,139 @@ See platform docs on [managing credentials](documentation/manage-projects/manage
2643
}
2744
```
2845

29-
### Helpful Links
46+
See this adaptor's
47+
[Configuration docs](/adaptors/packages/openmrs-configuration-schema) for more
48+
details.
3049

31-
1. [OpenMRS Developer Guide](https://openmrs.atlassian.net/wiki/spaces/docs/pages/25476048/Developer+Guide)
32-
2. Community Forums: [OpenMRS Talk](https://talk.openmrs.org/)
50+
## API Basics
3351

34-
### Implementation Examples
52+
There are three ways you can use the OpenMRS API, all available interchangeable
53+
in the same step in a workflow.
54+
55+
Like other adaptors, the FHIR adaptor "returns" output by writing to
56+
`state.data`:
57+
58+
```js
59+
get('patient/71075074-f02e-4270-89a3-f2dcda436f70');
60+
fn(state => {
61+
console.log(state.data); // the downloaded patient is available here
62+
return state;
63+
});
64+
```
65+
66+
### REST API Operations
67+
68+
The main namespace contains high-level helper functions, which are designed as
69+
the primary interface. These are designed to handle the most common use cases,
70+
like downloading OpenMRS resources. They will configure default values and
71+
handle some complications for you, like authorization and pagination.
72+
73+
All requests generated by these operations are made against your instance URL
74+
plus `ws/rest/v1`.
75+
76+
For a list of valid resource types, see the
77+
[OpenMRS REST API Docs](https://rest.openmrs.org/#openmrs-rest-api). These docs
78+
are a useful resource when using OpenMRS, as different resources have different
79+
usage rules.
80+
81+
For example, to download all concepts:
82+
83+
```js
84+
get('concept');
85+
// calls <instanceUrl>/ws/rest/v1/concept
86+
```
87+
88+
Each resource in OpenMRS defines a number of query parameters. These can be
89+
passed as an options object as the second argument. For example, to set the
90+
[`source` parameter](https://rest.openmrs.org/#list-all-concepts) on the concept
91+
resource:
92+
93+
```js
94+
get('concept', { source: 'SNOWMED' });
95+
// calls <instanceUrl>/ws/rest/v1/concept?source=SNOWMED
96+
```
97+
98+
Most options are appended to the request URL as query parameters, so you can
99+
pass whatever parameters OpenMRS requires.
100+
101+
The adaptor will download resources over multiple pages. Each individual request
102+
to OpenMRS will be logged, for debugging and optimization.
103+
104+
Note that by default, the function imposes a download limit of 10,000 records.
105+
You can force all data to be downloaded by passing `max: Infinity`, like this:
106+
107+
```js
108+
get('concept', { max: Infinity });
109+
```
35110

36-
1. OpenFn Prototype for Médecins Sans Frontières (MSF) LIME Project - OpenMRS -> DHIS2 sync: [https://github.com/OpenFn/openfn-lime](https://github.com/OpenFn/openfn-lime)
111+
When paging, the adaptor will make multiple requests. By default each request
112+
will download a page of data according to the instance's configuration. To force
113+
a larger page size (and reduce the number of requests, pass `pageSize`)
37114

115+
```js
116+
get('concept', { pageSize: 1000 });
117+
```
118+
119+
To disable pagination and force a single request, set `limit`.
120+
121+
You can page from a specific position by passing `startIndex`. This works with
122+
pagination and with `limit`.
123+
124+
## HTTP Utility Functions
125+
126+
The REST API operations are be opinionated, and in some cases can make too many
127+
assumptions about what you want to do.
128+
129+
The operations in the `http` namespace are simpler, lower-level helpers and work
130+
more like curl or postman. They'll do exactly what you ask for them. They'll
131+
handle authorization for you but won't paginate or prepend anything to the
132+
requested path.
133+
134+
To request a single page of concepts, you can do:
135+
136+
```js
137+
http.get('ws/rest/v1/concept');
138+
```
139+
140+
You can pass a query via the options object:
141+
142+
```js
143+
http.get('ws/rest/v1/concept', {
144+
query: {
145+
limit: 1000,
146+
source: 'SNOWMED',
147+
},
148+
});
149+
```
38150

151+
Using the http helpers, pagination must be implemented manually.
39152

153+
The HTTP helpers write to things to your state object:
154+
155+
- `state.data` is the response body returned by OpenMRS
156+
- `state.response` is the rest of the HTTP response (excluding the body),
157+
including `statusCode`, `statusMessage` and `headers`.
158+
159+
## FHIR Helpers
160+
161+
The OpenMRS adaptor also provides a
162+
[FHIR helper API](https://docs.openfn.org/adaptors/packages/openmrs-docs#fhir),
163+
which allows you to make requests against FHIR endpoints and download FHIR data.
164+
165+
```js
166+
fhir.get('Encounter', {
167+
count: 100,
168+
lastUpdated: 'ge2024-01-01T00:00:00Z',
169+
});
170+
```
171+
172+
### Helpful Links
173+
174+
1. [OpenMRS Developer Guide](https://openmrs.atlassian.net/wiki/spaces/docs/pages/25476048/Developer+Guide)
175+
2. Community Forums: [OpenMRS Talk](https://talk.openmrs.org/)
176+
177+
### Implementation Examples
40178

179+
1. OpenFn Prototype for Médecins Sans Frontières (MSF) LIME Project - OpenMRS ->
180+
DHIS2 sync:
181+
[https://github.com/OpenFn/openfn-lime](https://github.com/OpenFn/openfn-lime)

0 commit comments

Comments
 (0)