Skip to content

Commit

Permalink
Merge pull request #749 from OpenFn/747-cleanup
Browse files Browse the repository at this point in the history
`openmrs` remove createEncounter and createPatient
  • Loading branch information
josephjclark authored Sep 11, 2024
2 parents 57d8b55 + cff65e6 commit 2c03c75
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 218 deletions.
20 changes: 19 additions & 1 deletion .changeset/wicked-carrots-whisper.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
---
'@openfn/language-openmrs': minor
'@openfn/language-openmrs': major
---

- Add pagination support on request helper function
- Remove `createEncounter` and `createPatient` functions

### Migration Guide

The `createEncounter` and `createPatient` functions have been removed from the
OpenMRS adaptor. Use the `create` function with the appropriate resource type.

To create a new encounter, you can use the following code:

```js
create('encounter', $.encounter);
```

To create a new patient, you can use the following code:

```js
create('patient', $.patient);
```
123 changes: 10 additions & 113 deletions packages/openmrs/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,63 +57,6 @@
},
"valid": true
},
{
"name": "createEncounter",
"params": [
"data",
"callback"
],
"docs": {
"description": "Creates an encounter",
"tags": [
{
"title": "example",
"description": "createEncounter({\n encounterDatetime: '2023-05-25T06:08:25.000+0000',\n patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',\n encounterType: 'dd528487-82a5-4082-9c72-ed246bd49591',\n location: 'ba685651-ed3b-4e63-9b35-78893060758a',\n encounterProviders: [],\n visit: {\n patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',\n visitType: '7b0f5697-27e3-40c4-8bae-f4049abfb4ed',\n startDatetime: '2023-05-25T06:08:25.000+0000',\n stopDatetime: '2023-05-25T06:09:25.000+0000',\n },\n})",
"caption": "Create an encounter"
},
{
"title": "function",
"description": null,
"name": null
},
{
"title": "public",
"description": null,
"type": null
},
{
"title": "param",
"description": "Data parameters of the encounter",
"type": {
"type": "NameExpression",
"name": "object"
},
"name": "data"
},
{
"title": "param",
"description": "Optional callback to handle the response",
"type": {
"type": "OptionalType",
"expression": {
"type": "NameExpression",
"name": "function"
}
},
"name": "callback"
},
{
"title": "returns",
"description": null,
"type": {
"type": "NameExpression",
"name": "Operation"
}
}
]
},
"valid": true
},
{
"name": "get",
"params": [
Expand Down Expand Up @@ -358,62 +301,6 @@
},
"valid": true
},
{
"name": "createPatient",
"params": [
"data",
"callback"
],
"docs": {
"description": "Creates a new patient",
"tags": [
{
"title": "example",
"description": "createPatient({\n identifiers: [\n {\n identifier: '4023287',\n identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334',\n preferred: true,\n },\n ],\n person: {\n gender: 'M',\n age: 42,\n birthdate: '1970-01-01T00:00:00.000+0100',\n birthdateEstimated: false,\n names: [\n {\n givenName: 'Doe',\n familyName: 'John',\n },\n ],\n },\n})"
},
{
"title": "function",
"description": null,
"name": null
},
{
"title": "public",
"description": null,
"type": null
},
{
"title": "param",
"description": "Object parameters of the patient",
"type": {
"type": "NameExpression",
"name": "object"
},
"name": "data"
},
{
"title": "param",
"description": "Optional callback to handle the response",
"type": {
"type": "OptionalType",
"expression": {
"type": "NameExpression",
"name": "function"
}
},
"name": "callback"
},
{
"title": "returns",
"description": null,
"type": {
"type": "NameExpression",
"name": "Operation"
}
}
]
},
"valid": true
},
{
"name": "getEncounter",
"params": [
Expand Down Expand Up @@ -588,6 +475,16 @@
"title": "example",
"description": "create(\"person\", {\n names: [\n {\n givenName: \"Mohit\",\n familyName: \"Kumar\",\n },\n ],\n gender: \"M\",\n birthdate: \"1997-09-02\",\n addresses: [\n {\n address1: \"30, Vivekananda Layout, Munnekolal,Marathahalli\",\n cityVillage: \"Bengaluru\",\n country: \"India\",\n postalCode: \"560037\",\n },\n ],\n});",
"caption": "Create a person"
},
{
"title": "example",
"description": "create(\"encounter\", {\n encounterDatetime: '2023-05-25T06:08:25.000+0000',\n patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',\n encounterType: 'dd528487-82a5-4082-9c72-ed246bd49591',\n location: 'ba685651-ed3b-4e63-9b35-78893060758a',\n encounterProviders: [],\n visit: {\n patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',\n visitType: '7b0f5697-27e3-40c4-8bae-f4049abfb4ed',\n startDatetime: '2023-05-25T06:08:25.000+0000',\n stopDatetime: '2023-05-25T06:09:25.000+0000',\n },\n})",
"caption": "Create an encounter"
},
{
"title": "example",
"description": "create(\"patient\", {\n identifiers: [\n {\n identifier: '4023287',\n identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334',\n preferred: true,\n },\n ],\n person: {\n gender: 'M',\n age: 42,\n birthdate: '1970-01-01T00:00:00.000+0100',\n birthdateEstimated: false,\n names: [\n {\n givenName: 'Doe',\n familyName: 'John',\n },\n ],\n },\n})",
"caption": "Create a patient"
}
]
},
Expand Down
126 changes: 36 additions & 90 deletions packages/openmrs/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,6 @@ export function getPatient(uuid, callback = s => s) {
};
}

/**
* Creates an encounter
* @example <caption>Create an encounter</caption>
* createEncounter({
* encounterDatetime: '2023-05-25T06:08:25.000+0000',
* patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',
* encounterType: 'dd528487-82a5-4082-9c72-ed246bd49591',
* location: 'ba685651-ed3b-4e63-9b35-78893060758a',
* encounterProviders: [],
* visit: {
* patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',
* visitType: '7b0f5697-27e3-40c4-8bae-f4049abfb4ed',
* startDatetime: '2023-05-25T06:08:25.000+0000',
* stopDatetime: '2023-05-25T06:09:25.000+0000',
* },
* })
* @function
* @public
* @param {object} data - Data parameters of the encounter
* @param {function} [callback] - Optional callback to handle the response
* @returns {Operation}
*/
export function createEncounter(data, callback = s => s) {
return async state => {
const [resolvedData] = expandReferences(state, data);

console.log(`Creating an encounter.`);

const response = await request(
state,
'POST',
'/ws/rest/v1/encounter',
resolvedData
);

console.log(`Created encounter with new UUID: ${response.body.id}`);
return prepareNextState(state, response, callback);
};
}

/**
* Make a get request to any OpenMRS endpoint
* @example
Expand Down Expand Up @@ -219,56 +179,6 @@ export function searchPerson(query, callback = s => s) {
};
}

/**
* Creates a new patient
* @example
* createPatient({
* identifiers: [
* {
* identifier: '4023287',
* identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334',
* preferred: true,
* },
* ],
* person: {
* gender: 'M',
* age: 42,
* birthdate: '1970-01-01T00:00:00.000+0100',
* birthdateEstimated: false,
* names: [
* {
* givenName: 'Doe',
* familyName: 'John',
* },
* ],
* },
* })
* @function
* @public
* @param {object} data - Object parameters of the patient
* @param {function} [callback] - Optional callback to handle the response
* @returns {Operation}
*/
export function createPatient(data, callback = s => s) {
return async state => {
const [resolvedData] = expandReferences(state, data);
console.log(`Creating a patient.`);

const response = await request(
state,
'POST',
'/ws/rest/v1/person',
resolvedData
);

console.log(
`Successfully created a patient with UUID: ${response?.body?.uuid}`
);

return prepareNextState(state, response, callback);
};
}

/**
* Gets encounter matching a uuid
* @example
Expand Down Expand Up @@ -353,6 +263,42 @@ export function getEncounters(query, callback = s => s) {
* },
* ],
* });
* @example <caption>Create an encounter</caption>
* create("encounter", {
* encounterDatetime: '2023-05-25T06:08:25.000+0000',
* patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',
* encounterType: 'dd528487-82a5-4082-9c72-ed246bd49591',
* location: 'ba685651-ed3b-4e63-9b35-78893060758a',
* encounterProviders: [],
* visit: {
* patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',
* visitType: '7b0f5697-27e3-40c4-8bae-f4049abfb4ed',
* startDatetime: '2023-05-25T06:08:25.000+0000',
* stopDatetime: '2023-05-25T06:09:25.000+0000',
* },
* })
* @example <caption>Create a patient</caption>
* create("patient", {
* identifiers: [
* {
* identifier: '4023287',
* identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334',
* preferred: true,
* },
* ],
* person: {
* gender: 'M',
* age: 42,
* birthdate: '1970-01-01T00:00:00.000+0100',
* birthdateEstimated: false,
* names: [
* {
* givenName: 'Doe',
* familyName: 'John',
* },
* ],
* },
* })
*/
export function create(resourceType, data, callback = s => s) {
return async state => {
Expand Down
36 changes: 36 additions & 0 deletions packages/openmrs/test/fixtures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"patient": {
"identifiers": [
{
"identifier": "4023287",
"identifierType": "05a29f94-c0ed-11e2-94be-8c13b969e334",
"preferred": true
}
],
"person": {
"gender": "M",
"age": 42,
"birthdate": "1970-01-01T00:00:00.000+0100",
"birthdateEstimated": false,
"names": [
{
"givenName": "Doe",
"familyName": "John"
}
]
}
},
"encounter": {
"patient": "1fdaa696-e759-4a7d-a066-f1ae557c151b",
"encounterDatetime": "2023-05-25T06:08:25.000+0000",
"encounterType": "dd528487-82a5-4082-9c72-ed246bd49591",
"location": "ba685651-ed3b-4e63-9b35-78893060758a",
"encounterProviders": [],
"visit": {
"patient": "1fdaa696-e759-4a7d-a066-f1ae557c151b",
"visitType": "7b0f5697-27e3-40c4-8bae-f4049abfb4ed",
"startDatetime": "2023-05-25T06:08:25.000+0000",
"stopDatetime": "2023-05-25T06:09:25.000+0000"
}
}
}
Loading

0 comments on commit 2c03c75

Please sign in to comment.