Exemplo n.º 1
0
 def post(self, email, password, **kwargs):
     user = User.query.filter_by(email=email).first()
     if user is not None and user.check_password(password):
         user.token = create_access_token(identity=user, fresh=True)
         user.update(last_seen=dt.datetime.utcnow())
         return user
     else:
         raise InvalidUsage.user_not_found()
Exemplo n.º 2
0
 def get(self):
     if not current_user:
         raise InvalidUsage.user_not_found()
     user = current_user
     if user.type == "child":
         return user.parents
     else:
         raise InvalidUsage.unknown_error()
Exemplo n.º 3
0
 def get(self):
     if current_user is not None:
         user = current_user
         user.token = request.headers.environ['HTTP_AUTHORIZATION'].split(
             'Token ')[1]
         return current_user
     else:
         raise InvalidUsage.user_not_found()
Exemplo n.º 4
0
    def post(self, name, surname, email, password, confirmPassword,
             dateofbirth, gender, disease, diseaseInfo, **kwargs):

        if (password != confirmPassword):
            raise InvalidUsage.password_dont_match()
        if not current_user:
            raise InvalidUsage.user_not_found()
        r = requests.post(apiurl + 'ehr',
                          auth=HTTPBasicAuth(
                              current_app.config['EHR_USER'],
                              current_app.config['EHR_USER_PASS']))
        if r.status_code == 201:
            body = {
                "firstNames":
                name,
                "lastNames":
                surname,
                "gender":
                gender,
                "dateOfBirth":
                dateofbirth.isoformat(),
                "partyAdditionalInfo": [{
                    "key": "ehrId",
                    "value": r.json()['ehrId']
                }, {
                    "key": "disease",
                    "value": disease
                }]
            }
            if disease == 'DIABETES':
                body['partyAdditionalInfo'].append({
                    "key":
                    "intendedMeasurements/Day",
                    "value":
                    diseaseInfo["measurements"]
                })
                body['partyAdditionalInfo'].append({
                    "key":
                    "SU_LO",
                    "value":
                    diseaseInfo["SU_LO"]
                })
                body['partyAdditionalInfo'].append({
                    "key":
                    "SU_HI",
                    "value":
                    diseaseInfo["SU_HI"]
                })
            if disease == 'OBESITY':
                body['partyAdditionalInfo'].append({
                    "key":
                    "goalweight",
                    "value":
                    diseaseInfo["goalweight"]
                })
            party = requests.post(apiurl + '/demographics/party',
                                  json=body,
                                  auth=HTTPBasicAuth(
                                      current_app.config['EHR_USER'],
                                      current_app.config['EHR_USER_PASS']))
            print(party)
            print(party.status_code)
            if party.status_code == 201:
                try:
                    ehrid = r.json()['ehrId']
                    child = Child(name, surname, email, password, current_user,
                                  ehrid, **kwargs)
                    db.session.add(child)
                    db.session.commit()
                    return child
                except IntegrityError:
                    db.session.rollback()
                    raise InvalidUsage.user_already_registered()
            raise InvalidUsage.unknown_error()