Skip to Content
Menu
This question has been flagged
948 Views

I'm developing an api in odoo that creates a patient using the application of medical lab.



``` 

@app.route('/patient', methods=['POST'])

def addPatient():

    title = request.json['title']

    patient = request.json['patient'] //id of res.partner

    name = request.json['name']

    gender = request.json['gender']

    dob = request.json['dob']

    phone = request.json['phone']

    visa_info = request.json['visa_info']

    id_proof_number = request.json['id_proof_number']

    blood_group = request.json['blood_group']

    email = request.json['email']

    idcreated = models.execute_kw(db, uid, password, 'lab.patient', 'create',

                                 [{'title': title, 'patient': patient, 'name': name, 'gender': gender, 'dob': dob,

                                   'phone': phone,'visa_info': visa_info, "id_proof_number": id_proof_number,

                                   "blood_group": blood_group, 'email': email}])

    print("New Patient Created")

    return jsonify({'msg':'Pacient inserted correctly','success': True, 'nuevo id': idcreated})

``` 


My problem is that I can only create a patient if there is a res.partner created before. I can create first a res.partner and later a lab.patient. But i have using the interface of the application of medical laboratory management and in the interface i can create a partner from patient, apparently i can create a parent model (res_partner) from a child model (lab_patient). I want to avoid using first a function to create a partner and later the patient.


I want to create a patient no matter if there is a partner or no. If there is not a partner created, i want to create a partner from the function of addPatient.


In other words, using postman or insomnia, after running the command post, i hope i can create a new patient, if exists a partner. If there is not a partner, the function of addPatient will create the partner.


I know i have to use many2one, maybe another function that calls an external function that create a partner before creating a patient, but inside the function addPatient, my question and problem is how can I implement that function inside the function addPatient.


Thanks in advance

Avatar
Discard