Skip to content

Accessing Case Data

Farid Rener edited this page May 17, 2021 · 5 revisions

Case Content Provider API

Android applications that have the appropriate permissions can read data from the case database of the currently logged in CommCare user.

The android "permissions" and content provider API's are not sufficient to prevent unauthorized access to data in a number of circumstances. The manner in which this is protected by this API is still ongoing.

Support Library

Many of these functions are more easily accessible via the support library.

Prerequisites

In order to use this API, you'll need

  • An application installed in CommCare
  • A user logged into CommCare
  • For the external application to implement the appropriate Android Permissions

Workflow

Applications reading data from CommCare do so with an Android Content Provider.

Unlike a static content provider, CommCare's content provider requests should be considered transient. What data is available from CommCare depends on the logged in user and their current session data, since all CommCare data is encrypted at rest and is unavailable to the app while a user is not logged in. External applications should not store CommCare data in persistent storage unless properly encrypted.

Currently all CommCare content providers are Read Only. The databases cannot be manipulated externally.

Content URI Structure

The base and content authority of CommCare provider requests is

content://org.commcare.dalvik.case/

Permissions

External applications should implement the permission

org.commcare.dalvik.provider.cases.read

in order to permit them to access case data through this API.

Available Providers

It will be helpful to refer to the internal CaseDB XML provider when describing what information is made available by each provider

Case Metadata Listing

Provides a listing of all cases in the system, along with their metadata. Essentially returns all of the named attributes for a case (case_type, date_opened, etc) in columns.

  • content://org.commcare.dalvik.case/casedb/case
    • content://org.commcare.dalvik.case/casedb/case/CASE_ID

Response content

column required
case_id yes
case_type yes
owner_id yes
status yes
case_name yes
date_opened yes
last_modified yes

Case Data Listing

Returns the key/value pairs of all data for a specific case

  • content://org.commcare.dalvik.case/casedb/data/CASE_ID
column required
case_id yes
datum_id yes
value yes

Case Index Listing

Returns all indices for a specific case

  • content://org.commcare.dalvik.case/casedb/index/CASE_ID
column required
case_id yes
index_id yes
case_type yes
value yes

Case Attachment Listing

Returns all case attachments (still in flux) associated with a specific case.

  • content://org.commcare.dalvik.case/casedb/attachment/CASE_ID
column required description
case_id yes
attachment_id yes
attachment_type no (potential) Content type for the attachment
value yes The body of the attachment (This will be very large and should be requested manually)

Note that the value returned is the full body of the attachment, which means this API is only viable for communicating with attachments that are not particularly large, depending on the amount of memory on the device.