Skip to content

Instantly share code, notes, and snippets.

@gabrielgilini
Last active August 29, 2015 14:05
Show Gist options
  • Save gabrielgilini/bf18949db2768542c1e3 to your computer and use it in GitHub Desktop.
Save gabrielgilini/bf18949db2768542c1e3 to your computer and use it in GitHub Desktop.
{"program": {
"id": 42, // When editing this will be set
"settings": {
"name": "Program Example #1",
"authors": "John Doe, Jane Doe",
"description": "This is an example of the JSON generated by the Program Creation Tool canvas",
"parameters_of_interest": ["some param of interest", "other param of interest"],
"status": "draft"
},
"start_question": 1,
"questions_attributes": [
{
"id": 1,
"type": "OpenEnded",
"content": {"English": "foo bar en", "Spanish": "foo bar es"},
"scheduling_attributes": {
"type": "scheduled", // Possible values: ["immediate", "scheduled"]
"params": { // Only present if type == "scheduled"
"week": 5,
"wday": 0, // 0 is Monday, 6 is Sunday
"time": "10:30 AM"
}
},
"parameter_of_interest_id": 5,
"connections_attributes": [
{
"type": "OpenEnded",
"content": {"English": "answer content_text"}, // Optional
"targets_attributes": [{"question_id": 3}, {"question_id": 2}] // Ordered by priority
},
{
"type": "NoResponse",
"content": {"English": "no response content_text"}, // Optional
"targets_attributes": [{"question_id": 4}, {"question_id": 6, "persisted_id": 82, "_destroy": true}] // The connection to the question with id == 6 was removed
// since this connection already persisted to the db we have persisted_id
}
],
"position_attributes": {"x": 300, "y": 200}
},
{
"id": 2,
"type": "MultipleChoice",
"content": {"English": "multiple foo"},
"scheduling_attributes": {
"type": "immediate"
},
"branching_attributes": {
"ethnicities": ["Unknown or Declined"],
"genders": ["male", "undetermined"],
"minimum_age": 5,
"maximum_age": 42
},
"connections_attributes": [
{
"type": "A",
"targets_attributes": [{"question_id": 3}, {"question_id": 4, "persisted_id": 37, "_destroy": true}], // This connection was deleted before being persisted to the db
// so we send _destroy == true but no persisted_id
"correct": true
},
{
"type": "B",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 4}],
"correct": false
},
{
"type": "C",
"content": {"English": "answer content_text"},
"targets_attributes": [], // The answer is not connected to another question
"correct": false
},
{
"type": "NoResponse",
"targets_attributes": [{"question_id": 4}]
}
],
"position_attributes": {"x": 350, "y": 250}
},
{
"id": 3,
"type": "TrueFalse",
"content": {"English": "wu tang is for the children"},
"scheduling_attributes": {
"type": "immediate"
},
"branching_attributes": {
"locations": ["05005", "00110"],
"races": ["Hispanic", "Other"],
"conditions_attributes": [{"code": "001"}, {"code": "003"}, {"code": "010", "id": 1, "_destroy": true}] // Condition ids, the one with id == 1 was removed
},
"connections_attributes": [
{
"type": "True",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 4}],
"correct": false
},
{
"type": "False",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 4}],
"correct": true
},
{
"type": "NoResponse",
"content": {"English": "no response content_text"},
"targets_attributes": [{"question_id": 4}]
}
],
"position_attributes": {"x": 400, "y": 300}
},
{
"id": 4,
"type": "YesNo",
"content": {"English": "wu tang is for the children"},
"scheduling_attributes": {
"type": "immediate"
},
"connections_attributes": [
{
"type": "Yes",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 5}],
"correct": true
},
{
"type": "No",
"targets_attributes": [{"question_id": 6}],
"correct": false
},
{
"type": "NoResponse",
"content": {"English": "no response content_text"},
"targets_attributes": []
}
],
"position_attributes": {"x": 450, "y": 350}
},
{
"id": 5,
"type": "Numerical",
"content": {"English": "numerical range"},
"scheduling_attributes": {
"type": "immediate"
},
"connections_attributes": [
{
"type": "Numerical",
"params": "0-100",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 6}],
"correct": false
},
{
"type": "Numerical",
"params": "101-200",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 6}],
"correct": false
},
{
"type": "Numerical",
"params": "201-300",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 7}],
"correct": true
},
{
"type": "NoResponse",
"targets_attributes": [{"question_id": 8}]
}
],
"position_attributes": {"x": 500, "y": 400}
},
{
"id": 6,
"type": "Scale",
"content": {"English": "multiple foo"},
"scheduling_attributes": {
"type": "immediate"
},
"connections_attributes": [
{
"type": "Scale",
"params": "1-7",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 7}]
},
{
"type": "NoResponse",
"content": {"English": "no response content_text"},
"targets_attributes": [{"question_id": 8}]
}
],
"position_attributes": {"x": 550, "y": 450}
},
{
"id": 7,
"type": "Date",
"content": {"English": "foo bar en", "Spanish": "foo bar es"},
"scheduling_attributes": {
"type": "immediate"
},
"connections_attributes": [
{
"type": "Date",
"content": {"English": "answer content_text"},
"targets_attributes": [{"question_id": 8}]
},
{
"type": "NoResponse",
"content": {"English": "no response content_text"},
"targets_attributes": [{"question_id": 8}]
}
],
"position_attributes": {"x": 600, "y": 500}
},
{
"id": 8,
"type": "NoResponse",
"content": {"English": "last one"},
"scheduling_attributes": {
"type": "immediate"
},
"connections_attributes": [
{
"type": "NoResponse",
"content": {"English": "no response content_text"},
"targets_attributes": []
}
],
"position_attributes": {"x": 650, "y": 550}
},
{
"id": 9,
"_destroy": true, // Set this to true to destroy a question
"persisted_id": 42 // This is the question id on the database,
// it must be set when _destroy == true
}
]
}}
@danielnc
Copy link

Please add the following changes:

  {
    start_question_id: 1,
    questions_attributes: [
      {
        id: 1,
        type: "OpenEnded",
        content: {english: "foo bar en", spanish: "foo bar es"},
        scheduling_attributes: {
          type: "scheduled",
          params: {
            week: 5,
            day: 0,
            time: "10:30 AM"
          }
        },
        params_of_interest_id: 10,
        connections_attributes: {
          response: {
            content: {english: "answer content_text"},
            targets_attributes: [{id: 3}, {id: 2}]
          },
          no_response: {
            content: {english: "no response content text"},
            targets_attributes: [{id: 2}]
          }
        },
        position_attributes: {x: 300, y: 200}
      },
      {
        id: 2,
        type: "MultipleChoice",
        content: {english: "multiple foo"},
        scheduling_attributes: {
          type: "immediate"
        },
        branching_attributes: {
          literacy: ["Standard", "Low"],
          patient_control: ["Good Control", "Bad Control"],
          location: ["05005", "00110"],
          literacy: ["Standard"],
          race: ["Hispanic", "Other"],
          conditions_attributes: [{"code": "001"}, {"code": "003"}, {"code": "010", id: 1, _destroy: true}]
        },
        connections_attributes: {
          a: {
            content: {english: "answer content_text"},
            targets_attributes: [{id: 2}]
          },
          b: {
            content: {english: "answer content_text"},
            targets_attributes: []
          },
          no_response: {
            targets_attributes: [{id: 3}]
          }
        },
        position_attributes: {x: 350, y: 250}
      },
      {
        id: 4,
        type: "Numerical",
        content: {english: "numerical range"},
        scheduling_attributes: {
          type: "immediate"
        },
        connections_attributes: {
          "0-100" => {
            content: {english: "answer content_text"},
            targets_attributes: [{id: 3}]
          },
          "101-200" => {
            content: {english: "answer content_text"},
            targets_attributes: [{id: 3}]
          },
          "201-250" => {
            content: {english: "answer content_text"},
            targets_attributes: []
          },
          "251-300" => {
            content: {english: "answer content_text"},
            targets_attributes: []
          },
          "301-350" => {
            content: {english: "answer content_text"},
            targets_attributes: []
          },
          no_response: {
            targets_attributes: []
          }
        },
        position_attributes: {x: 500, y: 400}
      },
    ]
  }

@danielnc
Copy link

Regarding branching info, today we'll only have those:

:locations, :ethnicities, :races, :genders, :age_range

@danielnc
Copy link

Sorry, age_range is now 2 fields: minimum_age and maximum_age

@danielnc
Copy link

{  
   "start_question_id":1,
   "questions_attributes":[  
      {  
         "id":1,
         "type":"OpenEnded",
         "content":{  
            "English":"foo bar en",
            "Spanish":"foo bar es"
         },
         "scheduling_attributes":{  
            "type":"scheduled",
            "params":{  
               "week":5,
               "day":0,
               "time":"10:30 AM"
            }
         },
         "params_of_interest_id":10,
         "connections_attributes":[  
            {  
               "type":"OpenEnded",
               "content":{  
                  "English":"answer content_text"
               },
               "targets_attributes":[  
                  {  
                     "id":3
                  },
                  {  
                     "id":2
                  }
               ]
            },
            {  
               "type":"NoResponse",
               "targets_attributes":[  
                  {  
                     "id":2
                  }
               ]
            }
         ],
         "position_attributes":{  
            "x":300,
            "y":200
         }
      },
      {  
         "id":2,
         "type":"MultipleChoice",
         "content":{  
            "English":"multiple foo"
         },
         "scheduling_attributes":{  
            "type":"immediate"
         },
         "branching_attributes":{  
            "ethnicities":[  
               "Not Hispanic or Latino"
            ],
            "genders":[  
               "male",
               "female"
            ],
            "locations":[  
               "05005",
               "00110"
            ],
            "minimum_age":10,
            "maximum_age":30,
            "races":[  
               "Hispanic",
               "Other"
            ],
            "conditions_attributes":[  
               {  
                  "code":"001"
               },
               {  
                  "code":"003"
               }
            ]
         },
         "connections_attributes":[  
            {  
               "type":"A",
               "content":{  
                  "English":"answer content_text"
               },
               "targets_attributes":[  
                  {  
                     "id":2
                  }
               ]
            },
            {  
               "type":"B",
               "content":{  
                  "English":"answer content_text"
               },
               "targets_attributes":[  

               ]
            },
            {  
               "type":"NoResponse",
               "targets_attributes":[  
                  {  
                     "id":3
                  }
               ]
            }
         ],
         "position_attributes":{  
            "x":350,
            "y":250
         }
      },
      {  
         "id":4,
         "type":"Numerical",
         "content":{  
            "English":"numerical range"
         },
         "scheduling_attributes":{  
            "type":"immediate"
         },
         "connections_attributes":[  
            {  
               "type":"Numerical",
               "params":"0-100",
               "content":{  
                  "English":"answer content_text"
               },
               "targets_attributes":[  
                  {  
                     "id":3
                  }
               ]
            },
            {  
               "type":"Numerical",
               "params":"101-200",
               "content":{  
                  "English":"answer content_text"
               },
               "targets_attributes":[  
                  {  
                     "id":3
                  }
               ]
            },
            {  
               "type":"Numerical",
               "params":"201-300",
               "content":{  
                  "English":"answer content_text"
               },
               "targets_attributes":[  

               ]
            },
            {  
               "type":"NoResponse",
               "targets_attributes":[  

               ]
            }
         ],
         "position_attributes":{  
            "x":500,
            "y":400
         }
      }
   ]
}

@danielnc
Copy link

        scheduling_attributes: {
          type: "scheduled",
          params: {
            week: 5,
            wday: 0,
            time: "10:30 AM"
          }
        },

Change day to wday

And we need to send the offset of the browser

@danielnc
Copy link

Change params_of_interest_id to parameter_of_interest_id

@danielnc
Copy link

Add system: "CMD" to each condition attribute

@danielnc
Copy link

{  
   "program":{  
      "id":1,
      "start_question_id":1,
      "errors":{  

      },
      "questions_attributes":[  
         {  
            "persisted_id":1,
            "type":"OpenEnded",
            "content":{  
               "English":"foo bar en",
               "Spanish":"foo bar es"
            },
            "parameter_of_interest_id":null,
            "errors":{  

            },
            "scheduling_attributes":{  
               "type":"scheduled",
               "params":{  
                  "preferred_scheduling":{  
                     "week":5,
                     "wday":0,
                     "time":"10:30 AM",
                     "errors":{  

                     }
                  }
               }
            },
            "branching_attributes":null,
            "connections_attributes":[  
               {  
                  "type":"OpenEnded",
                  "content":{  
                     "English":"answer content_text"
                  },
                  "errors":{  

                  },
                  "targets_attributes":[  
                     {  
                        "question_id":2,
                        "persisted_id":5
                     },
                     {  
                        "question_id":3,
                        "persisted_id":6
                     }
                  ]
               },
               {  
                  "type":"NoResponse",
                  "content":{  

                  },
                  "errors":{  

                  },
                  "targets_attributes":[  
                     {  
                        "question_id":3,
                        "persisted_id":7
                     }
                  ]
               }
            ]
         },
         {  
            "persisted_id":3,
            "type":"MultipleChoice",
            "content":{  
               "English":"multiple foo"
            },
            "parameter_of_interest_id":null,
            "errors":{  

            },
            "scheduling_attributes":{  
               "type":"immediate"
            },
            "branching_attributes":{  
               "locations":[  
                  "05005",
                  "00110"
               ],
               "ethnicities":[  
                  "Not Hispanic or Latino"
               ],
               "races":[  
                  "Hispanic",
                  "Other"
               ],
               "genders":[  
                  "male",
                  "female"
               ],
               "minimum_age":10,
               "maximum_age":30,
               "errors":{  

               },
               "conditions_attributes":[  
                  {  
                     "id":1,
                     "system":"CMD",
                     "code":"001",
                     "value":null,
                     "updated_at":"2014-08-29T20:49:18+07:00",
                     "errors":{  

                     }
                  },
                  {  
                     "id":2,
                     "system":"CMD",
                     "code":"002",
                     "value":null,
                     "updated_at":"2014-08-29T20:49:18+07:00",
                     "errors":{  

                     }
                  }
               ]
            },
            "connections_attributes":[  
               {  
                  "type":"A",
                  "content":{  
                     "English":"answer content_text"
                  },
                  "errors":{  

                  },
                  "targets_attributes":[  
                     {  
                        "question_id":2,
                        "persisted_id":1
                     }
                  ]
               },
               {  
                  "type":"B",
                  "content":{  
                     "English":"answer content_text"
                  },
                  "errors":{  

                  },
                  "targets_attributes":[  

                  ]
               },
               {  
                  "type":"NoResponse",
                  "content":{  

                  },
                  "errors":{  

                  },
                  "targets_attributes":[  
                     {  
                        "question_id":2,
                        "persisted_id":2
                     }
                  ]
               }
            ]
         },
         {  
            "persisted_id":2,
            "type":"Numerical",
            "content":{  
               "English":"numerical range"
            },
            "parameter_of_interest_id":null,
            "errors":{  

            },
            "scheduling_attributes":{  
               "type":"immediate"
            },
            "branching_attributes":null,
            "connections_attributes":[  
               {  
                  "type":"Numerical",
                  "content":{  
                     "English":"answer content_text"
                  },
                  "errors":{  

                  },
                  "targets_attributes":[  
                     {  
                        "question_id":3,
                        "persisted_id":3
                     }
                  ]
               },
               {  
                  "type":"Numerical",
                  "content":{  
                     "English":"answer content_text"
                  },
                  "errors":{  

                  },
                  "targets_attributes":[  
                     {  
                        "question_id":3,
                        "persisted_id":4
                     }
                  ]
               },
               {  
                  "type":"Numerical",
                  "content":{  
                     "English":"answer content_text"
                  },
                  "errors":{  

                  },
                  "targets_attributes":[  

                  ]
               },
               {  
                  "type":"Numerical",
                  "content":{  
                     "English":"answer content_text"
                  },
                  "errors":{  

                  },
                  "targets_attributes":[  

                  ]
               },
               {  
                  "type":"NoResponse",
                  "content":{  

                  },
                  "errors":{  

                  },
                  "targets_attributes":[  

                  ]
               }
            ]
         }
      ]
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment