o
    qg2                     @   sZ   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZG dd dZ	dS )    Nc                   @   s2   e Zd Zdd Zdg ddddfddZdd ZdS )	ReportWriterc                 C   s2   d| _ d| _g d| _d| _d| _d| _d| _d S )Nz$/home/ubuntu/flask/files/report.docx&/home/ubuntu/flask/files/template.docx)z&/home/ubuntu/flask/files/bascprs1.docxz&/home/ubuntu/flask/files/bascprs2.docxz%/home/ubuntu/flask/files/basctrs.docxz%/home/ubuntu/flask/files/bascsrp.docxz"/home/ubuntu/flask/files/wisc.docxz&/home/ubuntu/flask/files/woodcock.docxz"/home/ubuntu/flask/files/wais.docxz"/home/ubuntu/flask/files/brown.pdf)
reportFiletemplateFilebascFilewiscFilewoodcockFilewaisFile	brownFile)self r   /home/ubuntu/flask/main.py__init__   s   

zReportWriter.__init__ c
                    s  dd l  |s	| j}|s| j}|s| j}|s| j}|s| j}|	s"| j}	t fdd|D s9 j	|s9 j	|r<d}nd}t
dt fdd|D  t
d j	| t
d	 j	| t
d
|  t
d|  t
d t
| j t
d t||  j	| jrzt|}
W n   d }
t
d Y nd }
t
d t||||
 t
d |D ];} j	|rd|v rd}nd|v rd}nd|v rd}nd|v rd}nt
d  d S t|g d}t|||| qt
d  j	|r
t|}t
| t||| t||| nt
d t
d  j	|r,t|}t||| t||| t
d  j	|rLt|}t||| t||| d S d S )Nr   c                 3       | ]	} j |V  qd S Npathexists.0fileosr   r   	<genexpr>+       z%ReportWriter.start.<locals>.<genexpr>r   z"/home/ubuntu/flask/files/ADHD.docxzBASC Exists: c                 3   r   r   r   r   r   r   r   r   /   r   zWISC Exists: zWoodcock Exists: zReport file is: zTemplate file is: zBasc file is: zCopying template file...zError with Brownz#Inserting patient name and pronounszAttempting BASCprs1prs2trssrpzInvalid filename)      	   zAttempting WISCz!failed to find the wisc my bruthazAttempting WAISzAttempting Woodcock)r   r   r   r   r   r	   r
   anyr   r   printshutilcopybrownBrowndemographicsreplace_placeholdersbascIndividualextract_t_scoresupdate_templatewiscextract_table_from_docxinsert_table_into_wordupdate_documentwaiswoodcockextract_table_data)r   r   	firstNamepronounsr   r   r   r   r	   r
   	brownTextfilenametypet_scorestable_contentdatar   r   r   start   s   .



zReportWriter.startc                 C   s   t j|d}t|D ]5}t j||vrAzt | td|  W q ty@ } ztd| d|  W Y d }~qd }~ww qd S )Nz*.docxz	Deleted: zFailed to delete z: )r   r   joinglobbasenameremover$   	Exception)r   	directoryexclude_filefile_pattern	file_pather   r   r   delete_docx_filest   s   
 zReportWriter.delete_docx_filesN)__name__
__module____qualname__r   r=   rH   r   r   r   r   r      s    Wr   )
r%   r+   r.   r3   r2   r   r?   r)   r'   r   r   r   r   r   <module>   s    