Revision b4310641
Added by Mikaël Ates almost 12 years ago
calebasse/dossiers/views.py | ||
---|---|---|
734 | 734 |
ctx['appointment'] = appointment |
735 | 735 |
return ctx |
736 | 736 |
|
737 |
def form_valid(self, form): |
|
738 |
patient = PatientRecord.objects.get(id=self.kwargs['patientrecord_id']) |
|
737 |
def form_valid(self, form, **kwargs): |
|
738 |
ctx = self.get_context_data(**kwargs) |
|
739 |
patient = ctx['object'] |
|
740 |
appointment = ctx['appointment'] |
|
739 | 741 |
template_filename = form.cleaned_data.get('template_filename') |
740 | 742 |
dest_filename = datetime.now().strftime('%Y-%m-%d--%H:%M:%S') + '--' + template_filename |
741 | 743 |
from_path = os.path.join(settings.RTF_TEMPLATES_DIRECTORY, template_filename) |
... | ... | |
753 | 755 |
# else : use temporary files |
754 | 756 |
persistent = False |
755 | 757 |
to_path = dest_filename |
756 |
vars = {'AD11': '', 'AD12': '', 'AD13': '', 'AD14': '', 'AD15': '', |
|
757 |
'JOU1': datetime.today().strftime('%d/%m/%Y'), |
|
758 |
'VIL1': u'Saint-Étienne', |
|
759 |
'PRE1': form.cleaned_data.get('first_name'), |
|
760 |
'NOM1': form.cleaned_data.get('last_name'), |
|
761 |
'DPA1': form.cleaned_data.get('appointment_intervenants') |
|
762 |
} |
|
758 |
variables = {'AD11': '', 'AD12': '', 'AD13': '', 'AD14': '', |
|
759 |
'AD15': '', 'AD18': '', |
|
760 |
'JOU1': datetime.today().strftime('%d/%m/%Y'), |
|
761 |
'VIL1': u'Saint-Étienne', |
|
762 |
'RDV1': '', 'HEU1': '', 'THE1': '', 'DPA1': '', |
|
763 |
'NOM1': '', 'PRE1': '', 'NAI1': '', 'NUM2': '', |
|
764 |
'NOM2': '', 'PRE2': '', 'TPA1': '', 'NSS1': '', |
|
765 |
'TR01': '', 'TR02': '', 'TR03': '', 'TR04': '', 'TR05': '', |
|
766 |
'AD16': '', 'AD17': '', 'AD19': '', |
|
767 |
'AD21': '', 'AD22': '', 'AD23': '', 'AD24': '', 'AD25': '', |
|
768 |
'AD26': '', 'AD27': '', 'AD28': '', 'AD29': '', |
|
769 |
} |
|
770 |
if appointment: |
|
771 |
variables['RDV1'] = appointment.date |
|
772 |
variables['HEU1'] = appointment.begin_hour |
|
773 |
variables['THE1'] = ' '.join([str(i) for i in appointment.workers])# ou DPA1? |
|
774 |
variables['DPA1'] = variables['THE1'] |
|
775 |
if patient: |
|
776 |
variables['NOM1'] = patient.last_name |
|
777 |
variables['PRE1'] = patient.first_name |
|
778 |
if patient.birthdate : |
|
779 |
variables['NAI1'] = patient.birthdate.strftime('%d/%m/%Y') |
|
780 |
variables['NUM2'] = patient.paper_id |
|
781 |
if patient.policyholder: |
|
782 |
variables['NOM2'] = patient.policyholder.last_name |
|
783 |
variables['PRE2'] = patient.policyholder.first_name |
|
784 |
variables['TPA1'] = patient.policyholder.health_center.name |
|
785 |
if patient.policyholder.social_security_id: |
|
786 |
key = str(patient.policyholder.get_control_key()) |
|
787 |
if len(key) == 1: |
|
788 |
key = '0' + key |
|
789 |
variables['NSS1'] = \ |
|
790 |
' '.join([patient.policyholder.social_security_id, |
|
791 |
key]) |
|
792 |
if patient.transportcompany: |
|
793 |
variables['TR01'] = patient.transportcompany.name |
|
794 |
variables['TR02'] = patient.transportcompany.address |
|
795 |
variables['TR03'] = patient.transportcompany.address_complement |
|
796 |
variables['TR04'] = patient.transportcompany.zip_code |
|
797 |
variables['TR05'] = patient.transportcompany.city |
|
798 |
variables['AD18'] = form.cleaned_data.get('phone_address') or '' |
|
763 | 799 |
for i, line in enumerate(form.cleaned_data.get('address').splitlines()): |
764 |
vars['AD%d' % (11+i)] = line |
|
800 |
variables['AD%d' % (11+i)] = line
|
|
765 | 801 |
if i == 4: |
766 | 802 |
break |
767 |
filename = make_doc_from_template(from_path, to_path, vars, persistent) |
|
803 |
|
|
804 |
filename = make_doc_from_template(from_path, to_path, variables, |
|
805 |
persistent) |
|
768 | 806 |
|
769 | 807 |
client_dir = patient.get_client_side_directory(self.service.name) |
770 | 808 |
if not client_dir: |
Also available in: Unified diff
Complete variables for template-based document generation.