Skip to content

Commit

Permalink
fix(#123): fixing Openmrs patient to cht
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Lorena Rodriguez Viruel committed Nov 22, 2024
1 parent d31b038 commit f94d709
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 21 deletions.
67 changes: 67 additions & 0 deletions mediator/test/openmrs-resource-factories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { randomUUID } from 'crypto';
import { Factory } from 'rosie';

export const OpenMRSPatientFactory = new Factory()
.option('placeId')
.attr('resourceType', 'Patient')
.attr('id', () => randomUUID())
.attr('meta', () => ({
versionId: '2',
lastUpdated: new Date().toISOString(),
source: 'cht#rjEgeBRWROBrChB7'
}))
.attr('text', () => ({
status: 'generated',
div: '<div xmlns="http://www.w3.org/1999/xhtml"><div class="hapiHeaderText">OpenMRS <b>PATIENT </b></div><table class="hapiPropertyTable"><tbody><tr><td>Identifier</td><td>52802</td></tr><tr><td>Date of birth</td><td><span>06 June 1980</span></td></tr></tbody></table></div>'
}))
.attr('identifier', () => [
{
id: randomUUID(),
use: 'official',
type: { text: 'CHT Patient ID' },
value: Math.floor(Math.random() * 100000).toString()
},
{
id: randomUUID(),
use: 'secondary',
type: { text: 'CHT Document ID' },
value: randomUUID()
},
{
id: randomUUID(),
use: 'secondary',
type: { text: 'OpenMRS Patient UUID' },
value: randomUUID()
}
])
.attr('name', () => [
{
id: randomUUID(),
family: 'Patient',
given: ['OpenMRS']
}
])
.attr('telecom', () => [
{
id: randomUUID(),
value: '+2548277217095'
}
])
.attr('gender', 'male')
.attr('birthDate', '1980-06-06')
.attr('address', ['placeId'], (placeId) => [
{
id: randomUUID(),
line: ['123 Main St'],
city: 'Nairobi',
country: 'Kenya',
extension: [{
extension: [
{
url: 'http://fhir.openmrs.org/ext/address#address4',
valueString: `FCHV Area [${placeId}]`
}
]
}]
}
]);
52 changes: 31 additions & 21 deletions mediator/test/workflows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
OrganizationFactory as OrganizationFactoryBase,
ServiceRequestFactory as ServiceRequestFactoryBase
} from '../src/middlewares/schemas/tests/fhir-resource-factories';
import { OpenMRSPatientFactory } from './openmrs-resource-factories';

const { generateAuthHeaders } = require('../../configurator/libs/authentication');

jest.setTimeout(50000);
Expand Down Expand Up @@ -112,8 +114,8 @@ describe('Workflows', () => {
await createOpenMRSIdType('CHT Document ID');
});

describe('OpenMRS workflow', () => {
it('Should follow the CHT Patient to OpenMRS workflow', async () => {
describe.only('OpenMRS workflow', () => {
it('should follow the CHT Patient to OpenMRS workflow', async () => {
const checkMediatorResponse = await request(FHIR.url)
.get('/mediator/')
.auth(FHIR.username, FHIR.password);
Expand Down Expand Up @@ -153,7 +155,6 @@ describe('Workflows', () => {
expect(retrieveOpenMrsPatientIdResponse.body.total).toBe(1);

const openMrsPatientId = retrieveOpenMrsPatientIdResponse.body.entry[0].resource.id;
console.log('openMrsPatientId: ' + openMrsPatientId);
const retrieveUpdatedFhirPatientResponse = await request(FHIR.url)
.get(`/fhir/Patient/${patientId}`)
.auth(FHIR.username, FHIR.password);
Expand All @@ -174,35 +175,44 @@ describe('Workflows', () => {
expect(searchOpenMrsPatientResponse.status).toBe(200);
expect(searchOpenMrsPatientResponse.body.total).toBe(1);
expect(searchOpenMrsPatientResponse.body.entry[0].resource.id).toBe(openMrsPatientId);

const searchOpenMrsPatientbyPhoneResponse = await request(OPENMRS.url)
.get(`/Patient/?telecom.value=+2548277217095`)
.auth(OPENMRS.username, OPENMRS.password);
expect(searchOpenMrsPatientbyPhoneResponse.status).toBe(200);
expect(searchOpenMrsPatientbyPhoneResponse.body.total).toBe(1);
expect(searchOpenMrsPatientbyPhoneResponse.body.entry[0].resource.id).toBe(openMrsPatientId);
});

//skipping this test because is incomplete.
it.skip('Should follow the OpenMRS Patient to CHT workflow', async () => {
it('should follow the OpenMRS Patient to CHT workflow', async () => {
const checkMediatorResponse = await request(FHIR.url)
.get('/mediator/')
.auth(FHIR.username, FHIR.password);

expect(checkMediatorResponse.status).toBe(200);

//TODO: Create a patient using openMRS api
console.log('placeId:' + placeId);
const openMrsPatient = OpenMRSPatientFactory.build({}, {placeId});
console.log('openMrsPatient: ' + JSON.stringify(openMrsPatient));

const createOpenMrsPatientResponse = await request(OPENMRS.url)
.post('/Patient')
.auth(OPENMRS.username, OPENMRS.password)
.send(openMrsPatient);

console.log('createOpenMrsPatientResponse: ' + JSON.stringify(createOpenMrsPatientResponse.body));
expect(createOpenMrsPatientResponse.status).toBe(201);
expect(createOpenMrsPatientResponse.body).toHaveProperty('id');

const openMrsPatientId = createOpenMrsPatientResponse.body.id;

await new Promise((r) => setTimeout(r, 10000));

const triggerOpenMrsSyncPatientResponse = await request('https://localhost:5002')
.get('/mediator/openmrs/sync')
.auth(OPENMRS.username, OPENMRS.password)
.send();
expect(triggerOpenMrsSyncPatientResponse.status).toBe(200);

await new Promise((r) => setTimeout(r, 10000));

const retrieveFhirPatientIdResponse = await request(FHIR.url)
.get('/fhir/Patient/?identifier=' + patientId)
.get('/fhir/Patient/?identifier=' + openMrsPatientId)
.auth(FHIR.username, FHIR.password);

expect(retrieveFhirPatientIdResponse.status).toBe(200);
//expect(retrieveFhirPatientIdResponse.body.total).toBe(1);

//TODO: retrieve and validate patient from CHT api
//trigger openmrs sync
//validate id
expect(retrieveFhirPatientIdResponse.body.total).toBe(1);
});
});

Expand Down

0 comments on commit f94d709

Please sign in to comment.