Esempio n. 1
0
    def test_row_to_dict(self):
        """ Test row_to_dict """

        row_1 = model.Locations(name="Test",
                              parent_location=2,
                              case_report=1)

        result_dict = util.row_to_dict(row_1)
        self.assertEqual(result_dict["name"], "Test")
        self.assertEqual(result_dict["parent_location"], 2)
        self.assertEqual(result_dict["case_report"], 1)
        row_2 = model.Data(uuid="test-uuid",
                         date=datetime(2016, 1, 1),
                         variables={"tot_1": 4}
                         )
        result_dict = util.row_to_dict(row_2)
        self.assertEqual(result_dict["uuid"], "test-uuid")
        self.assertEqual(result_dict["date"], datetime(2016, 1, 1))
        self.assertEqual(result_dict["variables"], {"tot_1": 4})

        # Test with a tuple of rows
        result_dict = util.row_to_dict((row_1, row_2))

        self.assertIn("data", result_dict)
        self.assertIn("locations", result_dict)
        self.assertEqual(result_dict["data"]["variables"], {"tot_1": 4})
        self.assertEqual(result_dict["locations"]["name"], "Test")
Esempio n. 2
0
    def get(self, alert_id):
        result = db.session.query(model.Data).filter(
            model.Data.variables["alert_id"].astext == alert_id).first()

        if result:
            if not is_allowed_location(result.clinic, g.allowed_location):
                return {}

            if result.variables.get("alert_type", None) == "threshold":
                other_data = rows_to_dicts(
                    db.session.query(model.Data).filter(
                        model.Data.variables["master_alert"].astext ==
                        result.uuid).all())
            else:
                other_data = {}
            return jsonify({
                "alert": row_to_dict(result),
                "linked_alerts": other_data
            })
        else:
            result = db.session.query(model.DisregardedData).filter(
                model.DisregardedData.variables["alert_id"].astext ==
                alert_id).first()
            if result:
                return jsonify({
                    "alert": row_to_dict(result),
                    "linked_alerts": {}
                })
            return {}
Esempio n. 3
0
 def get(self, device_id):
     location_filter = _get_by_device_id_filter(device_id)
     query = db.session.query(model.Locations).filter(location_filter)
     if query.count() == 0:
         abort(404,
               message="No location matching deviceid: {!r}".format(
                   device_id))
     else:
         return jsonify(row_to_dict(query.one()))
Esempio n. 4
0
 def get(self, location_id):
     return jsonify(row_to_dict(Location.get_location_by_id(location_id)))
Esempio n. 5
0
 def get(self, variable_id):
     return row_to_dict(
         db.session.query(model.AggregationVariables).filter(
             model.AggregationVariables.id == variable_id).first())