Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commcare: update examples documentation #596

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions adaptors/library/jobs/commcare-asri-bulk-upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

// Bulk update obat lookup-table
fn(state => {
const { medication_ids, visit, obat } = state.data
state.medication_ids = medication_ids;
state.visit = visit
state.obat = obat
return state
})

fn(state => {

const properties = state.visit.properties;

const data = state.medication_ids
.flatMap(medicine => {
const medicineName = properties[Object.keys(medicine)[0]];
return state.obat.filter(
item => item.fields['Nama'] === medicineName
).map(item => ({ ...item, fields: { ...item.fields, satusehat_id: Object.values(medicine)[0] } }))
}).map(obat => {
const data = {
UID: obat.id,
'DELETE(Y/N)': 'N',
'field:Nama': obat.fields['Nama'],
'field:Satuan': obat.fields['Satuan'],
'field:Harga': obat.fields['Harga'],
'field:kfa_codes': obat.fields['kfa_codes'],
'field:satusehat_id': obat.fields['satusehat_id'],
'field:strength': obat.fields['strength'],
'field:strength_unit': obat.fields['strength_unit'],
}
return data
})

state.medicationMappedData = {
types: [{
'DELETE(Y/N)': 'N',
table_id: 'test_obat',
'is_global?': 'yes',
'field 1': 'Nama',
'field 2': 'Satuan',
'field 3': 'Harga',
'field 4': 'kfa_codes',
'field 5': 'satusehat_id',
'field 6': 'strength',
'field 7': 'strength_unit',
}],
test_obat: data,
}

return state
})

bulk(
'lookup-table',
state => state.medicationMappedData,
{ replace: false }
)
7 changes: 6 additions & 1 deletion adaptors/library/staticExamples.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"expressionPath": "jobs/commcare-asri-bulk-upload",
"adaptor": "commcare",
"name": "Bulk upload obat lookup-table"
},
{
"expressionPath": "jobs/getKoboData",
"adaptor": "http",
Expand Down Expand Up @@ -101,4 +106,4 @@
"adaptor": "postgresql",
"name": "Using findValue with an array of data"
}
]
]