def delete(self): if current_user.type == 'parent': current_user.children = [] db.session.delete(current_user) db.session.commit() return 200 else: raise InvalidUsage.unknown_error()
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()
def post(self): timer = request.args['timer'] if timer == 'null': current_user.timer = None else: current_user.timer = dt.datetime.strptime(timer, '%Y-%m-%dT%H:%M:%S') try: db.session.commit() except IntegrityError: db.session.rollback() raise InvalidUsage.unknown_error() return timer
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()