Skip to content

Instantly share code, notes, and snippets.

@mandric
Last active December 21, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandric/6362900 to your computer and use it in GitHub Desktop.
Save mandric/6362900 to your computer and use it in GitHub Desktop.
{
"type": "reminder_registration",
"form": { "code": "ANCR" },
"auto_id": {
"property_name": "patient_id",
"format": "11111"
},
"responses": {
"valid": {
"en": "Thank you {{chw_name}} for registering {{patient_name}}. Patient ID is {{patient_id}}. ANC visit is needed in {{weeks}} weeks.",
"sw": "Asante(CHW name) kwa kusajili (name of mother:first,last ). ID namba yake ni (Patient ID).Klinik yake ni baada ya wiki {{weeks}}"
},
"invalid": {}
},
"schedule": "<schedule def...>",
"constraints": [
{
// value constraint
"type": "value",
// expr should return true against each field value
"fields": [
{
"prop": "lmp",
"expr": "typeof {{val}} !== 'undefined'",
},
{
"prop": "name",
"expr": "typeof {{val}} !== 'undefined'"
}
],
"responses": {
"invalid": {
"en": "Please include the patient name and LMP value.",
"sw": "Tafadhali andika jina la mgonjwa na uhakikishe umeweka LMP sahihi."
}
},
// push to doc.errors
"error": {
"code": "required_field",
"message": "No Patient Name or LMP entered.",
}
},
{
"type": "value",
"fields": [
{
"prop": "name",
"expr": "typeof {{val}} !== 'undefined'"
}
],
"responses": {
"invalid": {
"en": "Please include Patient Name",
"sw": "Tafadhali andika jina la mgonjwa."
}
},
"error": {
// push to doc.errors
"code": "required_field",
"message": "No Patient Name entered."
}
},
{
"type": "value",
"fields": [
{
"prop": "lmp",
"expr": "0 < {{val}} < 39",
}
],
"responses": {
"invalid": {
"en": "Invalid LMP; must be between 0-40 weeks.",
"sw": "Umekosea wiki za LMP. Lazima ziwe kati ya 0-40."
}
}
},
{
"type": "value",
"fields": [
{
"prop": "name",
"expr": "{{val}}.length <= 100", // ugh
}
],
"responses": [
{
"en": "Name has exceeded maximum length. Please shorten name to under 100 characters.",
"sw": "Hilo jina ni refu mno. Tafadhali andika jina fupi ambalo haizidi vijineno mia moja."
}
]
},
{
// unique constraint
"type": "unique",
"within" "12 months",
"fields": ['lmp', 'name'],
"responses": [
{
"en": "This patient is already registered on this number.{{patient_id}}.The CHEW will get back to you.",
"sw": "Huyu mama ameshasajiliwa.Namba yake ni {{patient_id}}.CHEW atawasiliana nawe."
}
],
"error": {
"code": "duplicate_record",
"message": "Duplicate record found; {{patient_id}} already registered within 12 months."
}
}
]
}
/*
* Rather than use expr we could have a bunch of preset functions we make
* available like isDefined, isBetween(12,3) hasLengthBetween(1,40), etc?
*
* interesting libraries https://npmjs.org/package/validator
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment