Skip to content

Commit 2a69f6e

Browse files
authored
Merge pull request #651 from OpenFn/feature/971-satusehat-examples
satusehat: add job examples
2 parents c4bcc06 + a44efb8 commit 2a69f6e

File tree

6 files changed

+425
-2
lines changed

6 files changed

+425
-2
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Map diagnosis objects from commcare into Condition resources
2+
3+
fn(state => {
4+
state.conditions = state.visit.diagnosis.map(diagnosis => {
5+
const diagnosisName = diagnosis.fields.name;
6+
const code = diagnosis.fields['icd_10_code'];
7+
8+
return {
9+
resourceType: 'Condition',
10+
clinicalStatus: {
11+
coding: [
12+
{
13+
system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
14+
code: 'active',
15+
display: 'Active',
16+
},
17+
],
18+
},
19+
verificationStatus: {
20+
coding: [
21+
{
22+
system:
23+
'http://terminology.hl7.org/CodeSystem/condition-ver-status',
24+
code: 'confirmed',
25+
display: 'Confirmed',
26+
},
27+
],
28+
},
29+
category: [
30+
{
31+
coding: [
32+
{
33+
system:
34+
'http://terminology.hl7.org/CodeSystem/condition-category',
35+
code: 'encounter-diagnosis',
36+
display: 'Encounter Diagnosis',
37+
},
38+
],
39+
},
40+
],
41+
subject: {
42+
reference: `Patient/${state.patient.ihs_number}`,
43+
display: state.patient.full_name,
44+
},
45+
encounter: {
46+
reference: `Encounter/${state.encounterId}`,
47+
display:
48+
state.patient.full_name +
49+
"'s " +
50+
state.visit.properties.visit_type +
51+
' on ' +
52+
state.visit.properties.visit_date,
53+
},
54+
code: {
55+
coding: [
56+
{
57+
system: 'http://hl7.org/fhir/sid/icd-10',
58+
code: code,
59+
display: diagnosisName,
60+
},
61+
],
62+
},
63+
bodySite: [
64+
{
65+
coding: [
66+
{
67+
system: 'http://snomed.info/sct',
68+
code: '74262004',
69+
display: 'Oral cavity structure',
70+
},
71+
],
72+
},
73+
],
74+
recorder: {
75+
reference: state.encounter.resource.participant[0].individual.reference,
76+
},
77+
onsetDateTime: state.visit.visit_date,
78+
recordedDate: state.visit.visit_date,
79+
};
80+
});
81+
return state;
82+
});
83+
84+
// Post our condition resources to Satusehat
85+
post('Condition', $.conditions);
86+
87+
fn(state => {
88+
// Store the newly created resources, created by the server, into state for the next step
89+
state.conditions = state.data;
90+
return state;
91+
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Create an encounter in Satusehat based on an incoming Commcare visit
2+
3+
fn(state => {
4+
state.encounterId = util.uuid();
5+
6+
state.encounter = {
7+
id: state.encounterId,
8+
resourceType: 'Encounter',
9+
identifier: [
10+
{
11+
system: `http://sys-ids.kemkes.go.id/encounter/${state.visit.organizationId}`,
12+
value: state.visit.case_id,
13+
},
14+
],
15+
status: 'arrived',
16+
class: {
17+
system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode',
18+
code: 'AMB',
19+
display: 'ambulatory',
20+
},
21+
subject: {
22+
reference: 'Patient/P00805884304',
23+
display: 'Elizabeth Dior',
24+
},
25+
participant: [
26+
{
27+
type: [
28+
{
29+
coding: [
30+
{
31+
system:
32+
'http://terminology.hl7.org/CodeSystem/v3-ParticipationType',
33+
code: 'ATND',
34+
display: 'attender',
35+
},
36+
],
37+
},
38+
],
39+
individual: {
40+
reference: `Practitioner/N10000001`,
41+
display: 'Voigt',
42+
},
43+
},
44+
],
45+
period: {
46+
start: state.visit.visit_date,
47+
end: state.visit.visit_date,
48+
},
49+
50+
location: [
51+
{
52+
location: {
53+
reference: `Location/574d5ffd-2dc2-453b-a787-d1c63cc89ae4`,
54+
display: `PLKB`,
55+
},
56+
extension: [
57+
{
58+
url: 'https://fhir.kemkes.go.id/r4/StructureDefinition/ServiceClass',
59+
extension: [
60+
{
61+
url: 'value',
62+
valueCodeableConcept: {
63+
coding: [
64+
{
65+
system:
66+
'http://terminology.kemkes.go.id/CodeSystem/locationServiceClass-Outpatient',
67+
code: 'reguler',
68+
display: 'Kelas Reguler',
69+
},
70+
],
71+
},
72+
},
73+
],
74+
},
75+
],
76+
},
77+
],
78+
statusHistory: [
79+
{
80+
status: 'arrived',
81+
period: {
82+
start: state.visit.visit_date,
83+
end: state.visit.visit_date,
84+
},
85+
},
86+
],
87+
serviceProvider: {
88+
reference: `Organization/${state.visit.organizationId}`,
89+
},
90+
};
91+
92+
return state;
93+
});
94+
95+
// Post our encounter resources to Satusehat
96+
post('Encounter', $.encounter);
97+
98+
fn(state => {
99+
// Store the newly created resources, created by the server, into state for the next step
100+
state.encounter = state.data;
101+
return state;
102+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Create medication in Satusehat based on an incoming Commcare visit
2+
3+
fn(state => {
4+
// state.visit is a Commcare Visit record
5+
const properties = state.visit.properties;
6+
const medicineKeys = Object.keys(properties).filter(
7+
key =>
8+
key.startsWith('prescription_') &&
9+
!key.includes('_amount') &&
10+
!key.includes('_instruction') &&
11+
!key.includes('_dose')
12+
);
13+
14+
const medicationId = util.uuid();
15+
16+
// Map medication data for each relevant key
17+
state.medication = medicineKeys.map(item => {
18+
return {
19+
resourceType: 'Medication',
20+
id: state => medicationId,
21+
meta: {
22+
profile: [
23+
'https://fhir.kemkes.go.id/r4/StructureDefinition/Medication',
24+
],
25+
},
26+
identifier: [
27+
{
28+
system: `http://sys-ids.kemkes.go.id/medication/${state.visit.satusehatId}`,
29+
use: 'usual',
30+
value: item.fields['Nama'],
31+
},
32+
],
33+
code: {
34+
coding: [
35+
{
36+
system: 'http://sys-ids.kemkes.go.id/kfa',
37+
code: item.fields['kfa_codes'],
38+
display: item.fields['Nama'],
39+
},
40+
],
41+
},
42+
status: 'active',
43+
extension: [
44+
{
45+
url: 'https://fhir.kemkes.go.id/r4/StructureDefinition/MedicationType',
46+
valueCodeableConcept: {
47+
coding: [
48+
{
49+
system:
50+
'http://terminology.kemkes.go.id/CodeSystem/medication-type',
51+
code: 'NC',
52+
display: 'Non-compound',
53+
},
54+
],
55+
},
56+
},
57+
],
58+
};
59+
});
60+
61+
return state;
62+
});
63+
64+
// Post our medication resources to Satusehat
65+
post('Medication', $.medication);
66+
67+
fn(state => {
68+
// Store the newly created resources, created by the server, into state for the next step
69+
state.medication = state.data;
70+
return state;
71+
});

0 commit comments

Comments
 (0)