Пример #1
0
    def get(self, patient_id):
        """Get a patient record by ID from the database

        Example **GET http://hrsdb/patient/1** ::

            {
              "response": {
                "id": 1,
                "first_name": "Bob",
                "last_name": "Smith",
                "gender": 0,
                "date_of_birth": "1997/04/12"
              }
            }
        
        """
        with open_session() as session:
            try:
                record = session.query(Patient) \
                    .filter(Patient.id == patient_id).one()
            except NoResultFound:
                logger.info("No record found")
                resp = gen_response("No record found")
                resp.status_code = 404
                return resp

            except Exception as error:
                print("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            return gen_response(to_dict(record))
Пример #2
0
    def get(self):
        """Get all biometric types from the database

        Example **GET http://hrsdb/biometric_types** ::

            {
              "response": [
                {
                  "id": 1,
                  "name": "height",
                  "units" "cm"
                }
                {
                  "id": 2,
                  "name": "weight",
                  "units": "kg"
                }
                ...
              ]
            }

        """
        records = None
        with open_session() as session:
            try:
                records = session.query(BiometricType).all()
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            logger.debug(records)
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)
Пример #3
0
    def get(self, biometric_id):
        """Get a biometric record by ID from the database

        Example **GET http://hrsdb/biometric/1** ::

            {
              "response": {
                  "id": 1,
                  "patient_id": 1,
                  "timestamp": "2015/05/19" 12:04:59,
                  "type_id": 1,
                  "value": "167"
              }
            }

        """
        record = None
        with open_session() as session:
            try:
                record = session.query(Biometric) \
                    .filter(Biometric.id == biometric_id).one()
            except NoResultFound:
                logger.warn("No record found")
                resp = gen_response("No record found")
                resp.status_code = 404
                return resp
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            logger.debug(record)
            return gen_response(to_dict(record))
Пример #4
0
    def get(self, patient_id):
        """Get a patient record by ID from the database

        Example **GET http://hrsdb/patient/1** ::

            {
              "response": {
                "id": 1,
                "first_name": "Bob",
                "last_name": "Smith",
                "gender": 0,
                "date_of_birth": "1997/04/12"
              }
            }
        
        """
        with open_session() as session:
            try:
                record = session.query(Patient) \
                    .filter(Patient.id == patient_id).one()
            except NoResultFound:
                logger.info("No record found")
                resp = gen_response("No record found")
                resp.status_code = 404
                return resp

            except Exception as error:
                print("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            return gen_response(to_dict(record))
Пример #5
0
    def get(self, biometric_id):
        """Get a biometric record by ID from the database

        Example **GET http://hrsdb/biometric/1** ::

            {
              "response": {
                  "id": 1,
                  "patient_id": 1,
                  "timestamp": "2015/05/19" 12:04:59,
                  "type_id": 1,
                  "value": "167"
              }
            }

        """
        record = None
        with open_session() as session:
            try:
                record = session.query(Biometric) \
                    .filter(Biometric.id == biometric_id).one()
            except NoResultFound:
                logger.warn("No record found")
                resp = gen_response("No record found")
                resp.status_code = 404
                return resp
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            logger.debug(record)
            return gen_response(to_dict(record))
Пример #6
0
    def get(self):
        """Get all biometric types from the database

        Example **GET http://hrsdb/biometric_types** ::

            {
              "response": [
                {
                  "id": 1,
                  "name": "height",
                  "units" "cm"
                }
                {
                  "id": 2,
                  "name": "weight",
                  "units": "kg"
                }
                ...
              ]
            }

        """
        records = None
        with open_session() as session:
            try:
                records = session.query(BiometricType).all()
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            logger.debug(records)
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)
Пример #7
0
    def get(self):
        """
        Fetchs the list of biometric records from the database for this patient
        The list can optionally be filtered using a biometric_type id.

        Example **GET http://hrsdb/biometrics?patient_id=1&biometric_type_id=1**
        
        .. code-block:: javascript

            {
              "response": [
                {
                  "id": 1,
                  "patient_id": 1,
                  "timestamp": "2015/05/19" 12:04:59,
                  "type_id": 1,
                  "value": "167"
                }
                {
                  "id":2,
                  ...
                }
              ]
            }

        """
        args = self.parser.parse_args(strict=True)

        with open_session() as session:
            try:
                query = session.query(Biometric) \
                    .filter(Biometric.patient_id == args.patient_id)

                # Optional filter by type_id
                if (args.biometric_type_id):
                    query = query.filter(
                        Biometric.type_id == args.biometric_type_id)

                records = query.all()

            except NoResultFound:
                logger.info("No record found")
                resp = gen_response("No result found")
                resp.status_code = 404
                return resp
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            # Build the response list
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)
Пример #8
0
    def get(self):
        """
        Fetchs the list of biometric records from the database for this patient
        The list can optionally be filtered using a biometric_type id.

        Example **GET http://hrsdb/biometrics?patient_id=1&biometric_type_id=1**
        
        .. code-block:: javascript

            {
              "response": [
                {
                  "id": 1,
                  "patient_id": 1,
                  "timestamp": "2015/05/19" 12:04:59,
                  "type_id": 1,
                  "value": "167"
                }
                {
                  "id":2,
                  ...
                }
              ]
            }

        """
        args = self.parser.parse_args(strict=True)

        with open_session() as session:
            try:
                query = session.query(Biometric) \
                    .filter(Biometric.patient_id == args.patient_id)
                    
                # Optional filter by type_id
                if(args.biometric_type_id):
                    query = query.filter(Biometric.type_id == args.biometric_type_id)
                
                records = query.all()

            except NoResultFound:
                logger.info("No record found")
                resp = gen_response("No result found")
                resp.status_code = 404
                return resp
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            # Build the response list
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)
Пример #9
0
    def get(self):
        """
        Fetchs a list of ecgc records from the database for a specific patient.
        Example **GET http://hrsdb/ecg?patient_id=1**
        
        .. code-block:: javascript

            {
              "response": [
                {
                  "id": 1,
                  "patient_id": 1,
                  "sampling_freq": 1000.0
                  "timestamp": "2015/05/19" 12:04:59,
                  "data_id": 1,
                }
                {
                  "id":2,
                  ...
                }
              ]
            }

        """
        args = self.get_parser.parse_args(strict=True)

        with open_session() as session:
            try:
                records = session.query(ECG) \
                    .filter(ECG.patient_id == args.patient_id) \
                    .all()
            except NoResultFound:
                logger.info("No record found")
                resp = gen_response("No result found")
                resp.status_code = 404
                return resp
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            # Build the response list
            print(records)
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)
Пример #10
0
    def get(self):
        """
        Fetchs a list of ecgc records from the database for a specific patient.
        Example **GET http://hrsdb/ecg?patient_id=1**
        
        .. code-block:: javascript

            {
              "response": [
                {
                  "id": 1,
                  "patient_id": 1,
                  "sampling_freq": 1000.0
                  "timestamp": "2015/05/19" 12:04:59,
                  "data_id": 1,
                }
                {
                  "id":2,
                  ...
                }
              ]
            }

        """
        args = self.get_parser.parse_args(strict=True)

        with open_session() as session:
            try:
                records = session.query(ECG) \
                    .filter(ECG.patient_id == args.patient_id) \
                    .all()
            except NoResultFound:
                logger.info("No record found")
                resp = gen_response("No result found")
                resp.status_code = 404
                return resp
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            # Build the response list
            print(records)
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)
Пример #11
0
    def get(self):
        """Gets all patient records from the database

        Example **GET http://hrsdb/patients**

        .. code-block:: javascript

            {
              "response": [
                {
                  "id": 1,
                  "first_name": "Bob",
                  "last_name": "Smith",
                  "gender": 0,
                  "date_of_birth": "1997/04/12"

                }
                {
                  "id": 2
                  ...
                }
              ]
            }

        """
        with open_session() as session:
            try:
                records = session.query(Patient).all()
            except NoResultFound:
                logger.info("No record found")    # TODO: remove debugging
                return gen_response("No result found")
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            # Build the response list
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)
Пример #12
0
    def get(self):
        """Gets all patient records from the database

        Example **GET http://hrsdb/patients**

        .. code-block:: javascript

            {
              "response": [
                {
                  "id": 1,
                  "first_name": "Bob",
                  "last_name": "Smith",
                  "gender": 0,
                  "date_of_birth": "1997/04/12"

                }
                {
                  "id": 2
                  ...
                }
              ]
            }

        """
        with open_session() as session:
            try:
                records = session.query(Patient).all()
            except NoResultFound:
                logger.info("No record found")  # TODO: remove debugging
                return gen_response("No result found")
            except Exception as error:
                logger.exception("Exeption: %s" % (str(error)))
                return gen_response("Internal server error")

            # Build the response list
            rlist = [to_dict(record) for record in records]
            return gen_response(rlist)