medic / cht-release-testing

Used to track release testing on medic projects
2 stars 0 forks source link

Create a place via SMS #81

Open ngaruko opened 4 years ago

ngaruko commented 4 years ago

See cht-core#5614: Add feature to create a place via SMS. This is an example of a form that creates a "clinic" under the submitter's parent. It requires for the submitter to be at "health_center" level:

 "meta": {
        "code": "CLINIC",
        "icon": "new-clinic",
        "translation_key": "form.clinic.title"
    },
    "fields": {
        "place_name": {
            "labels": {
                "tiny": { "en": "N" },
                "short": { "translation_key": "report.n.place_name" }
            },
            "position": 0,
            "type": "string",
            "length": [ 1, 30 ],
            "required": true
        }
    },
    "public_form": false,
    "use_sentinel": true
},

along with the "registration" config:

{
      "form":"CLINIC",
      "events":[
        {
          "name":"on_create",
          "trigger":"add_place",
          "params":{
            "contact_type":"clinic"
          },
          "bool_expr":""
        }
      ],
      "messages":[
        {
          "recipient":"reporting_unit",
          "event_type":"parent_invalid",
          "message":[
            {
              "locale":"en",
              "content": "Cannot create a place type \"clinic\" under parent {{parent.name}}(contact type {{parent.type}})"
            }
          ]
        },    
        {
          "recipient":"reporting_unit",
          "event_type":"report_accepted",
          "bool_expr":"doc.place",
          "message":[
            {
              "locale":"en",
              "content":"Place {{place.name}}({{place_id}}) added to {{health_center.name}}"
            }
          ]
        }
      ]
    },

This is an example of a form that creates a "clinic" under a specified health_center. Place documents should now get a "place_id" field when they are edited, which has the same format as the "patient_id" for people - it's even added by the same transition. If you want to view this field in the webapp, you're going to have to edit your contact-summary config and add it as a field, otherwise you can check it in the database directly. When specifying which health_center to create the new clinic under, please use it's "place_id".

"CLINIC2": {
      "meta": {
        "code": "CLINIC2",
        "icon": "new-clinic",
        "translation_key": "form.clinic.title"
      },
      "fields": {
        "parent_id": {
          "labels": {
            "tiny": {
              "en": "P"
            },
            "short": {
              "translation_key": "report.n.parent_id"
            }
          },
          "position": 0,
          "type": "string",
          "length": [
            1,
            30
          ],
          "required": true
        },
        "place_name": {
          "labels": {
            "tiny": {
              "en": "N"
            },
            "short": {
              "translation_key": "report.n.place_name"
            }
          },
          "position": 1,
          "type": "string",
          "length": [
            1,
            30
          ],
          "required": true
        }
      },
      "public_form": false,
      "use_sentinel": true
    },

along with this registration config:

{
      "form":"CLINIC2",
      "events":[
        {
          "name":"on_create",
          "trigger":"add_place",
          "params":{
            "contact_type":"clinic",
            "parent_id": "parent_id"
          },
          "bool_expr":""
        }
      ],
      "messages":[
        {
          "recipient":"reporting_unit",
          "event_type":"parent_invalid",
          "message":[
            {
              "locale":"en",
              "content": "Cannot create a place type \"clinic\" under parent {{parent.name}}(contact type {{parent.type}})"
            }
          ]
        },
        {
          "recipient":"reporting_unit",
          "event_type":"parent_field_not_provided",
          "message":[
            {
              "locale":"en",
              "content":"Parent field is required"
            }
          ]
        },
        {
          "recipient":"reporting_unit",
          "event_type":"parent_not_found",
          "message":[
            {
              "locale":"en",
              "content":"Parent not found"
            }
          ]
        },
        {
          "recipient":"reporting_unit",
          "event_type":"report_accepted",
          "bool_expr":"doc.place",
          "message":[
            {
              "locale":"en",
              "content":"Place {{place.name}}({{place_id}}) added to {{health_center.name}}"
            }
          ]
        }
      ]
    },

The "add_patient" event has also been changed so it supports the "parent_id" config and should be tested as well.

ngaruko commented 3 years ago

Tested by adding 'CLINIC" form to app-settings and sending a sms in the form of 1!CLINIC!<NameOfClinic. Clinic creation SHOULD fail if the submitter (ie the contact associated to phone number used to submit the form) is not a health_center level (which is expected) image

Test passes, report created and actual clinic created otherwise, image image

meghna-khemka commented 3 years ago

https://github.com/medic/cht-core/pull/7230 raised for automation