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 1 commit
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 }
)
8 changes: 8 additions & 0 deletions adaptors/library/jobs/commcare-asri-submitxls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Update the kunjungan case with a new row of data. The row contains the case_id and satusehat_id

submitXls([{ case_id: 'abcde', satusehat_id: '12345' }], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is just a one-liner, would it be better if it were just a regular example in the adaptor docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, its already in the adaptor docs Let me remove it

case_type: 'kunjungan',
search_field: 'case_id',
search_column: 'case_id',
create_new_cases: 'off',
});
12 changes: 11 additions & 1 deletion adaptors/library/staticExamples.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"expressionPath": "jobs/commcare-asri-submitxls",
"adaptor": "commcare",
"name": "Update visit case with satusehat-id and case-id"
},
{
"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 +111,4 @@
"adaptor": "postgresql",
"name": "Using findValue with an array of data"
}
]
]