diff --git a/adaptors/library/jobs/commcare-asri-bulk-upload.js b/adaptors/library/jobs/commcare-asri-bulk-upload.js new file mode 100644 index 00000000000..0745e42a2bf --- /dev/null +++ b/adaptors/library/jobs/commcare-asri-bulk-upload.js @@ -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 } + ) diff --git a/adaptors/library/staticExamples.json b/adaptors/library/staticExamples.json index 6fdb148a20e..02cd577b75e 100644 --- a/adaptors/library/staticExamples.json +++ b/adaptors/library/staticExamples.json @@ -1,4 +1,9 @@ [ + { + "expressionPath": "jobs/commcare-asri-bulk-upload", + "adaptor": "commcare", + "name": "Bulk upload obat lookup-table" + }, { "expressionPath": "jobs/getKoboData", "adaptor": "http", @@ -101,4 +106,4 @@ "adaptor": "postgresql", "name": "Using findValue with an array of data" } -] +] \ No newline at end of file