Esempio n. 1
0
    def add_nota_fiscal(patient_id, appointment_id=0):
        authorized_roles = [ constants.ROLE_DENTIST, constants.ROLE_NURSE,
                        constants.ROLE_ASSISTANT, constants.ROLE_SECRETARY ]
        if session['role'] not in authorized_roles:
            return abort(403)
        patient, appointment = checks.get_patient_appointment(patient_id,
                                                                appointment_id)
        
        document_form = NotaFiscalForm(request.form)
        if request.method == 'POST' and document_form.validate():
            document_data = request.files[document_form.document.name].read()
            if document_data:
                new_file = insert_document_in_db(document_data,
                                document_form.document_type.data, appointment)
                
                values = {
                    'patient_id': patient_id,
                    'document_id': new_file.id,
                }
                new_nota_fiscal = statements.NotaFiscalBr(**values)
                meta.session.add(new_nota_fiscal)
                meta.session.commit()

        return render_template('add_nota_fiscal.html', patient=patient,
                                            appointment=appointment,
                                            document_form=document_form)
Esempio n. 2
0
def add_patient_survey(appointment_id):
    patient, appointment = checks.get_patient_appointment(appointment_id=appointment_id)
    patient_survey_form = PatientSurveyForm(request.form)

    patient_survey_form.appointment_id.choices = [
        (appointment.id, appointment.agenda.starttime)
        for appointment in meta.session.query(schedule.Appointment)
        .filter(schedule.Appointment.patient_id == patient.id)
        .all()
    ]

    if patient_survey_form.validate():
        # !!! Beware of this two variables really seemful ! Bad.
        anamnesis_appointment = (
            meta.session.query(schedule.Appointment)
            .filter(schedule.Appointment.id == patient_survey_form.appointment_id.data)
            .one()
        )
        appointment_anamnesis = (
            meta.session.query(anamnesis.Anamnesis)
            .filter(anamnesis.Anamnesis.appointment_id == anamnesis_appointment.id)
            .all()
        )

        document_data = request.files[patient_survey_form.document.name].read()
        if document_data:
            new_file = insert_document_in_db(document_data, constants.FILE_ANAMNESIS, anamnesis_appointment)
            for anamnesis_entry in appointment_anamnesis:
                if not anamnesis_entry.file_id:
                    anamnesis_entry.file_id = new_file.id
                    meta.session.commit()

    return redirect(url_for("list_anamnesis", patient_id=patient.id, appointment_id=appointment.id))
Esempio n. 3
0
def add_file_to_tooth_event(patient_id, appointment_id, event_id):
    authorized_roles = [ constants.ROLE_DENTIST, constants.ROLE_NURSE,
                        constants.ROLE_ASSISTANT ]
    if session['role'] not in authorized_roles:
        return abort(403)

    patient, appointment = checks.get_patient_appointment(patient_id,
                                                                appointment_id)
    event = ( meta.session.query(teeth.Event)
                .filter(teeth.Event.id == event_id)
                .one()
    )
    document_form = DocumentForm(request.form)
    if document_form.validate():
        document_data = request.files[document_form.document.name].read()
        if document_data:
            new_file = insert_document_in_db(document_data, 
                                document_form.document_type.data, appointment)
            if new_file not in event.files:
                event.files.append(new_file)
                meta.session.commit()

    return redirect(url_for('show_tooth', patient_id=patient_id,
                                        appointment_id=appointment_id,
                                        tooth_codename=event.tooth.codename))