Skip to content

Commit

Permalink
Support the transform code to convert OpenRosa xform into enketo format
Browse files Browse the repository at this point in the history
Original code by @atton16 in
https://github.com/e-mission/e-mission-phone/tree/rk-unsw/survey-resources

Modified and simplified survey from Bingrong Sun
Modified further by @shankari to work with the enketo core
- remove the UUID field
- remove the final "estimate of commute time" field since we can get that from OpenPATH
- turn on pagination

e-mission/e-mission-docs#732 (comment)
  • Loading branch information
shankari committed May 31, 2022
1 parent 757b512 commit b0f883c
Show file tree
Hide file tree
Showing 9 changed files with 3,406 additions and 0 deletions.
1 change: 1 addition & 0 deletions survey-resources/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8
11 changes: 11 additions & 0 deletions survey-resources/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:8-alpine

WORKDIR /usr/app
COPY package.json package-lock.json index.js ./
RUN apk --no-cache add --virtual native-deps \
g++ gcc libgcc libstdc++ linux-headers make python && \
npm install --quiet node-gyp -g &&\
npm ci &&\
apk del native-deps

ENTRYPOINT node .
25 changes: 25 additions & 0 deletions survey-resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# xform-transformer

Complementary xform transformer for e-mission-phone

## Installation

```bash
npm install
```

## Usage

1. Put your `xml` form (xform) file into `data-xml` directory.
2. Run this app `node .`
3. Grab your json form file under `data-json` directory.
4. Enjoy!

Consult *Input Data Preparation* if you do not have xform file yet.

## Input Data Preparation

1. Build your survey form on [https://www.kobotoolbox.org/](https://www.kobotoolbox.org/)
2. Download the XLS form file
3. Convert `XLS` form to `xml` form (xform) using [http://xlsform.opendatakit.org/](http://xlsform.opendatakit.org/)
4. Done!
1 change: 1 addition & 0 deletions survey-resources/data-json/demo-survey-v1.json

Large diffs are not rendered by default.

1,879 changes: 1,879 additions & 0 deletions survey-resources/data-xml/demo-survey-v1.xml

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions survey-resources/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const fs = require('fs');
const transformer = require('enketo-transformer');

const config = {
inputDir: 'data-xml',
outputDir: 'data-json',
};

console.log('==== xform-transformer ====');
console.log('');
console.log(`Input directory: "${config.inputDir}"`);
console.log(`Output directory: "${config.outputDir}"`);
console.log('');
console.log('Begin transforming xform files...');
console.log('');

fs.readdirSync(`./${config.inputDir}`, {
encoding: 'utf8',
withFileTypes: false,
}).filter(file => {
console.log("Considering "+JSON.stringify(file)+" in filter");
return file.match(/.xml$/);
}).forEach(file => {
const filename = file.substr(0, file.length - 4);
const inputPath = `./${config.inputDir}/${file}`;
const outputPath = `./${config.outputDir}/${filename}.json`;
console.log(`Reading "${inputPath}" ...`);
transformer.transform({
xform: fs.readFileSync(inputPath),
preprocess: doc => doc,
}).then(function(result){
fs.writeFileSync(outputPath, JSON.stringify(result));
console.log(`Successfully saved "${outputPath}"`);
});
});

Loading

0 comments on commit b0f883c

Please sign in to comment.