예제 #1
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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))
예제 #2
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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
파일: app.py 프로젝트: sirboldilox/hrsdb
    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)
예제 #4
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self):
        """ Upload an ECG datafile to the server.
        The file should be labled as "data" when uploaded

        Example URL **PUT http://hrsdb/ecgdata**

        Example response::

            {
              "response": {
                "id": 1
              }
            }
        """

        args = self.put_parser.parse_args(strict=True)
        ecgfile = args.data

        # Save the file on disk using a uuid
        filename = "%s%s.dat" % (self.file_prefix, uuid())
        ecgfile.save(
            os.path.join(current_app.config['UPLOAD_FOLDER'], filename))

        # Create a new database record for this file
        with open_session() as session:
            ecgdata = ECGData(filename)
            session.add(ecgdata)
            session.flush()
            session.commit()

            print(ecgdata.id)

            return gen_response({"id": ecgdata.id})
예제 #5
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self):
        """ Upload an ECG datafile to the server.
        The file should be labled as "data" when uploaded

        Example URL **PUT http://hrsdb/ecgdata**

        Example response::

            {
              "response": {
                "id": 1
              }
            }
        """

        args = self.put_parser.parse_args(strict=True)
        ecgfile = args.data

        # Save the file on disk using a uuid
        filename = "%s%s.dat" % (self.file_prefix, uuid())
        ecgfile.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename))

        # Create a new database record for this file
        with open_session() as session:
            ecgdata = ECGData(filename)
            session.add(ecgdata)
            session.flush()
            session.commit()

            print(ecgdata.id)

            return gen_response({"id": ecgdata.id})
예제 #6
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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))
예제 #7
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def get(self):
        """
        Fetchs the ECG data for a specific entry from disk
        Example **GET http://hrsdb/ecgdata?id=1**
        
        .. code-block:: javascript

            {
              "response": [
                 0,0,0,0,10,40...
              ]
            }
        """
        args = self.get_parser.parse_args(strict=True)

        with open_session() as session:
            try:
                db_record = query = session.query(ECGData) \
                    .filter(ECGData.id == args.id).one()
            except NoResultFound:
                logger.info("No record found")  # TODO: remove debugging
                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")

            data_file_path = os.path.join(current_app.config['UPLOAD_FOLDER'],
                                          db_record.path)
            with open(data_file_path) as data_file:
                csv_reader = csv.reader(data_file)
                data = list(csv_reader)[0]

            return gen_response(data)
예제 #8
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def get(self):
        """
        Fetchs the ECG data for a specific entry from disk
        Example **GET http://hrsdb/ecgdata?id=1**
        
        .. code-block:: javascript

            {
              "response": [
                 0,0,0,0,10,40...
              ]
            }
        """
        args = self.get_parser.parse_args(strict=True)

        with open_session() as session:
            try:
                db_record = query = session.query(ECGData) \
                    .filter(ECGData.id == args.id).one()
            except NoResultFound:
                logger.info("No record found")    # TODO: remove debugging
                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")

            data_file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], db_record.path)
            with open(data_file_path) as data_file:
                csv_reader = csv.reader(data_file)
                data = list(csv_reader)[0]

            return gen_response(data)
예제 #9
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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))
예제 #10
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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))
예제 #11
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self):
        """Put a new ECG record into the database
        Example JSON Body **PUT http://hrsdb/ecg** ::

            {
              "id": 1,
              "patient_id": 1,
              "sampling_freq": 1000.0
              "timestamp": "2015/05/19" 12:04:59,
              "data_id": 1,
            }

        Example response::

            {
              "response": {
                "id": 1
              }
            }

        """
        args = self.put_parser.parse_args()

        # Convert data_time and validate
        timestamp = utils.str2date(args.timestamp)
        if timestamp is None:
            abort(500)

        return_id = None
        with open_session() as session:
            try:
                patient = session.query(Patient) \
                            .filter(Patient.id == args.patient_id).one()

                ecgdata = session.query(ECGData) \
                            .filter(ECGData.id == args.data_id).one()
            except NoResultFound:
                logger.warn("PUT: No Patient matching id for biometric")
                return gen_response("No matching Patient")
            except Exception as error:
                logger.exception("Exception: %s" % (str(error)))
                return gen_response("Internal server error")

            # Add ecg record
            ecg = patient.add_ecg(
                session,
                args.sampling_freq,
                ecgdata,
                timestamp
            )

            session.commit()
            return gen_response({"id": ecg.id})
예제 #12
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self, biometric_id):
        """Put a new biometric record into the database
        Example JSON Body **PUT http://hrsdb/biometric/0** ::

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

        Example response::

            {
              "response": {
                "id": 1
              }
            }

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

        # Convert data_time and validate
        timestamp = utils.str2date(args.timestamp)
        if timestamp is None:
            abort(500)

        return_id = None
        with open_session() as session:
            try:
                patient = session.query(Patient) \
                            .filter(Patient.id == args.patient_id).one()
            except NoResultFound:
                logger.warn("PUT: No Patient matching id for biometric")
                return gen_response("No matching Patient")
            except Exception as error:
                logger.exception("Exception: %s" % (str(error)))
                return gen_response("Internal server error")

            # Add biometric record
            biometric = patient.add_biometric(session,
                                  args.biometric_type_id,
                                  args.value,
                                  timestamp
                        )

            if biometric is None:
                logger.warn("PUT: No Patient matching id for biometric")
                return gen_response("No matching Biometric type")

            session.commit()
            return gen_response({"id": biometric.id})
예제 #13
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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)
예제 #14
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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)
예제 #15
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self):
        """Put a new ECG record into the database
        Example JSON Body **PUT http://hrsdb/ecg** ::

            {
              "id": 1,
              "patient_id": 1,
              "sampling_freq": 1000.0
              "timestamp": "2015/05/19" 12:04:59,
              "data_id": 1,
            }

        Example response::

            {
              "response": {
                "id": 1
              }
            }

        """
        args = self.put_parser.parse_args()

        # Convert data_time and validate
        timestamp = utils.str2date(args.timestamp)
        if timestamp is None:
            abort(500)

        return_id = None
        with open_session() as session:
            try:
                patient = session.query(Patient) \
                            .filter(Patient.id == args.patient_id).one()

                ecgdata = session.query(ECGData) \
                            .filter(ECGData.id == args.data_id).one()
            except NoResultFound:
                logger.warn("PUT: No Patient matching id for biometric")
                return gen_response("No matching Patient")
            except Exception as error:
                logger.exception("Exception: %s" % (str(error)))
                return gen_response("Internal server error")

            # Add ecg record
            ecg = patient.add_ecg(session, args.sampling_freq, ecgdata,
                                  timestamp)

            session.commit()
            return gen_response({"id": ecg.id})
예제 #16
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self, biometric_id):
        """Put a new biometric record into the database
        Example JSON Body **PUT http://hrsdb/biometric/0** ::

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

        Example response::

            {
              "response": {
                "id": 1
              }
            }

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

        # Convert data_time and validate
        timestamp = utils.str2date(args.timestamp)
        if timestamp is None:
            abort(500)

        return_id = None
        with open_session() as session:
            try:
                patient = session.query(Patient) \
                            .filter(Patient.id == args.patient_id).one()
            except NoResultFound:
                logger.warn("PUT: No Patient matching id for biometric")
                return gen_response("No matching Patient")
            except Exception as error:
                logger.exception("Exception: %s" % (str(error)))
                return gen_response("Internal server error")

            # Add biometric record
            biometric = patient.add_biometric(session, args.biometric_type_id,
                                              args.value, timestamp)

            if biometric is None:
                logger.warn("PUT: No Patient matching id for biometric")
                return gen_response("No matching Biometric type")

            session.commit()
            return gen_response({"id": biometric.id})
예제 #17
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self, patient_id):
        """PUT a new record into the database
        Example JSON Body **PUT http://hrsdb/patient/0** ::

            {
                "first_name": "Bob",
                "last_name": "Smith",
                "gender": 0,
                "date_of_birth": "1997/04/12"
            }

        Example response::

            {
              "response": {
                "id": 1
              }
            }

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

        # Convert data_time and validate
        date_of_birth = utils.str2date(args.date_of_birth)
        if date_of_birth is None:
            abort()

        return_id = None
        with open_session() as session:
            record = Patient(args.first_name,
                             args.last_name,
                             args.gender,
                             date_of_birth)

            session.add(record)
            session.flush()
            session.commit()

            return_id = record.id

        # Check for error handling
        if return_id is None:
            return gen_response("internal server error")
        else:
            return gen_response({"id": return_id})
예제 #18
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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)
예제 #19
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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)
예제 #20
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    def put(self, patient_id):
        """PUT a new record into the database
        Example JSON Body **PUT http://hrsdb/patient/0** ::

            {
                "first_name": "Bob",
                "last_name": "Smith",
                "gender": 0,
                "date_of_birth": "1997/04/12"
            }

        Example response::

            {
              "response": {
                "id": 1
              }
            }

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

        # Convert data_time and validate
        date_of_birth = utils.str2date(args.date_of_birth)
        if date_of_birth is None:
            abort()

        return_id = None
        with open_session() as session:
            record = Patient(args.first_name, args.last_name, args.gender,
                             date_of_birth)

            session.add(record)
            session.flush()
            session.commit()

            return_id = record.id

        # Check for error handling
        if return_id is None:
            return gen_response("internal server error")
        else:
            return gen_response({"id": return_id})
예제 #21
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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)
예제 #22
0
파일: app.py 프로젝트: sirboldilox/hrsdb
    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)