
    />{j/                    2   S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  \R                  " \5      rSrSrS=S jr\" S	 \ 5       5      r\" S
S15      r\" S V s1 s H  n \" U 5      iM     sn 5      r\" S V s1 s H  n \" U 5      iM     sn 5      r\" S V s1 s H  n \" U 5      iM     sn 5      r\" S V s1 s H  n \" U 5      iM     sn 5      r\" S V s1 s H  n \" U 5      iM     sn 5      r\" S V s1 s H  n \" U 5      iM     sn 5      rSrSrS>S jrS?S jrS@S jrSAS jrSBS jrSCS jr SCS jr!SBS jr"Sr#SDS jr$SES jr%SCS jr&SCS  jr'            SFS! jr(SGS" jr)SHS# jr*SIS$ jr+SHS% jr,SES& jr-S'r.S(\. S)3r/SJS* jr0SKS+ jr1SLS, jr2SMS- jr3S?S. jr4 SN     SOS/ jjr5SPS0 jr6SES1 jr7 SN     SQS2 jjr8S3r9S4r:SRS5 jr;SES6 jr<SES7 jr=SSS8 jr>SSS9 jr?      STS: jr@SS;.         SUS< jjrAgs  sn f s  sn f s  sn f s  sn f s  sn f s  sn f )VuU   Relleno determinístico de campos de identificación en informe familia (formulario).    )annotationsN)Path)Any)student_full_namestudent_identification_numberstudent_birth_datestudent_agestudent_coursestudent_schoolprofessional_full_name"professional_identification_numberprofessional_job_positionprofessional_phone_email"professional_delivered_date_informperson_full_nameperson_identification_numberperson_relation_studentperson_presence)evaluation_reasonapplied_instruments	diagnosis
diagnosticpedagogical_strengthspedagogical_support_needssocial_affective_strengthssocial_affective_support_needshealth_strengthshealth_support_needscollaborative_workhome_based_descriptionhome_supportschool_family_agreementsagreements_commitments
agreementspedagogical_field_1pedagogical_field_2social_field_1social_field_2r   supportsstrengths_1support_needs_1strengths_2support_needs_2strengths_3support_needs_3c                ,   U =(       d    SR                  5       R                  5       n[        R                  " SU5      nSR	                  S U 5       5      n[
        R                  " SSU5      n[
        R                  " SSU5      R                  S5      $ )N NFKDc              3  ^   #    U  H#  n[         R                  " U5      S :w  d  M  Uv   M%     g7f)MnN)unicodedatacategory.0cs     ZC:\Users\jesus\Desktop\proyecto_pie360\backend\app\backend\utils\familia_report_prefill.py	<genexpr>$_normalize_cc_tag.<locals>.<genexpr>C   s$     @1a 4 4Q 74 ?1s   -	-z
[^a-z0-9]+_z_+)striplowerr5   	normalizejoinresub)tagts     r:   _normalize_cc_tagrF   @   ss    	!!#Afa(A
@1@@A
}c1%A66%a &&s++    c              #  8   #    U  H  n[        U5      v   M     g 7fN)rF   )r8   ks     r:   r;   r;   H   s      O!!21!5!5s   
evaluationreevaluation)rK   ingreso	admissionevaluacion_ingreso)rL   reevaluacion   reevaluaciónrevaluationevaluacion_reevaluacion)primarytitularguardian_primaryapoderado_titularapoderado_a_titular)
substitutesuplenteguardian_substituteapoderado_suplenteapoderado_a_suplente)yessi   sí	power_yespoder_sihas_power_yeshas_power_of_attorney_yes)nopower_nopoder_nohas_power_nohas_power_of_attorney_no   ☐   ☒c                     [         [        -  [        -  [        -  [        -  [
        -  [         V s1 s H  n [        U 5      iM     sn -  $ s  sn f rI   )_EVALUATION_CHECK_TAGS_REEVALUATION_CHECK_TAGS_GUARDIAN_PRIMARY_TAGS_GUARDIAN_SUBSTITUTE_TAGS_POWER_YES_TAGS_POWER_NO_TAGS_CHECKBOX_SDT_TAGSrF   rE   s    r:   all_familia_checkbox_tag_normsru   r   s^    
"	#
 	! $	$ 		
 	 *<
<);AQ);
<	= =s   Ac                    U (       d  g[        U 5      nU[        5       ;   a  gUnSU;   =(       d    SU;   =(       d    SU;   $ )NFT	apoderadoguardianpoder)rF   ru   )rD   tag_nlows      r:   is_familia_checkbox_tag_normr|   ~   sD    c"E.00
C#Ds!2DgnDrG   c                    U R                  U" S5      5       H(  nUR                  =(       d    SnSU;   a    gSU;   d  M(    g   [        $ )u?   Símbolo vacío del checkbox: conserva ☐/□ de la plantilla.w:tr1   rj      □)itertextFAMILIA_CHECKBOX_UNCHECKED)sdtqnwtr   s       r:   _sdt_checkbox_unchecked_displayr      sB    hhr%y!ww}"D=D= " &%rG   c                \    SR                  S U R                  U" S5      5       5       5      $ )Nr1   c              3  J   #    U  H  oR                   =(       d    S v   M     g7fr1   Nr   r8   rE   s     r:   r;   *_paragraph_visible_text.<locals>.<genexpr>   s     @+?aFFLbL+?   !#r~   )rA   r   )p_elr   s     r:   _paragraph_visible_textr      s$    77@499RY+?@@@rG   c                   U =(       d    SR                  5       n[        U5      S:  a  gU Vs/ s H  o"R                  5       (       d  M  UPM     nn[        U5      S:  a  g[        S U 5       5      nU[        U5      -  S:  $ s  snf )Nr1   
   F   c              3  R   #    U  H  oR                  5       (       d  M  S v   M     g7f)   N)isupperr7   s     r:   r;   &_is_label_paragraph.<locals>.<genexpr>   s     27aiik7s   '	'g=
ףp=?)r>   lenisalphasum)r   sr9   lettersuppers        r:   _is_label_paragraphr      st    	A
1v{+!Qyy{q!G+
7|a2722ECL D((	 ,s   B
Bc                    S H;  n[        U R                  U" U5      5      5       H  nU R                  U5        M     M=     [        U R                  U" S5      5      5       H  nU R                  U5        M     g)uG   Evita saltos forzados y bloques que Word empuja a la página siguiente.)z
w:keepNextzw:keepLineszw:pageBreakBeforezw:widowControlN)listfindallremove)pprr   OxmlElementrD   els        r:   !_clear_paragraph_pagination_locksr      s_    As{{2c7+,BJJrN - B 3;;r"2345

2 6rG   c                   [        U R                  U" S5      5      5       H  nU R                  U5        M     U" S5      nUR                  U" S5      S5        UR                  U" S5      S5        UR                  U" S5      S5        UR                  U" S5      S5        U R	                  U5        [        U R                  U" S	5      5      5       H  nU R                  U5        M     [        XU5        g )
Nz	w:spacingzw:before0zw:afterzw:line240z
w:lineRuleautozw:contextualSpacing)r   r   r   setappendr   )r   r   r   spspacingctxs         r:   _zero_paragraph_spacingr      s    3;;r+/0

2 1+&GKK:$KK9s#KK8e$KK< &)JJwCKK#8 9:;

3 <%c{;rG   c                `   ^ U =(       d    SR                  5       m[        U4S jS 5       5      $ )Nr1   c              3  .   >#    U  H
  nUT;   v   M     g 7frI    )r8   phr{   s     r:   r;   -_paragraph_has_placeholder.<locals>.<genexpr>   s       
B 	c	
s   )zhaz clicz	pulse aquzescribir textoz
click hereztap herezclick or tapzclic aqu)r?   any)r   r{   s    @r:   _paragraph_has_placeholderr      s1    :2


C 
  rG   )u+   Haz clic o pulse aquí para escribir texto.u*   Haz clic o pulse aquí para escribir textoz Click or tap here to enter text.zClick or tap here to enter textc                .   U R                   =(       d    SnUR                  5       (       d  g[        U5      (       a  SU l         gUn[         H  nX2;   d  M
  UR	                  US5      nM     UR                  5       nX!R                  5       :w  a  X l         gg)u>   Vacía nodos w:t que solo contienen el texto de ayuda de Word.r1   FT)r   r>   r   _WORD_PLACEHOLDER_LITERALSreplace)r   r   cleanedlits       r:   _sweep_placeholder_wtr      sz    77=bD::<<!$''G)>ooc2.G * mmoG**,rG   c                f   SSK Jn  SSKJn  U" [	        U 5      5      nUR
                  R                  /nUR                   Hk  nUR                  UR                  UR                  UR                  4 H6  nUc  M  [        US5      (       d  M  UR                  UR                  5        M8     Mm     SnU H8  nUR                  U" S5      5       H  n	[!        U	5      (       d  M  US-  nM     M:     U(       a;  UR#                  [	        U 5      5        [$        R'                  SXpR(                  5        gg)	uO   Quita «Haz clic o pulse aquí…» dejando la celda vacía cuando no hay dato.r   Documentr   N_elementr~   r   z,clear_word_form_placeholders: %d nodos en %s)docxr   docx.oxml.nsr   strelementbodysectionsheaderfooterfirst_page_headerfirst_page_footerhasattrr   r   r   r   saveloggerdebugname)
	docx_pathr   r   docrootssectionhfchangedrootr   s
             r:   clear_word_form_placeholdersr      s    
3y>
"C(()E<<>>7>>73L3LgNgNghB~'"j"9"9R[[) i  
 G))BuI&B$R((1 ' 
 Y CWnn] rG   c                    [        U R                  U" S5      5      5       H  nU R                  U5        M     U" S5      nUR                  U" S5      S5        U R	                  U5        g)uV   Justificado estándar (w:jc both). La última línea de cada w:p queda a la izquierda.zw:jcw:valbothN)r   r   r   r   r   )r   r   r   jcjc_els        r:   _ppr_set_justifyr      sQ    3;;r&z*+

2 ,E	IIbk6"JJurG   c                4    [        XU5        [        XU5        g rI   )r   r   )r   r   r   s      r:   !_apply_narrative_paragraph_formatr     s    Sk*C[1rG   c                   SSK Jn  U" S5      nU" S5      n[        XrU5        UR                  U5        U" S5      nUb  UR                  U" U5      5        U" S5      n	Xl        UR                  S5      (       d  UR                  S5      (       a  U	R                  U" S5      S	5        UR                  U	5        UR                  U5        U R                  U5        g )
Nr   deepcopyw:pw:pPrw:rr~    z	xml:spacepreserve)copyr   r   r   r   
startswithendswithr   )
parentr   r   r   ref_r_prr   new_pr   rr   s
             r:   _append_narrative_paragraphr   	  s     E
g
C%c{;	LLEA	(#$	U	BGst}}S11
r+
+HHRL	LLO
MM%rG   c                   / n/ nU R                  U" S5      5       H  nUR                  U" S5      5      nUb,  UR                  (       a  UR                  UR                  5        UR                  U" S5      5      c  Mc  SR	                  U5      R                  5       nU(       a  UR                  U5        / nM     SR	                  U5      R                  5       nU(       a  UR                  U5        U$ )z4Parte un w:p en bloques de texto separados por w:br.r   r~   w:brr1   )r   findr   r   rA   r>   )r   r   segmentsbufr   r   chunktails           r:   _split_paragraph_segmentsr   "  s    HC\\"U)$VVBuI>bggJJrww66"V*)GGCL&&(E&C % 773<DOrG   c                j    U R                  U" S5      5      nUb  [        X1U5        g[        XU5        g)u   
Normaliza narrativa: un w:p por bloque, justificado, sin w:br.
w:br + justify en el mismo párrafo estira líneas cortas con espacios enormes.
zw:tcN)r   '_reformat_narrative_paragraph_container)sdt_content_elr   r   	direct_tcs       r:   _reformat_narrative_sdt_contentr   5  s5     ##BvJ/I/	{K+NLrG   c           	        ^ SSK Jn  / nS nU R                  T" S5      5       GH  n[        UT5      R	                  SS5      R	                  SS5      nUR                  5       nU(       a   [        U5      (       d  [        U5      (       a  Mi  UcB  UR                  T" S5      5       H'  nUR                  T" S5      5      n	U	c  M  U" U	5      n  O   [        U4S	 jUR                  T" S5      5       5       5      (       a  UR                  [        UT5      5        M  UR                  S5       V
s/ s H)  oR                  5       (       d  M  U
R                  5       PM+     nn
[        U5      S
:  a  UR                  U5        GMb  [        R                  " SU5       H-  nUR                  5       nU(       d  M  UR!                  U5        M/     GM     U R                  T" S5      5       HD  nUR                  T" S5      5      nUc  U" S5      nUR#                  SU5        [%        UTU5        MF     U(       d  g ['        U 5       H,  nUR(                  T" S5      :X  a  M  U R+                  U5        M.     U H  n[-        XTX%5        M     g s  sn
f )Nr   r   r   z

r   w:rPrc              3  T   >#    U  H  oR                  T" S 5      5      SLv   M     g7fr   Nr   r8   r   r   s     r:   r;   :_reformat_narrative_paragraph_container.<locals>.<genexpr>T  s#     L7K!vvbj!-7K   %(r   z\n\s*\nr   zw:tcPr)r   r   r   r   r   r>   r   r   r   r   r   extendr   splitr   rB   r   insertr   r   rD   r   r   )container_elr   r   r   r   r   prawr   rprlnlinesblockr   childsegs    `              r:   r   r   C  s	   HHr%y)%a,44VTBJJ4QUViik0559LS9Q9QVVBuI&ffR[)?'}H	 '
 LqyyE7KLLLOO5a<=*-))D/H/BXXZZRXXZ/EH5zA~&XXj#6E!KKMEu . 7% *. r%y)ffR[!;g&CHHQ)#r;? * l#998$E" $
 #Lr;Q 1 Is   0JJc                    [        XU5        g)uK   Reformatea párrafos narrativos: justificado, un w:p por bloque (sin w:br).N)r   )r   r   r   s      r:   _compact_sdt_content_spacingr  s  s    #NDrG   c                H  ^^^ SSK JnJn  SSKJnJnJn  U" U 5      (       a  U" U 5        U" U 5        gU" U 5      (       a	  U" U 5        gSSKJn  SSK	J
m  SSKJm  U" [        U 5      5      nS
U4S jjmSUUU4S	 jjnU" UR                  R                  5        UR                    H^  n	U	R"                  U	R$                  U	R&                  U	R(                  4 H)  n
U
c  M  U
R*                  c  M  U" U
R*                  5        M+     M`     UR-                  [        U 5      5        g)zUJustifica narrativa, separa bloques en w:p distintos (sin w:br) y compacta espaciado.r   )"compact_familia_formtext_narrativedocx_has_legacy_formtext)compact_familia_tabla_narrative!docx_is_familia_ministerial_tablarelax_familia_tabla_layoutNr   r   r   c           	        > U R                  T" S5      5       H4  n[        U4S jUR                  T" S5      5       5       5      (       d  M4    g   g)Nr   c              3  T   >#    U  H  oR                  T" S 5      5      SLv   M     g7fr  r  r  s     r:   r;   Zcompact_familia_narrative_spacing.<locals>._sdt_content_has_soft_breaks.<locals>.<genexpr>  s#     P;Oa66"V*%T1;Or  r   TF)r   r   r   )r   r  r   s     r:   _sdt_content_has_soft_breaksGcompact_familia_narrative_spacing.<locals>._sdt_content_has_soft_breaks  sB    $$RY/AP199RY;OPPP 0 rG   c                ~  > U R                  T" S5      5       H  nUR                  ST" S5      -   5      nUc  M"  UR                  T" S5      5      =(       d    Sn[        U5      (       a  MT  [	        U5      nUR                  T" S5      5      nUc  M{  U[
        ;  a  T" U5      (       d  M  [        UTT5        M     g )Nw:sdt.//w:tagr   r1   w:sdtContent)r   r   getr|   rF   _NARRATIVE_TAG_NORMSr  )	r   r   tag_eltag_valrz   sdt_contentr   r   r   s	         r:   	walk_sdts4compact_familia_narrative_spacing.<locals>.walk_sdts  s    ;;r'{+CXXebk12F~jjG-3G+G44%g.E((2n#56K"009UVa9b9b(b+F ,rG   )r   r   returnboolr   r   r.  None))app.backend.utils.familia_report_formtextr  r  +app.backend.utils.familia_report_tabla_fillr  r  r  r   r   	docx.oxmlr   r   r   r   r   r   r   r   r   r   r   r   r   )r   r  r  r  r  r  r   r   r,  r   r   r   r   r   s              @@@r:   !compact_familia_narrative_spacingr5  x  s      )33'	2"9-	***95%
3y>
"CG G  ckk<<NNNN%%%%	
B ~"++"9"++&
   HHS^rG   z4http://schemas.microsoft.com/office/word/2010/wordml{z}valc                   U =(       d    0 n[        UR                  S5      =(       d    S5      R                  5       R                  5       nU(       de  [	        [        UR                  S5      =(       d    S5      5      (       a  g[	        [        UR                  S5      =(       d    S5      5      (       a  ggUS;   a  gUS	;   a  gg)
uO   Devuelve (ingreso_marcado, reevaluacion_marcada). Sin dato → ninguno marcado.evaluation_typer1   rL   )FTrK   )TF)FF)rR   rQ   rP   reeval2)rN   	   admisiónadmisionrM   1)r   r'  r>   r?   _truthy_checkbox_value)contextr   	eval_types      r:   _evaluation_type_flagsrA    s    
-RCCGG-.4"5;;=CCEI!#cggn&=&C"DEE!#cggl&;&Ar"BCCSSJJrG   c                Z    U =(       d    SR                  5       R                  5       nUS;   $ )Nr1   )	r=  truer^   r_   r`   onxrk      ☑)r>   r?   )r  vs     r:   r>  r>    s)    	!!#AJJJrG   c                x   U (       d  g[        U 5      nU=(       d    0 n[        U5      u  pEU[        ;   a  U$ U[        ;   a  U$ [	        UR                  S5      =(       d    S5      R                  5       R                  5       nU[        ;   a  US;   $ U[        ;   a  US;   $ [	        UR                  S5      =(       d    S5      R                  5       R                  5       nU[        ;   a  US;   $ U[        ;   a  US;   $ X4 H6  nX;   d  M
  [        [	        UR                  U5      =(       d    S5      5      s  $    g)	uA   True solo si hay dato explícito que corresponda a este checkbox.Fguardian_typer1   )rT   rU   r=  )rY   rZ   r:  has_power_of_attorney)r^   r_   r`   r=  rC  )re   r   false)rF   rA  rm   rn   r   r'  r>   r?   ro   rp   rq   rr   r>  )	rD   r?  rz   r   is_admission	is_reevalrI  poakeys	            r:   _familia_checkbox_should_checkrP    s    c"E
-RC4S9L&&((06B7==?EEGM&& ;;;)) ???
cgg-.4"
5
;
;
=
C
C
EC777***|:)#cggcl.@b*ABB  rG   c                b    U c  gU  H%  nUR                   R                  S5      (       d  M%    g   g)NF	}checkboxT)rD   r   )sdt_prr  s     r:   _sdt_has_checkboxrT    s1    ~99k**  rG   c                    U (       d  g[        U 5      nU[        [        -  [        -  [        -  [
        -  [        -  [        -  ;   $ )NF)rF   rm   rn   ro   rp   rq   rr   rs   )rD   rz   s     r:   _is_familia_checkbox_tagrV    sZ    c"E
"	#
 	! $	$ 		
 	 	 rG   c                  ^^^	 SSK Jn  SSKJm  SSKJm	  U" [        U 5      5      nU=(       d    0 mSUUU	4S jjnU" UR                  R                  5        UR                   H^  nUR                  UR                  UR                  UR                  4 H)  nUc  M  UR                  c  M  U" UR                  5        M+     M`     UR                  [        U 5      5        g)zHDeja en blanco los checkboxes sin dato; marca solo los que correspondan.r   r   r  r   c                8  > U R                  T" S5      5       H~  nUR                  T" S5      5      nUb  UR                  T" S5      5      OS nUb  UR                  T" S5      5      OS n[        U5      (       d  Md  [	        UT5      n[        UTTU5        M     g )Nr#  w:sdtPrr%  r   )r   r   r'  rV  rP  _set_sdt_checkbox_mark)	r   r   rS  r)  r*  checkedr   r   r   s	         r:   walk+apply_familia_checkbox_states.<locals>.walk  s    ;;r'{+CXXbm,F171CV[[G-F171CfjjG-G+G444WcBG"3KA ,rG   Nr0  r   r   r4  r   r   r   r   r   r   r   r   r   r   r   r   r   )
r   r?  r   r   r\  r   r   r   r   r   s
          @@@r:   apply_familia_checkbox_statesr_    s    
 %
3y>
"C
-RCB B 			<<NNNN%%%%	
B ~"++"9R[[!
   HHS^rG   c                   U R                  U" S5      5      nSnUb-  U H'  nUR                  R                  S5      (       d  M%  Un  O   Ub  SnU H'  nUR                  R                  S5      (       d  M%  Un  O   U(       a  SOSnUb  UR                  [        U5        O/U" S5      nUR                  [        U5        UR                  U5        U R                  U" S5      5      n	U	c  gU(       a  [        O
[        X5      n
[        U	R                  U" S	5      5      5      nU(       a  XS
   l
        USS  H
  nSUl
        M     gU	R                  U" S5      5       Ho  nUR                  U" S5      5      nUc  U" S5      nUR                  U5        UR                  U" S	5      5      nUc  U" S	5      nUR                  U5        Xl
          g   g)u   
Marca checkbox en el SDT (no en etiquetas de celda).
Siempre ☐ vacío / ☒ marcado en w:t; si hay w14 también actualiza el atributo.
rY  NrR  z}checkedr=  r   zw14:checkedr&  r~   r   r   r1   r   r   )r   rD   r   r   W14_CHECKED_ATTRr   FAMILIA_CHECKBOX_CHECKED_MARKr   r   r   r   )r   r   r   r[  rS  w14_checkboxr  check_elval_strr+  markwt_listr   r   w_rs                  r:   rZ  rZ  +  s   
 XXbm$FLEyy!!+..$ 
 !Eyy!!*--  " !#cLL)73"=1HLL)73)((2n-.K,3(9XY\9aD;##BuI./G
!"+BBG   $$RY/D))BuI&C{!%(C "U)$Bz '

2G 0rG   c                   ^^^ SSK Jn  SSKJm  SSKJm  U" [        U 5      5      nSmS	UUU4S jjnUR                  R                  R                  T" S5      5       H  nU" U5        M     T(       a  UR                  [        U 5      5        gg)
uW   Restaura ☐ en SDT de checkbox vacíos; convierte x suelta → ☒. No toca etiquetas.r   r   r  r   Fc                  > U R                  T" S5      5      nUb  UR                  T" S5      5      OS nUb  UR                  T" S5      5      OS n[        U5      (       d  g U R                  T" S5      5      nUc  g SR                  S UR	                  T" S5      5       5       5      R                  5       nUS;   a8  [        UR	                  T" S5      5      5      nU(       a  [        US	   l        S
mg U[        S4;   a  g U[        S4;   a  g [        UR	                  T" S5      5      5      nU(       a$  [        US	   l        USS   H
  nSUl        M     S
mg UR	                  T" S5      5       Hv  nUR                  T" S5      5      n	U	c  T
" S5      n	UR                  U	5        U	R                  T" S5      5      nUc  T
" S5      nU	R                  U5        [        Ul        S
m  g    g )NrY  r%  r   r&  r1   c              3  J   #    U  H  oR                   =(       d    S v   M     g7fr   r   r   s     r:   r;   Mensure_familia_checkbox_boxes_visible.<locals>._ensure_sdt.<locals>.<genexpr>p  s     N2MQ66<R<2Mr   r~   )rE  Xr   TrF  r   r   r   r   )r   r'  r|   rA   r   r>   r   rb  r   r   r   )r   rS  r)  r*  r+  visiblerg  r   r   rh  r   r   r   s             r:   _ensure_sdt:ensure_familia_checkbox_boxes_visible.<locals>._ensure_sdtf  s   "Y-(-3-?R[)T-3-?&**R[)T+G44hhr.12''N+2B2B2e92MNNTTVj ;++BuI67G"?
4e<<1599{''5	238GAJOabk "G$$RY/D))BuI&C{!%(C "U)$Bz '

20BGG 0rG   r#  N)r   r   r.  r1  )r   r   r4  r   r   r   r   r   r   r   r   )r   r   r   ro  r   r   r   r   s        @@@r:   %ensure_familia_checkbox_boxes_visiblerq  ]  sq    %
3y>
"CG' 'R {{$$R[1C 2 Y  rG   c                |    SSK JnJn  SSKJnJn  U" U 5      (       a	  U" X5        gU" U 5      (       a	  U" X5        gg)u   
Restaura fila MOTIVO DE LA EVALUACIÓN como plantilla original:
Evaluación: x de Ingreso   x Reevaluación (una x con cuadro).
r   )r  &fix_familia_motivo_evaluacion_formtext)r  #fix_familia_motivo_evaluacion_tablaN)r2  r  rs  r3  r  rt  )r   student_contextr  rs  r  rt  s         r:   !fix_familia_motivo_evaluacion_rowrv    s?    
 )33+IG	**.yJ
 rG   Arial20c                >   U R                  U" S5      5      nUc  U" S5      nU R                  SU5        S H;  n[        UR                  U" U5      5      5       H  nUR	                  U5        M     M=     U" S5      nS H  nUR                  U" U5      [        5        M!     UR                  U5        U" S5      nUR                  U" S5      [        5        UR                  U5        U" S5      n	U	R                  U" S5      [        5        UR                  U	5        g )	Nr  r   )zw:bzw:bCsw:rFontsw:szw:szCsrz  )zw:asciizw:hAnsizw:csr{  r   r|  )	r   r
  r   r   r   r   FAMILIA_ANSWER_FONTr   FAMILIA_ANSWER_SIZE_HALF_PT)
r   r   r   r_prrD   r   r_fontsattrszsz_css
             r:   _apply_arial_10_to_runr    s    66"W+D|7#	D=t||BsG,-BKKO . > *%G.BtH12 /KK	V	BFF2g;34KKO!E	IIbk67KKrG   c                   ^
^ SSK JnJn  SSKJnJn  U" U 5      (       a	  U" U 5        gU" U 5      (       a	  U" U 5        gSSKJn  SSKJ	m
  SSK
Jm  U" [        U 5      5      nS	U
U4S jjnU" UR                  R                  5        UR                   H^  nUR                   UR"                  UR$                  UR&                  4 H)  n	U	c  M  U	R(                  c  M  U" U	R(                  5        M+     M`     UR+                  [        U 5      5        g)
z@Todas las respuestas en content controls: Arial 10, sin negrita.r   )"apply_familia_arial_10_to_formtextr  )apply_familia_arial_10_to_tablar  Nr   r  r   c                  > U R                  T" S5      5       H  nUR                  ST" S5      -   5      nUb  UR                  T" S5      5      OS n[        U5      (       a  MK  UR                  T" S5      5       HT  nUR                  T" S5      5      nUb(  UR                  =(       d    SR                  5       (       d  MG  [        UTT5        MV     M     g )Nr#  r$  r%  r   r   r~   r1   )r   r   r'  r|   r   r>   r  )r   r   r)  r*  r   r   r   r   s         r:   r\  )apply_familia_arial_10_font.<locals>.walk  s    ;;r'{+CXXebk12F171CfjjG-G+G44XXbi(VVBuI&:bggm%:%:%<%<&q"k:	 ) ,rG   r0  )r2  r  r  r3  r  r  r   r   r4  r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r  r  r  r  r   r   r\  r   r   r   r   s             @@r:   apply_familia_arial_10_fontr    s    
 )33'	2	***95%
3y>
"C
; 
; 			<<NNNN%%%%	
B ~"++"9R[[!
   HHS^rG   c                  ^^^ SSK Jn  SSKJm  SSKJm  U" [        U 5      5      nSU4S jjmS	UUU4S jjnU" UR                  R                  5        UR                   H^  nUR                  UR                  UR                  UR                  4 H)  nUc  M  UR                  c  M  U" UR                  5        M+     M`     UR                  [        U 5      5        g)
uS   Justifica (w:jc both) todos los párrafos con respuesta dentro de content controls.r   r   r  r   c                   > [        U T5      R                  5       nU(       d  g[        U5      (       a  g[        U5      (       a  gg)NFT)r   r>   r   r   )r   r   r   s     r:   _paragraph_has_answer_textHapply_familia_justify_sdt_paragraphs.<locals>._paragraph_has_answer_text  s=    &tR0668%d++t$$rG   c                  > U R                  T	" S5      5       H  nUR                  ST	" S5      -   5      nUb  UR                  T	" S5      5      OS n[        U5      (       a  MK  UR                  T	" S5      5      nUc  Mg  UR                  T	" S5      5       HS  nT" U5      (       d  M  UR                  T	" S5      5      nUc  T" S5      nUR	                  SU5        [        UT	T5        MU     M     g )	Nr#  r$  r%  r   r&  r   r   r   )r   r   r'  r|   r
  r   )
r   r   r)  r*  r+  r  r   r   r  r   s
          r:   r\  2apply_familia_justify_sdt_paragraphs.<locals>.walk  s    ;;r'{+CXXebk12F171CfjjG-G+G44((2n#56K" %%bi01!44ffR[);%g.CHHQ$ b+6 1 ,rG   N)r   r   r.  r/  r0  r^  )	r   r   r   r\  r   r   r   r  r   s	         @@@r:   $apply_familia_justify_sdt_paragraphsr    s    %
3y>
"C7 7$ 			<<NNNN%%%%	
B ~"++"9R[[!
   HHS^rG   c                  ^ [        U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       n[        U R                  S	5      =(       d    S5      R                  5       n[        U R                  S
5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       n	[        U R                  S5      =(       d    S5      R                  5       n
[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       nU(       d  U(       a  U SU 3R                  S5      OSn[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    U R                  S5      =(       d    S5      R                  5       n[        U R                  S5      =(       d    U R                  S 5      =(       d    S5      R                  5       nS!mS,U4S" jjn0 SU=(       d    T_SU=(       d    T_SU" U5      _SU=(       d    T_SU=(       d    T_SU=(       d    T_S	U=(       d    T_S
U=(       d    T_SU	=(       d    U=(       d    T_SU" U
5      _SU=(       d    T_S#U=(       d    T_SU=(       d    T_SU=(       d    T_SU=(       d    T_SU=(       d    T_SU=(       d    U=(       d    T_U" U5      U=(       d    TU=(       d    TU=(       d    TU=(       d    TS$.En[        U R                  S%5      =(       d    S5      R                  5       R                  5       nUS&;   a  S'US('   OUS);   a  S'US*'   S+ HB  n[        U R                  U5      =(       d    S5      R                  5       nU(       d  M=  UUU'   MD     U$ )-uT   Rellena solo los content controls de identificación (tags exactos de la plantilla).r   r1   student_social_namer   r   student_born_dater	   r
   r   r   professional_social_namer   r   professional_roleprofessional_phoneprofessional_emailz / r   report_delivery_dater   receiver_full_namereceiver_social_namer   receiver_identification_numberr   receiver_relationshipr   receiver_presence_ofperson_phonereceiver_phoneperson_emailreceiver_emailzNo informadoc                   > SSK Jn  U =(       d    SR                  5       nU(       a"  UR                  5       TR                  5       :X  a  T$ U" U5      $ )Nr   )_format_rut_displayr1   )&app.backend.utils.agent_student_lookupr  r>   r?   )valr  r  no_infos      r:   _fmt_rut;build_familia_identification_replacements.<locals>._fmt_rutg  s>    Nyb!ciikW]]_4N"3''rG   r   )r   r   r   r  r  r8  )rN   r;  rM   r=  r=  rK   )rR   rQ   rP   r:  rL   )evaluation_date_1evaluation_date_2evaluation_date_3)r  r   r.  r   )r   r'  r>   r?   )r?  student_fullstudent_social
student_idstudent_bornr	   r
   r   professional_fullprofessional_socialprofessional_idr  r   emprofessional_contactreport_deliveryreceiver_fullreceiver_socialreceiver_idreceiver_relationreceiver_presencer  r  r  replacementsr@  rO  r  r  s                               @r:   )build_familia_identification_replacementsr  0  s   w{{#67=2>DDFL%:;ArBHHJNW[[!@AGRHNNPJ()SW[[9L-MSQSeg  gkk-06B7==?K%56<"=CCEN%56<"=CCEN,- 	;;12	 eg	 
 gkk*DEKLRRT'++&JKQrRXXZO/0ZGKK@S4TZXZeg  
W[[-.4"	5	;	;	=B	W[[-.4"	5	;	;	=B;=bTRD>//6"89 	;;-.	 eg	  &'R7;;7K+LRPReg  '++&<=CDJJLO23 	;;78	 eg	 
 -.\'++>U2V\Z\eg  %&S'++6L*MSQSeg  N#Jw{{3C'DJeg  N#Jw{{3C'DJeg  G($\4W$~8$ 	(*)=$ 	l5g	$
 	{-g$ 	.3G$ 	.3G$ 	!"3">w$ 	#$7$W;L$WPW$ 	-h.G$ 	$%6%A'$ 	#$8$CG$ 	bmG$ 	bmG$ 	-o.H$  	M4W!$" 	 K= KG#$$ )1(=#4#?,7&1'&1'-$L2 GKK 128b9??AGGII>>%(\"	K	K'*^$N'++c"(b)//13 #L O
 rG   c                ,    [        [        U 5      U 5      $ )uA   Identificación + narrativa desde BD (informe guardado en admin).)_append_narrative_replacementsr  )r?  s    r:   build_familia_form_replacementsr    s    )1':G rG   c           
        [        UR                  S5      =(       d    UR                  S5      =(       d    S5      R                  5       nU(       a  X S'   X S'   [        UR                  S5      =(       d    UR                  S5      =(       d    S5      R                  5       nU(       a  X0S'   SSSS	S
SSSSS.	n[         H^  n[        UR                  U5      =(       d    S5      R                  5       nU(       d  M=  X`U'   UR                  US5       H  nX`U'   M	     M`     U R	                  5        VV	s0 s H  u  pU	(       d  M  X_M     sn	n$ s  sn	nf )Nr   r   r1   r   r   )r*   fortalezas_1)r+   necesidades_apoyo_1)r,   fortalezas_2fortalezas_social_afectivo)r-   necesidades_apoyo_2necesidades_social_afectivo)r.   )r/   )educational_supports_school)r!   )r#   )	r   r   r   r   r   r   r   r    r"   r   )r   r'  r>   _NARRATIVE_KEYSitems)
r  r?  r   r   	alias_maprO  r  aliasrJ   rG  s
             r:   r  r    s8    W[[-P\1JPbQWWYJ%/\"$.[!'(TGKK8M,NTRTeg  ,=() "A%O&c+

 - 4>"3$?I '++c"(b)//1S]]3+E"% ,  *//171TQQDAD1777s   4EE)form_template_pathc               2   U(       a  U(       d  U$ US   nUR                  S5      nU(       d  U$ [        U 5      U-  nUR                  R                  5       S:w  a  U$ UR	                  5       (       d1  U(       a*  UR	                  5       (       a  [
        R                  X65        UR	                  5       (       d  U$ Sn SSKJn  U" U5      n[        U5      (       dc  U(       aZ  UR	                  5       (       aE  [
        R                  X65        [        R                  SUR                  5         SSKJn  U" U5      nOU$ [        U5      (       d	  U(       d  U$  [        U5      n	SSKJn
Jn  U
" U5      (       a:  U" UU	US9nU(       a*  [        R                  S	UR                  [%        U5      5        Os['        XiU5      nUR                  S
5      S:X  a1  [        R)                  SUR                  UR                  S5      5        O![        R                  SUR                  5          [+        U5        [        R                  SUR                  5         [-        Xb5        [        R                  SUR                  5         [/        Xb5        [        R                  SUR                  5         [1        U5        [        R                  SUR                  5        U$ ! [         a     GNf = f! [         a    Sn GNf = f! [         a,  n[        R)                  SUR                  U5         SnAGNSnAff = f! [         a,  n[        R)                  SUR                  U5         SnAGNSnAff = f! [         a,  n[        R)                  SUR                  U5         SnAGN!SnAff = f! [         a,  n[        R)                  SUR                  U5         SnAGN.SnAff = f! [         a,  n[        R)                  SUR                  U5         SnAU$ SnAff = f)uN   Corrige identificación en .docx generado usando fill_docx_form y datos de BD.r   idz.docxF)r  zGInforme familia: reemplazado formato tablas por plantilla formulario %s)r  "refill_familia_identification_only)template_pathu-   Identificación re-aplicada en %s (%d campos)statuserroru"   Prefill familia falló para %s: %smessagezPrefill familia aplicado en %sz%Prefill familia no aplicado en %s: %sNz$Espaciado narrativo compactado en %su+   Compactación de espaciado falló en %s: %sz"Checkboxes familia ajustados en %sz%Checkboxes familia fallaron en %s: %su'   Fila motivo evaluación corregida en %su/   Corrección motivo evaluación falló en %s: %szArial 10 aplicado en %szArial 10 no aplicado en %s: %s)r'  	agent_dirsuffixr?   is_fileshutilcopy2(app.backend.utils.agent_familia_formtextr  	Exceptiondocx_has_form_controlsr   infor   r  r3  r  r  r   fill_familia_docxwarningr5  r_  rv  r  )agent_idsavedru  r  entryfile_idpathuses_formtextr  r  r  r  filledresultexcs                  r:   postprocess_saved_familia_docxr    sW    %!HEiioGX(D{{g%<<>>05G5O5O5Q5Q'.<<>>MU06 "$''"4"<"<">">LL+2KKY"''&] 8 > L!$''P@Q	

 -T2270F
 CIIK 't4@Fzz(#w.8IIJJy) <diiHV)$/:DIIFP%d<8$))DZ)$@=tyyII#D)-tyy9 L]    & %&J  P>		3OOP  VDdiiQTUUV  P>		3OOP  ZH$))UXYYZ  I7CHHLIs   >K .K) AK< 3AK<  K< '+L5 +M. ?+N' ++O  
K&%K&)K98K9<
L2!L--L25
M+?!M&&M+.
N$8!NN$'
O1!OO 
P*!PP)rD   r   r.  r   )r.  zfrozenset[str])rD   
str | Noner.  r/  )r   r   r   r   r.  r   )r   r   r   r   r.  r   )r   r   r.  r/  )r   r   r   r   r   r   r.  r1  )r   r   r.  r/  )r   r   r.  r1  )r   r   r   r   r   r   r   r   r   z
Any | Noner.  r1  )r   r   r   r   r.  z	list[str])r   r   r   r   r   r   r.  r1  )r  r   r   r   r   r   r.  r1  )r?  dict[str, Any] | Noner.  ztuple[bool, bool])r  r   r.  r/  )rD   r  r?  dict[str, Any]r.  r/  )rS  r   r.  r/  rI   )r   r   r?  r  r.  r1  )
r   r   r   r   r   r   r[  r/  r.  r1  )r   r   ru  r  r.  r1  )r   r   r   r   r   r   r.  r1  )r?  r  r.  dict[str, str])r  r  r?  r  r.  r  )
r  r   r  list[dict[str, Any]]ru  r  r  zPath | Noner.  r  )B__doc__
__future__r   loggingrB   r5   pathlibr   typingr   	getLogger__name__r   FAMILIA_IDENTIFICATION_SDT_TAGSr  rF   	frozensetr(  rs   rm   rn   ro   rp   rq   rr   r   rb  ru   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r5  W14_NSra  rA  r>  rP  rT  rV  r_  rZ  rq  rv  r}  r~  r  r  r  r  r  r  r  rt   s   0r:   <module>r     sT   [ "  	   			8	$# $@, ! O OO n=>  ##_`#_aq#_`  % mlA 	!l  # hgA 	!g  & qpA 	!p   mlA 	!l  \[A 	![ &  ( 	E&A)<  &^.2

 	 	
  
2&M-R`E
;| 
@xu% "K
>" &*!!"! 
!H/d6!v .2* 
<  " (/d/dcL%8 %8+9%8%8Z '+mmm +m
 $m mq as$   G;:H H8H
H6H