Esempio n. 1
0
    def POST(self):
        params = web.input(district="", subcounty="")
        if params.district and params.subcounty:
            if USE_OLD_WEBHOOKS:
                patient_id = get_webhook_msg_old(params, 'patient_id')
                patient_age = get_webhook_msg_old(params, 'patient_age')
                patient_sex = get_webhook_msg_old(params, 'patient_sex')
            else:
                payload = json.loads(web.data())
                patient_id = get_webhook_msg(payload, 'patient_id')
                patient_age = get_webhook_msg(payload, 'patient_age')
                patient_sex = get_webhook_msg(payload, 'patient_sex')

            district_contacts = CARAMAL_RESEARCH_TEAM.get(params.district, '')
            if district_contacts:
                subcounty_team_contacts = district_contacts.get(params.subcounty, '')
                if subcounty_team_contacts:
                    # time to schedule reminder accordingly
                    msg = (
                        "Patient with ID %s, age of %s and sex %s is "
                        "due for follow up 3 days from now." % (
                            patient_id, int(float(patient_age)), patient_sex))
                    sms_params = {'text': msg, 'to': subcounty_team_contacts}

                    current_time = datetime.datetime.now()
                    run_time = current_time + datetime.timedelta(days=25)
                    queue_schedule(db, sms_params, run_time, None, 'sms')
                    return json.dumps({"message": "scheduled successfully"})

        return json.dumps({"message": "success"})
Esempio n. 2
0
 def POST(self):
     web.header("Content-Type", "application/json; charset=utf-8")
     params = web.input()
     remark = get_webhook_msg(params, 'msg')
     phone = params.phone.replace('+', '')
     with db.transaction():
         r = db.query(
             "SELECT id, reporting_location, district_id, "
             "district, loc_name "
             "FROM reporters_view4 WHERE replace(telephone, '+', '') = $tel "
             "OR replace(alternate_tel, '+', '') = $tel LIMIT 1",
             {'tel': phone})
         if r:
             reporter = r[0]
             db.query(
                 "INSERT INTO alerts(district_id, reporting_location, alert) "
                 "VALUES($district_id, $loc, $msg) ", {
                     'district_id': reporter['district_id'],
                     'loc': reporter['reporting_location'],
                     'msg': remark
                 })
         else:
             db.query("INSERT INTO alerts (alert) VALUES($msg)",
                      {'msg': remark})
         ret = (
             "Thank you for your report, this report will be sent to relevant authorities."
         )
         return json.dumps({"message": ret})
Esempio n. 3
0
    def POST(self, form):
        params = web.input()
        if USE_OLD_WEBHOOKS:
            msg = get_webhook_msg_old(params, 'msg')
        else:
            payload = json.loads(web.data())
            msg = get_webhook_msg(payload, 'msg')

        message = parse_message(msg, form)

        return json.dumps({"message": message})