예제 #1
0
def signup():
    data = request.json
    if (not data or not data["name"] or not data["email"]
            or not data["password"] or not data["userType"]):
        return jsonify({"message": "Information entered in not complete"}), 400

    checkUser = None
    if data["userType"] == "patient":
        checkUser = Patient.objects(email=data["email"]).first()
    else:
        checkUser = HealthOfficial.objects(email=data["email"]).first()

    if checkUser:
        return jsonify({"message": "User already exists!"}), 400

    hashedpassword = generate_password_hash(data["password"])

    try:
        _id = None
        if data["userType"] == "patient":
            patient = Patient(name=data["name"],
                              email=data["email"],
                              password=hashedpassword)
            patient.save()
            _id = str(patient._id)

        else:
            healthOfficial = HealthOfficial(name=data["name"],
                                            email=data["email"],
                                            password=hashedpassword)
            healthOfficial.save()
            _id = str(healthOfficial._id)

        token = jwt.encode(
            {
                "id": _id,
                "exp":
                datetime.datetime.utcnow() + datetime.timedelta(days=30),
            },
            Config.SECRET_KEY,
        )

        return jsonify({
            "name": data["name"],
            "email": data["email"],
            "userType": data["userType"],
            "id": _id,
            "token": token.decode("utf-8"),
        })

    except:
        return jsonify({"message": "Bad request"}), 400
예제 #2
0
def add_patient(prId, fName, lName, gender, birth, ehrId, pid, pulse, oxSat, sysBp, diaBp, brFreq, alert, temp):
    db.session.add(Patient(id=prId,
                           firstNames=fName,
                           lastNames=lName,
                           gender=gender,
                           dateOfBirth=birth,
                           ehrId=ehrId,
                           Personnummer=pid,
                           pulse=pulse,
                           oxSaturation=oxSat,
                           sysBloodPressure=sysBp,
                           diaBloodPressure=diaBp,
                           breathingFreq=brFreq,
                           alertness=alert,
                           bodyTemp=temp))