Skip to content

Commit

Permalink
feat: change get patient and create encounter implementation
Browse files Browse the repository at this point in the history
 Signed-off-by: Hunter Achieng ([email protected])

Signed-off-by: Hunter Achieng <[email protected]>
  • Loading branch information
hunterachieng committed Feb 20, 2024
1 parent 0bdb6a4 commit 7d3dc50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 39 deletions.
50 changes: 13 additions & 37 deletions packages/openmrs/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import {
expandReferences,
} from '@openfn/language-common';
import request from 'superagent';
import { Log, handleError, handleResponse } from './Utils';

import {
Log,
handleError,
handleResponse,
request as sendRequest,
} from './Utils';

let agent = null;

Expand Down Expand Up @@ -61,23 +65,7 @@ async function login(state) {
* @returns {Operation}
*/
export function getPatient(uuid, callback = false) {
return state => {
Log.info(`Searching for patient with uuid: ${uuid}`);
const { instanceUrl } = state.configuration;
const defaultQuery = { v: 'full', limit: 1 };
const url = `${instanceUrl}/ws/rest/v1/patient/${uuid}`;

return agent
.get(url)
.accept('json')
.query(defaultQuery)
.then(response => {
Log.success(`Found patient.`);

return handleResponse(response, state, callback);
})
.catch(handleError);
};
return sendRequest('GET', `/ws/rest/v1/patient/${uuid}`, {}, callback);
}

/**
Expand All @@ -102,24 +90,12 @@ export function getPatient(uuid, callback = false) {
* @returns {Operation}
*/
export function createEncounter(data, callback = false) {
return state => {
const { instanceUrl } = state.configuration;
const body = expandReferences(data)(state);
const url = `${instanceUrl}/ws/rest/v1/encounter`;

Log.info(`Creating an encounter.`);

return agent
.post(url)
.type('json')
.send(body)
.then(response => {
Log.success(`Created an encounter.`);

return handleResponse(response, state, callback);
})
.catch(handleError);
};
sendRequest(
'POST',
'/ws/rest/v1/encounter',
{ body: data, headers: { 'content-type': 'application/json' } },
callback
);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/openmrs/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,3 @@ export function request(method, path, params, callback = s => s) {
});
};
}


0 comments on commit 7d3dc50

Please sign in to comment.