Ejemplo n.º 1
0
 def post(self, name, surname, email, password, confirmPassword, **kwargs):
     if (password != confirmPassword):
         raise InvalidUsage.password_dont_match()
     try:
         user = Parent(name, surname, email, password,
                       **kwargs).save().save()
         user.token = create_access_token(identity=user)
     except IntegrityError:
         db.session.rollback()
         raise InvalidUsage.user_already_registered()
     return user
Ejemplo n.º 2
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()