Skip to content

Commit

Permalink
Merge pull request #130 from dimagi/cz/misc
Browse files Browse the repository at this point in the history
Improve setup instructions and fix JSON examples
  • Loading branch information
snopoke committed Mar 10, 2020
2 parents 731ce5d + 0c09de4 commit 22d9497
Show file tree
Hide file tree
Showing 5 changed files with 570 additions and 206 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ Installation & Quick Start

0a\. Install Python and `pip`. This tool is [tested with Python 2.7, 3.6 and 3.7](https://travis-ci.org/dimagi/commcare-export).

0b\. Sign up for CommCareHQ at https://www.commcarehq.org/register/user if you have not already.
0b\. Sign up for [CommCareHQ](https://www.commcarehq.org/) if you have not already.

1\. Install CommCare Export via `pip`

```
$ pip install commcare-export
```

2\. Visit the CommCareHQ Exchange and add the [Simple CommCare Demo/Tutorial"](https://www.commcarehq.org/exchange/611422532c7ab89d22cca54d57ae89aa/info/) app to a new project space.
2\. Create a project space and application.

3\. Visit the Release Manager, make a build, click the star to release it.

4\. Visit CloudCare and fill out a bunch of forms.
4\. Use Web Apps and fill out some forms.

5\. Try out the example queries in the `examples/` directory, providing your project name on the command line:
5\. Modify one of example queries in the `examples/` directory, modifying the "Filter Value" column
to match your form XMLNS / case type.
See [this page](https://confluence.dimagi.com/display/commcarepublic/Finding+a+Form%27s+XMLNS) to
determine the XMLNS for your form.

```
$ commcare-export \
Expand All @@ -58,7 +61,8 @@ $ commcare-export \
You'll see the tables printed out. Change to `--output-format sql --output URL_TO_YOUR_DB --since DATE` to
sync all forms submitted since that date.

All examples are present in Excel and also equivalent JSON.
All examples are present in Excel and also equivalent JSON, however it is recommended
to use the Excel format as the JSON format may change upon future library releases.

Command-line Usage
------------------
Expand Down Expand Up @@ -332,7 +336,7 @@ Contributing
$ mkvirtualenv commcare-export
$ git clone git@github.com:dimagi/commcare-export.git
$ cd commcare-export
$ pip install -e ".[testing]"
$ pip install -e ".[test]"
$ git checkout -b my-super-duper-feature
```

Expand Down
217 changes: 151 additions & 66 deletions examples/demo-deliveries.json
Original file line number Diff line number Diff line change
@@ -1,75 +1,160 @@
{
"List": [
{ "Emit": {
"table": "Deliveries",
"headings": [
{ "Lit": "id" },
{ "Lit": "Did the mother deliver?" },
{ "Lit": "Delivery Date" },
{ "Lit": "Delivery Type" },
{ "Lit": "Number of children born" }
],
"source": {
"Map": {
"body": {
"List": [
{ "Ref": "id" },
{ "Ref": "form.mother_deliver" },
{ "Ref": "form.delivery_information.delivery_date" },
{ "Ref": "form.delivery_information.delivery_type" },
{ "Ref": "form.delivery_information.num_children" }
"Bind": {
"name": "checkpoint_manager",
"value": {
"Apply": {
"fn": {
"Ref": "get_checkpoint_manager"
},
"args": [
{
"Lit": [
"Deliveries",
"Children"
]
},
"source": {
"Apply": {
"fn": { "Ref": "api_data" },
"args": [
{ "Lit": "form" },
{ "Lit": {
"filter": { "term": { "xmlns.exact": "http://openrosa.org/formdesigner/74CCF2B2-AB85-4F1D-9CD7-5203056BB213" } }
}}
]
}
}
}
]
}
}},
{ "Emit": {
"table": "Children",
"headings": [
{ "Lit": "Form ID" },
{ "Lit": "id" },
{ "Lit": "Gender" },
{ "Lit": "Birth Weight" }
],
"source": {
"Map": {
"body": {
"List": [
{ "Ref": "$.id" },
{ "Ref": "id" },
{ "Ref": "gender" },
{ "Ref": "birth_weight" }
},
"body": {
"Filter": {
"predicate": {
"Apply": {
"fn": {
"Ref": "filter_empty"
},
"args": [
{
"Ref": "$"
}
]
},
"source": {
"FlatMap": {
"body": { "Ref": "form.delivery_information.child_questions.[*]" },
"source": {
"Apply": {
"fn": { "Ref": "api_data" },
"args": [
{ "Lit": "form" },
{ "Lit": {
"filter": { "term": { "xmlns.exact": "http://openrosa.org/formdesigner/74CCF2B2-AB85-4F1D-9CD7-5203056BB213" } }
}}
]
}
}
},
"source": {
"Map": {
"body": {
"List": [
{
"Emit": {
"table": "Deliveries",
"headings": [
{
"Lit": "id"
},
{
"Lit": "Did the mother deliver?"
},
{
"Lit": "Delivery Date"
},
{
"Lit": "Delivery Type"
},
{
"Lit": "Number of children born"
}
],
"source": {
"Map": {
"body": {
"List": [
{
"Ref": "id"
},
{
"Ref": "form.mother_deliver"
},
{
"Ref": "form.delivery_information.delivery_date"
},
{
"Ref": "form.delivery_information.delivery_type"
},
{
"Ref": "form.delivery_information.num_children"
}
]
},
"source": {
"Ref": "`this`"
},
"name": null
}
},
"missing_value": null
}
},
{
"Emit": {
"table": "Children",
"headings": [
{
"Lit": "Form ID"
},
{
"Lit": "id"
},
{
"Lit": "Gender"
},
{
"Lit": "Birth Weight"
}
],
"source": {
"Map": {
"body": {
"List": [
{
"Ref": "$.id"
},
{
"Ref": "id"
},
{
"Ref": "gender"
},
{
"Ref": "birth_weight"
}
]
},
"source": {
"Ref": "form.delivery_information.child_questions.[*]"
},
"name": null
}
},
"missing_value": null
}
}
]
},
"source": {
"Apply": {
"fn": {
"Ref": "api_data"
},
"args": [
{
"Lit": "form"
},
{
"Ref": "checkpoint_manager"
},
{
"Lit": {
"xmlns.exact": "http://openrosa.org/formdesigner/74CCF2B2-AB85-4F1D-9CD7-5203056BB213"
}
}
]
}
}
},
"name": null
}
}
},
"name": null
}
}}
]
}
}
}
Loading

0 comments on commit 22d9497

Please sign in to comment.