From 5d53997e2518f98cd6efcb619d9b8f8aa6ea1234 Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Thu, 21 Aug 2014 17:03:42 +0200 Subject: [PATCH 1/2] dossiers: printing the whole patient record in pdf format Closes #3109 --- .../templates/dossiers/patientrecord_print.html | 325 +++++++++++++++++++++ .../dossiers/patientrecord_print_coordinators.html | 9 + .../templates/dossiers/patientrecord_update.html | 3 + calebasse/dossiers/urls.py | 1 + calebasse/dossiers/views.py | 33 ++- calebasse/static/js/calebasse.dialog.js | 5 +- 6 files changed, 373 insertions(+), 3 deletions(-) create mode 100644 calebasse/dossiers/templates/dossiers/patientrecord_print.html create mode 100644 calebasse/dossiers/templates/dossiers/patientrecord_print_coordinators.html diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_print.html b/calebasse/dossiers/templates/dossiers/patientrecord_print.html new file mode 100644 index 0000000..9c3ac5f --- /dev/null +++ b/calebasse/dossiers/templates/dossiers/patientrecord_print.html @@ -0,0 +1,325 @@ +{% load dossiers %} + + + +
+

{{ object.last_name }} {{ object.first_name }} - Dossier {{ object.id }}

+
+ +
+

Général

+ + {% if future_state %} +

État à venir du dossier: {{ current_state.status.name.lower }} à partir du {{ current_state.date_selected|date:"d/m/Y" }}

+ {% else %} +

État courant du dossier: {{ current_state.status.name.lower }} depuis le {{ current_state.date_selected|date:"d/m/Y" }}

+ {% endif %} + {% if object.pause_comment %}


{{ object.pause_comment }}

{% endif %} +
+ + + +
+

Fiche administrative

+

Inscription

+
    +
  • {{ object.analysemotive|default_if_none:'' }}
  • +
  • {{ object.familymotive|default_if_none:'' }}
  • +
  • {{ object.provenance|default_if_none:'' }}
  • +
  • {{ object.advicegiver|default_if_none:'' }}
  • +
  • {{ object.provenanceplace|default_if_none:'' }}
  • +
+ +

Sortie

+
    +
  • {{ object.outmotive|default_if_none:'' }}
  • +
  • {{ object.outto|default_if_none:'' }}
  • +
+ +

Famille

+
    +
  • {{ object.sibship_place|default_if_none:'' }}
  • +
  • {{ object.nb_children_family|default_if_none:'' }}
  • +
  • {{ object.twinning_rank|default_if_none:'Aucun' }}
  • +
  • {{ object.parental_authority|default_if_none:'' }}
  • +
  • {{ object.family_situation|default_if_none:'' }}
  • +
  • {{ object.child_custody|default_if_none:'' }}
  • +
  • {{ object.job_mother|default_if_none:'' }}
  • +
  • {{ object.job_father|default_if_none:'' }}
  • +
  • {{ object.rm_mother|default_if_none:'' }}
  • +
  • {{ object.rm_father|default_if_none:'' }}
  • +
  • {{ object.family_comment|default_if_none:'' }}
  • +
+ +

Transport

+
    +
  • {{ object.transporttype|default_if_none:'' }}
  • +
  • {{ object.transportcompany|default_if_none:'' }}
  • + {% if last_prescription %}
  • {{ last_prescription.created }}
  • {% endif %} +
+ +

Suivi du patient

+
    + {% include "dossiers/patientrecord_print_coordinators.html" %} +
  • {{ object.externaldoctor|default_if_none:'' }}
  • +
  • {{ object.externalintervener|default_if_none:'' }}
  • +
+ +

Mesures de protection

+
    + {% for protection in object.protectionstate_set.all %} +
  • +

    Depuis le {{ protection.start_date }} : {{ protection.status.name }}

    +
      + {% if protection.end_date %}
    • : {{ protection.end_date }}
    • {% endif %} + {% if protection.comment %}
    • : {{ protection.comment }}
    • {% endif %} +
    +
  • + {% endfor %} +
+
+ + + +
+

Adresses/contacts

+ {% if object.policyholder.contact_comment %} +

+ + {{ object.policyholder.contact_comment }} +

+ {% endif %} +
+ + + {% for contact in object.contacts.all %} + {% if not contact.addresses.all %} + + {% endif %} + {% endfor %} +

Patient{% if object.policyholder.id == object.id %}(Assuré){% endif %}

{% include "dossiers/patientrecord_tab3_contact.html" with contact=object %}

{% if contact.gender == 1 %}M.{% elif contact.gender == 2 %}Mme{% endif %} + {{ contact.first_name }} {{ contact.last_name }}{% if object.policyholder.id == contact.id %}(Assuré){% endif %} {% if contact.id == object.id %} (PATIENT){% endif %}

+ {% include "dossiers/patientrecord_tab3_contact.html" %} +
+
+ +
+ + {% for address in addresses %} + +{% for contact in address.patientcontact_set.all %} +{% if contact.id != object.id %} + +{% endif %} +{% endfor %} + +
+

{{ address }}{% if address.place_of_life %}(lieu de vie){% endif %}

+ {% if address.phone %}

{{ address.phone|phone }}

{% endif %} +{% if address.comment %}

{{ address.comment }}

{% endif %}
+

{% if contact.gender == 1 %}M.{% elif contact.gender == 2 %}Mme{% endif %}{{ contact.first_name }} {{ contact.last_name }}{% if object.policyholder.id == contact.id %}(Assuré){% endif %}{% if contact.id == object.id %} (PATIENT){% endif %}

+
+
+ {% include "dossiers/patientrecord_tab3_contact.html" %} +
+
+
+{% endfor %} +
+ + + +
+

Prise en charge

+ {% include "dossiers/patientrecord_tab4_notifs.html" %} +
+ + + +
+

Actes passés

+ {% include "dossiers/patientrecord_tab5_actes_passes.html" %} +
+ + + +
+

Prochains rendez-vous

+ {% include "dossiers/patientrecord_tab6_next_rdv.html" %} +
+ + + +
+

Socialisation

+ {% include "dossiers/patientrecord_tab7_socialisation.html" %} +
+ + + +
+

Données à caractère médical

+
    +
  • {{ object.size|default_if_none:'' }}
  • +
  • {{ object.weight|default_if_none:'' }}
  • +
  • {{ object.pregnancy_term|default_if_none:'' }}
  • +
  • {{ object.cranium_perimeter|default_if_none:'' }}
  • +
  • {{ object.chest_perimeter|default_if_none:'' }}
  • +
  • {{ object.apgar_score_one|default_if_none:'' }}
  • +
  • {{ object.apgar_score_two|default_if_none:'' }}
  • +
  • +
      + {% for m in object.mises_1.all %} +
    • {{ m }}
    • + {% endfor %} +
    +
  • + +
  • +
      + {% for m in object.mises_2.all %} +
    • {{ m }}
    • + {% endfor %} +
    +
  • + +
  • +
      + {% for m in object.mises_3.all %} +
    • {{ m }}
    • + {% endfor %} +
    +
  • + {% if object.deficiency_intellectual %} +
  • {{ object.get_deficiency_intellectual_display }}
  • + {% endif %} + {% if object.deficiency_autism_and_other_ted %} +
  • {{ object.get_deficiency_autism_and_other_ted_display }}
  • + {% endif %} + {% if object.deficiency_mental_disorder %} +
  • {{ object.get_deficiency_mental_disorder_display }}
  • + {% endif %} + {% if object.deficiency_learning_disorder %} +
  • {{ object.get_deficiency_learning_disorder_display }}
  • + {% endif %} + {% if object.deficiency_auditory %} +
  • {{ object.get_deficiency_auditory_display }}
  • + {% endif %} + {% if object.deficiency_visual %} +
  • {{ object.get_deficiency_visual_display }}
  • + {% endif %} + {% if object.deficiency_motor %} +
  • {{ object.get_deficiency_motor_display }}
  • + {% endif %} + {% if object.deficiency_metabolic_disorder %} +
  • {{ object.get_deficiency_metabolic_disorder_display }}
  • + {% endif %} + {% if object.deficiency_brain_damage %} +
  • {{ object.get_deficiency_brain_damage_display }}
  • + {% endif %} + {% if object.deficiency_polyhandicap %} +
  • + {% endif %} + {% if object.deficiency_behavioral_disorder %} +
  • {{ object.get_deficiency_brain_damage_display }}
  • + {% endif %} + {% if object.deficiency_in_diagnostic %} +
  • + {% endif %} + {% if object.deficiency_other_disorder %} +
  • {{ object.get_deficiency_other_disorder_display }}
  • + {% endif %} +
+
+ + diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_print_coordinators.html b/calebasse/dossiers/templates/dossiers/patientrecord_print_coordinators.html new file mode 100644 index 0000000..3cdf86f --- /dev/null +++ b/calebasse/dossiers/templates/dossiers/patientrecord_print_coordinators.html @@ -0,0 +1,9 @@ +
  • + {% if object.coordinators.all %} +
      + {% for coordinator in object.coordinators.all %} +
    • {{ coordinator.first_name }} {{ coordinator.last_name }}
    • + {% endfor %} +
    + {% else %}Aucun{% endif %} +
  • diff --git a/calebasse/dossiers/templates/dossiers/patientrecord_update.html b/calebasse/dossiers/templates/dossiers/patientrecord_update.html index 71af27a..fe499a1 100644 --- a/calebasse/dossiers/templates/dossiers/patientrecord_update.html +++ b/calebasse/dossiers/templates/dossiers/patientrecord_update.html @@ -19,6 +19,9 @@

    {% if current_state.status.type == 'CLOS' %}{% endif %}{{ object.last_name }} {{ object.first_name }}{% if object.paper_id %} - Dossier {{ object.paper_id}}{% endif %}{% if current_state.status.type == 'CLOS' %} clos{% endif %}

    Retourner aux dossiers +
    + +
    {% if 'validator' in role %}{% if object.can_be_deleted %}{% endif %}{% endif %} {% endblock %} diff --git a/calebasse/dossiers/urls.py b/calebasse/dossiers/urls.py index 0108c57..cbd251b 100644 --- a/calebasse/dossiers/urls.py +++ b/calebasse/dossiers/urls.py @@ -11,6 +11,7 @@ urlpatterns = patterns('calebasse.dossiers.views', url(r'^waiting-queue$', 'patientrecord_waiting_queue'), url(r'^new$', 'new_patient_record'), url(r'^(?P\d+)/view$', 'patient_record'), + url(r'^(?P\d+)/print$', 'patient_record_print', name='patientrecord_print'), url(r'^(?P\d+)/tab1$', 'tab1_general'), url(r'^(?P\d+)/tab2$', 'tab2_fiche_adm'), url(r'^(?P\d+)/tab3$', 'tab3_addresses'), diff --git a/calebasse/dossiers/views.py b/calebasse/dossiers/views.py index ad43c13..f238996 100644 --- a/calebasse/dossiers/views.py +++ b/calebasse/dossiers/views.py @@ -11,6 +11,7 @@ from django.views.generic import View from django.views.generic.edit import DeleteView from django.contrib import messages from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.core.urlresolvers import reverse from django.core.files import File from django.forms import Form from django.utils import formats @@ -32,6 +33,7 @@ from calebasse.dossiers.states import STATES_MAPPING, STATES_BTN_MAPPER from calebasse.ressources.models import (Service, SocialisationDuration, MDPHRequest, MDPHResponse) from calebasse.facturation.list_acts import list_acts_for_billing_CMPP_per_patient +from calebasse.facturation.invoice_header import render_to_pdf_file from calebasse.decorators import validator_only @@ -262,6 +264,35 @@ class PatientRecordView(cbv.UpdateView): patient_record = PatientRecordView.as_view() +class PatientRecordPrint(cbv.DetailView): + model = PatientRecord + # content_type = 'application/pdf' + template_name = 'dossiers/patientrecord_print.html' + + def get_context_data(self, *args, **kwargs): + context = super(PatientRecordPrint, self).get_context_data(*args, **kwargs) + for view in (PatientRecordGeneralView, PatientRecordAdmView, + PatientRecordAddrView, PatientRecordNotifsView, PatientRecordOldActs, + PatientRecordNextAppointmentsView, PatientRecordSocialisationView): + view_instance = view(request=self.request, object=self.object, + service=self.service) + context.update(view_instance.get_context_data(object=self.object)) + return context + + def get(self, request, *args, **kwargs): + self.object = self.get_object() + path = render_to_pdf_file([self.template_name], + self.get_context_data(object = self.object)) + content = File(file(path)) + response = HttpResponse(content, self.content_type) + response['Content-Length'] = content.size + output = 'dossier_%s.pdf' % self.object.id + response['Content-Disposition'] = \ + 'attachment; filename="%s"' % output + return response + +patient_record_print = PatientRecordPrint.as_view() + class PatientRecordGeneralView(cbv.UpdateView): model = PatientRecord form_class = forms.GeneralForm @@ -338,7 +369,7 @@ class PatientRecordNotifsView(cbv.DetailView): ctx['status'], ctx['hc_status'] = get_status(ctx, self.request.user) if ctx['object'].service.slug == "cmpp": (acts_not_locked, days_not_locked, acts_not_valide, - acts_not_billable, acts_pause, acts_per_hc, acts_losts) = \ + acts_not_biPllable, acts_pause, acts_per_hc, acts_losts) = \ list_acts_for_billing_CMPP_per_patient(self.object, datetime.today(), self.service) ctx['acts_losts'] = acts_losts diff --git a/calebasse/static/js/calebasse.dialog.js b/calebasse/static/js/calebasse.dialog.js index 265bdbd..149e98e 100644 --- a/calebasse/static/js/calebasse.dialog.js +++ b/calebasse/static/js/calebasse.dialog.js @@ -85,10 +85,11 @@ function generic_ajaxform_dialog(url, title, id, width, btn_submit_name, redirec * id: jQuery id where you want to replace form by ajaxForm */ function calebasse_ajax_form(id) { + var selector = id + ' form'; function onsuccess(response, status, xhr, form) { if ($('.errorlist', response).length != 0) { $(id).parent().html(response); - $('form').ajaxForm({ + $(selector).ajaxForm({ success: onsuccess, }); } @@ -96,7 +97,7 @@ function calebasse_ajax_form(id) { window.location.reload(true); } } - $('form').ajaxForm({ + $(selector).ajaxForm({ success: onsuccess, }); } -- 2.1.0