- This is a prototype - it has not been tested. Do not rely on this in production.
- It will change before it gets released, in particular, the naming will be sensible.
- Clone the repo
- Run
npm ci
- Run
npx webpack
- Now your lib is ready in ./dist/bundle.js
- Rename the
bundle.js
tobar.js
When you're ready to change the function, modify the /src/bar.js file and rebuild.
- Parameters are all objects in the form
{ t: <type>, v: <value> }
, eg:{ t: "string", v: "hello world" }
- The function should return a new object in the same form to be bound into the node in the xml model, eg:
return { t: "number", v: 5 };
- Make sure you're running CHT v4.x
- Install the prototype release:
medic:medic:7824-arbitrary-js
- Create a new CouchDB doc with
"_id": "libs"
with the attachmentbar.js
from above - Upload a new form with a calculate field that calls the custom
test-api
xpath function, example.
<bind nodeset="/data/avg" type="string" calculate="test-api('bar', /data/first , /data/second )" readonly="true()"/>
- The first parameter of the function is the name of the custom function to call as a string, eg: 'bar'.
- The remaining parameters are passed through to the custom function.