Skip to content

Commit 985b764

Browse files
Updates to commcare lookuptable docs (#688)
1 parent f437cf0 commit 985b764

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

adaptors/commcare.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ CommCare supports 2 primary integration options:
4141
to _push_ `cases` and `forms` data from CommCare to external systems. This
4242
option is suited for _real-time_, event-based data integration.
4343

44-
2. **[REST APIs](https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143958022/API+Access)**
44+
2. **[REST APIs](https://commcare-hq.readthedocs.io/api/index.html#commcare-apis)**
4545
that enable external services like OpenFn to _pull_ data from CommCare, or
4646
push data from external apps to CommCare. This option is suited for
4747
_scheduled, bulk syncs_ or workflows that must update data in CommCare with
48-
external information.
48+
external information. Also [see here](https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2279637003/CommCare+API+Overview)
49+
for more on the API Explorer.
4950

5051
This OpenFn adaptor is designed for option #2
5152
[CommCare's APIs](https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2279637003/CommCare+API+Overview).
@@ -255,37 +256,55 @@ If integrating with CommCare `forms`, you may need to make sure that any unique
255256

256257
### Lookup Tables in CommCare
257258
Lookup tables in CommCare store reference data that can be used across multiple forms and workflows. They are often used for predefined lists such as as health facility names, geographic locations, product catalogs, or standardized response options.
259+
258260
When fetching lookup table data in using CommCare APIs, there are two main approaches:
259261
**1. Using the Fixture API**
262+
[See here](https://commcare-hq.readthedocs.io/api/fixture.html) for the CommCare docs on this API. FYI `fixture` is a more technical term that the CommCare docs sometimes use to refer to a `lookup table`.
260263
```
264+
//sample openfn job to get a specific 'diagnosis' lookup table
261265
get("fixture/?fixture_type=diagnosis")
262266
```
263267

264268
**Pros:**
265-
- Simple and direct for fetching specific tables.
266-
- Works well when only a few tables (e.g., 2-3) are needed.
269+
- Simple and direct API for querying a specific lookup table; response include lookup table metadata and data.
270+
- Works well when items from only a couple of tables (e.g., 1-3) need to be queried.
271+
267272
**Cons:**
268-
- Requires multiple API calls if several tables are needed, which can be inefficient.
273+
- Requires multiple API calls if several tables are needed, which can be inefficient at scale.
274+
- See `lookup_table_item` API if querying data across multiple lookup tables.
269275

270276
**2. Using the lookup_table_item API**
271-
```
272-
const findLookupById = (id) => state.data.filter((i) => i.data_type_id === id);
277+
[See here](https://commcare-hq.readthedocs.io/api/fixture.html#list-lookup-table-row) for the CommCare docs on this API.
278+
You can use this API to query _and_ update lookup table items or rows.
273279

274-
state.facility = findLookupById("facility_table_id");
275-
state.product = findLookupById("product_table_id");
276-
state.medications = findLookupById("medications_table_id");
280+
```
281+
get('lookup_table_item') //to list all lookup table items
282+
283+
fn(state => {
284+
//custom function to then assign & group lookup_table_items to new variables
285+
const findLookupById = (id) => state.data.filter((i) => i.data_type_id === id);
286+
287+
//assign to facility, product, medications variables to use later in WF
288+
state.facility = findLookupById("facility_table_id");
289+
state.product = findLookupById("product_table_id");
290+
state.medications = findLookupById("medications_table_id");
291+
return state;
292+
})
277293
```
278294

279295
**Pros:**
280-
- Fetches all lookup tables in a single request, reducing API calls.
281-
- Useful for OpenFn workflows requiring multiple lookup tables.
296+
- Good for bulk querying lookup table rows in a single request, reducing API calls.
297+
- Useful for OpenFn workflows requiring data from multiple lookup tables.
298+
- Support for create & update of lookup table items.
299+
282300
**Cons:**
283301
- Retrieves all lookup tables and filters them in-memory, which can be inefficient if only a few tables are needed.
284302

285303
#### Best Practices
286-
- Use the Fixture API when fetching only a few lookup tables.
287-
- Use the lookup_table_item API for cases where multiple lookup tables are needed at once.
304+
- Use the `Fixture` API when fetching data for only a couple of (1-3) lookup tables.
305+
- Use the `lookup_table` API for scenarios where data from multiple lookup tables needs to be queried in bulk.
288306
- Consider performance trade-offs when selecting an approach, balancing API efficiency with data processing overhead.
307+
- See the [bulk()](/adaptors/packages/commcare-docs#bulk) helper function for bulk importing lookup table data.
289308

290309
#### Troubleshooting tips
291310
If some tables are throwing errors when being fetched using the fixtures API, the lookup table might be corrupt. Consider exporting the table and re-importing it.

0 commit comments

Comments
 (0)