From 1291192292b9fae10103f07ef13704b7db5ded88 Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Mon, 4 Nov 2024 17:06:37 +0300 Subject: [PATCH 1/2] feat: update commcare examples docs Signed-off-by: Hunter Achieng --- .../library/jobs/commcare-asri-bulk-upload.js | 59 +++++++++++++++++++ .../library/jobs/commcare-asri-submitxls.js | 8 +++ adaptors/library/staticExamples.json | 12 +++- 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 adaptors/library/jobs/commcare-asri-bulk-upload.js create mode 100644 adaptors/library/jobs/commcare-asri-submitxls.js 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 000000000000..0745e42a2bff --- /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/jobs/commcare-asri-submitxls.js b/adaptors/library/jobs/commcare-asri-submitxls.js new file mode 100644 index 000000000000..8035fc74f0c0 --- /dev/null +++ b/adaptors/library/jobs/commcare-asri-submitxls.js @@ -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' }], { + case_type: 'kunjungan', + search_field: 'case_id', + search_column: 'case_id', + create_new_cases: 'off', + }); \ No newline at end of file diff --git a/adaptors/library/staticExamples.json b/adaptors/library/staticExamples.json index 6fdb148a20e9..234d4262364f 100644 --- a/adaptors/library/staticExamples.json +++ b/adaptors/library/staticExamples.json @@ -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", @@ -101,4 +111,4 @@ "adaptor": "postgresql", "name": "Using findValue with an array of data" } -] +] \ No newline at end of file From 857224fc290e979006afd0e997048df624dccef6 Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Mon, 4 Nov 2024 18:10:39 +0300 Subject: [PATCH 2/2] remove submitXls Signed-off-by: Hunter Achieng --- adaptors/library/jobs/commcare-asri-submitxls.js | 8 -------- adaptors/library/staticExamples.json | 5 ----- 2 files changed, 13 deletions(-) delete mode 100644 adaptors/library/jobs/commcare-asri-submitxls.js diff --git a/adaptors/library/jobs/commcare-asri-submitxls.js b/adaptors/library/jobs/commcare-asri-submitxls.js deleted file mode 100644 index 8035fc74f0c0..000000000000 --- a/adaptors/library/jobs/commcare-asri-submitxls.js +++ /dev/null @@ -1,8 +0,0 @@ -// 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' }], { - case_type: 'kunjungan', - search_field: 'case_id', - search_column: 'case_id', - create_new_cases: 'off', - }); \ No newline at end of file diff --git a/adaptors/library/staticExamples.json b/adaptors/library/staticExamples.json index 234d4262364f..02cd577b75e3 100644 --- a/adaptors/library/staticExamples.json +++ b/adaptors/library/staticExamples.json @@ -1,9 +1,4 @@ [ - { - "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",