Example #1
0
def add_clinic_gesture_to_clinic_report(appointment_id):
    form = ChooseClinicGestureForReportForm(request.form)
    form.clinic_gesture_id.choices = [
        ( cg.id, cg.specialty.name[0:3] + " " + cg.name ) for cg in
            meta.session.query(act.ClinicGesture)
                .filter(act.ClinicGesture.before_first_patient.is_(False),
                        act.ClinicGesture.after_last_patient.is_(False),
                        act.ClinicGesture.before_each_appointment.is_(False),
                        act.ClinicGesture.after_each_appointment.is_(False)
                )
                .join(act.Specialty)
                .order_by(act.Specialty.name,
                            act.ClinicGesture.name )
                .all()
    ]
    if form.validate():
        if not form.anatomic_location.data:
            form.anatomic_location.data = 0
        try:
            if int(form.anatomic_location.data) >= 0 : 
                add_cg_to_cr(appointment_id, form.clinic_gesture_id.data,
                                                form.anatomic_location.data)
        except ValueError:
            for anatomic_location in\
                            teeth.get_teeth_list(form.anatomic_location.data) :
                add_cg_to_cr(appointment_id, form.clinic_gesture_id.data,
                                                        anatomic_location)
        
    return redirect(url_for('view_clinic_report', 
                                            appointment_id=appointment_id))
Example #2
0
def choose_clinic_gestures_from_cotation(appointment_id):
    """
        The POST action comes from view_clinic_report.
    """
    patient, appointment = checks.get_patient_appointment(
                                                appointment_id=appointment_id)
    form = ChooseCotationForReportForm(request.form)
    form.cotation_id.choices = [ (cot.id, cot.gesture.name) for cot in
        meta.session.query(act.Cotation)
            .join(act.Gesture, act.Specialty)
            .order_by(act.Specialty.name, act.Gesture.name)
            .all()
    ]
    if form.validate():
        # define which cotation we are working with
        cotation = ( meta.session.query(act.Cotation)
            .filter(act.Cotation.id == form.cotation_id.data)
            .one()
        )
        # Define anatomic_locations we are working with
        anatomic_locations = ""
        if not form.anatomic_location.data:
            form.anatomic_location.data = 0
        try:
            if int(form.anatomic_location.data) >= 0 :
                anatomic_locations = str(form.anatomic_location.data)
        except ValueError:
            for idx, anat_loc in\
                enumerate(teeth.get_teeth_list(form.anatomic_location.data)) :
                if idx:
                    anatomic_locations = anatomic_locations + ","
                anatomic_locations = anatomic_locations + str(anat_loc)

        # create form with clinic_gestures associated with this cotation
        cg_form = ClinicGesturesFromCotationForm(request.form)
        for cg_cot_ref in sorted(cotation.clinic_gestures,
                                key=lambda cg_cot_ref: (
                                    cg_cot_ref.appointment_number,
                                    cg_cot_ref.sequence )
                                                                         ):
            cg_keep_form = ClinicGestureKeepForm(request.form)
            cg_keep_form.clinic_gesture_id = cg_cot_ref.clinic_gesture_id
            cg_keep_form.clinic_gesture_data = cg_cot_ref.clinic_gesture.name
            cg_keep_form.keep = cg_cot_ref.appears_on_clinic_report
            cg_form.clinic_gestures.append_entry(cg_keep_form)
        
#        cg_form.clinic_gestures.entries = [ entry for entry in 
#            cg_form.clinic_gestures.entries if entry.data['clinic_gesture_id'] 
#        ]
        cg_form.price.data = cotation.price
        return render_template('choose_clinic_gestures_from_cotation.html', 
                                    anatomic_locations=anatomic_locations,
                                                    patient=patient,
                                                    appointment=appointment,
                                                    cotation_id=cotation.id,
                                                                form=cg_form,
                                                    constants=constants)
    return redirect(url_for('view_clinic_report', 
                                                appointment_id=appointment.id))
Example #3
0
def choose_cg_from_cot_inserted_in_cr(appointment_id, cotation_id, anat_loc):

    def _add_cg_to_cr(a_id, cg_id, anat_loc, cot_id, price):

        clinic_report = add_cg_to_cr(a_id, cg_id, anat_loc)

        cg_cot_refs = ( 
            meta.session.query(act.ClinicGestureCotationReference)
            .filter(
                act.ClinicGestureCotationReference.clinic_gesture_id == cg_id,
                act.ClinicGestureCotationReference.cotation_id == cot_id)
            .all()
        )

        for cg_cot_ref in cg_cot_refs:
            if cg_cot_ref.official_cotation:
                new_administrativ_cotation = add_appointment_cotation(
                                                    appointment_id=a_id,
                                                    cotation_id=cot_id,
                                                    price=price,
                                                    anatomic_location=anat_loc
                )

    form = ClinicGesturesFromCotationForm(request.form)
    if form.validate():
        cotation = ( meta.session.query(act.Cotation)
            .filter(act.Cotation.id == cotation_id)
            .one()
        )
        for entry in form.clinic_gestures.entries:
            if not entry.keep.data:
                continue
            if anat_loc_is_list(anat_loc):
                for anatomic_location in teeth.get_teeth_list(anat_loc):
                    clinic_report = _add_cg_to_cr(appointment_id, 
                                        int(entry.clinic_gesture_id.data),
                                        anatomic_location,
                                        cotation_id,
                                        form.price.data)
            else:
                clinic_report = _add_cg_to_cr(appointment_id, 
                                        int(entry.clinic_gesture_id.data), 
                                        str(anat_loc),
                                        cotation_id,
                                        form.price.data)
    
    return redirect(url_for('view_clinic_report', 
                                                appointment_id=appointment_id))