
    Lj}g                       U d Z ddlmZ ddlZddlZddlZddlZddlZddl	m
Z
m	Z	mZmZmZ ddlmZ ddlmZ  ee                                          j        d         Zded	<   ed
z  dz  Zded<   dZded<   dZded<   dZded<   dZded<   dZded<   g dZded<   dZded<   d0dZd1d!Z d1d"Z! e
d#d$d%          ed&d2d+Z"d3d,Z#d4d.Z$e%d/k    r e$             dS dS )5aY  Deterministic, synthetic-only SQLite fixture for Dashboard v5 acceptance work.

This module deliberately knows nothing about a Dashboard v5 Python/UI API.  It only
materializes the canonical schema and representative rows at a caller-provided
path.  Dates are derived from an explicit anchor so freshness tests do not depend
on wall-clock time.
    )annotationsN)datedatetimetime	timedeltatimezone)Path)Final   r
   ROOTdatabasez
schema.sqlDEFAULT_SCHEMA)Aphthen/MundulzerazGI/Darmu   Müdigkeit/FatigueHautAugenGelenkeu   Vaskulär/Thrombose-WarnzeichenSYMPTOM_DIMENSIONS)r      r      SPRINT4B_LAGS)baseline_pre_treatmentearly_treatmentstable_treatmentunknownSPRINT4B_PHASES)zapple:heart_rate_variabilityznutrition:histamine_scoreSPRINT4B_PREDICTORSBspearman_7d_block_permutation_complete_case_phase_stratified_bh_v1SPRINT4B_METHOD)complete_casephase_stratified7d_block_permutationno_causalitySPRINT4B_BASE_FLAGSz!dashboard-v5-synthetic-fixture-v1SYNTHETIC_FIXTURE_MARKERreturndict[str, object]c                 T   g } t           D ]q}t          D ]e}t          D ]Y}d}dd|z
  d|z
  }}}t          d|dz  z
  d          }t          d|dz  z   d          }	t          d	|d	z  z   d          }
t	          t
                    }|t           d
         k    r|d
k    r|t          d
         k    rd\  }}	}
n}|t           d
         k    r-|dk    r'|dk    r!d\  }}dx}x}	}
|                    d           n?|t           d         k    r.|dk    r(|dk    r"d\  }}}}dx}x}	}
|                    d           |                     |dd||d|||||z
  t          ||z  d          d||	|
d|t          |d           [gst	          t                    t	          t                    dd| dS )zHReturn a deterministic engine-compatible, aggregate-only Sprint-4B grid.computed      gzG?g{Gz?r   g{Gz?g{Gz?gQ?r   )        r+   r+   r   r   )insufficient_nr   Nlow_n_or_variancer   r   )insufficient_coverager)   
   r   low_target_coveragesymptom_total)	predictortarget)lag_daysmedication_phase   )eligible_target_daysexpected_target_daysobserved_pairsmissing_pairstarget_coverage)rhop_valueq_value)id
dimensionssample
statisticsstatusmethodquality_flags predictor_d_to_target_d_plus_lag)r4   medication_phaseslag_direction)r@   results)r   r   r   roundlistr#   appendr   )rI   r2   lagphaserC   expectedeligibleobservedr<   r=   r>   flagss               N/home/agent/.hermes/repos/HealthManager/tests/fixtures/dashboard_v5_fixture.pysprint4b_correlation_fixturerT   *   sG   ')G( ! !	   	  	C(  #/128R#XH($)$t*;Q$?$?(-dS4Z.?(C(C(-dS4Z.?(C(C011 3A 6663!88Q`abQcHcHc,9)C''"5a"888SAXX%SdJdJd':$FH.22C2'GLL!45555"5a"888SAXX%SeJeJe;]8FHh.22C2'GLL!6777(1_MM/2"N"N0808*2)1H)<+0H1Da+H+H  +.'g"V"V$-%*       # 	F ]++!%o!6!6?
 

       dayr   strc                *    |                                  S )N)	isoformatrV   s    rS   _iso_dayr[   Y   s    ==??rU   c                    t          j        | t          d          t          j                                                  S )N   )tzinfo)r   combiner   r   utcrY   rZ   s    rS   	_iso_noonra   ]   s.    Cb(,???IIKKKrU     r6      )anchor_dateschema_pathdb_path
str | Pathrd   re   c               z  5 t          |           }t          |          }|                                rt          d|           |                                st	          d|           |j                            dd           t          d          z
  }t          d          z
  }t          d          z   }fd	t          dd
          D             }t          d
          z
  }	t          d          z
  }
t          j
        |          }t          j        |_        	 |                    |                    d                     |                    d           |                    dt           f           |                    dddt%          |          t%          |          ddddddddddt%          |          fddt%          |          t%          |          dddd ddd!d"d#dt%          |          fdd$t%          |          t%          |          d%ddd&ddd'd(d)dt%          |          fdd*t%          |          t%          |          dd+d,d-ddd.d/d0dt%          |          fg           g }t          dd1          D ]}t          |          z
  }d2d3|z   d4fd$d5|z   dfd6d7|dz  z   d8fdd9|d:z  z   dffD ]l\  }}}|d6k    r|d;k    rd<| d=| }|                    d|t%          |          t%          |          |d|d>dd| d?|| d@dt%          |          f           m|                    d|           t)                      dA         }t%                    5t+          |t,                    sJ |D ]}t+          |t.                    sJ |                    dB|dC         dD         |dC         dE         |dF         dG         |dF         dH         |dI         dJ         |dI         dK         |dI         dL         |dI         dM         |dI         dN         |dO         dP         |dO         dQ         |dO         dR         |dS         |dT         t1          j        |dU                   |dS         dVk    rdWn|dS         dXk    rdYndZ5f           |                    d[5fd\d]d^d_d`t5          |          dadbdcffD             ddded,dfdgdhdhdedidjdkdlddm5fgz              |                    dndodpdkdqdrds5fdtdpdkdudrds5fdvdpdkdudrds5fdwdxdydqdd5fdzdpdkd{drds5fg           |                    d|t5          t          d;          z
            dodpdkd}dd~dr5f	t5          |          dtdpdkd}dddr5f	t5          t          d          z             dvdpdkdt5          t          d          z             ddr5f	t5          t          d          z             dzdpdkddddr5f	g           fddD             }d}ddrdt5          |          dddd:dddddd55fddrdt5          |          dddddddddd55fg}ddddddd5fddddqddd5fg}g d}g }t7          |d          D ]\  }}t7          |          D ]\  }\  }}} d:|dz  z   |z   }!d|dz
           }"d|                                 d|" }#d|dz  z   }$d|z   }%d|dz  z   }&d|z   }'|                    |!drd| d=| t5          |          ||#dd:d|$|%|&|'d| d=| 55f           |                    |!|| dddd5f           |                    |!dd|z   dt=          d|z             f|!dd|z   dt=          d|z             f|!dd|dz  z   dt=          d|dz  z             f|!dd|dz  z   dt=          d|dz  z             fg           d| d=| }(|                    |(|#                                d|#|| dddddddqddt5          |          f           |                    d|           |                    d|           |                    d|           |                    d5fd|D                        |                    dd |D                        |                    d|           |                    dd           |                    ddddt5          |          t5          |          ddddƉ5f
           t@          j!        "                    dtF          dz  dz  dz            })|)r|)j$        sJ t@          j!        %                    |)          }*|)j$        &                    |*           |*'                    |           |*(                    |           tA          j)        d˦          *                    |           tA          j)        d̦          *                    |           |                    dͦ           |                    dtV          ,                    dϦ          f           |                    dЦ           g ||}+|+D ]%},|*-                    |t5          |,                     &d}-dҠ.                    dӄ |+D                       }.dԄ |+D             }/|                    d|-f           |                    d|. dם|-g|/           |                    d|. dם|-g|/           |                    d٦          /                                r|                    d|-f           g }0t          d۬          z
  }1t7          |          D ]m\  }}t7          t`                    D ]S\  }2}3|3dk    r||1k    rdnd} n||2z   d;z  } |0                    t5          |          |3t=          |           ddމ5f           Tnt`          dd߅         D ]*}3|0                    t5          |	          |3ddd5f           +|                    d|0           |1                                 |                    d          2                                }4|4rtg          d|4           n9# th          $ r, |5                                 |6                    d            w xY w	 	 |5                                 n:# th          $ r Y n.w xY w# 	 |5                                 w # th          $ r Y w w xY wxY w|7                    d           t5                    t5          |          t5          |          t5          |          d |D             t5          |	          t5          |
          ddS )zCreate a new synthetic database and return its deterministic case manifest.

    ``db_path`` must not already exist.  This fail-closed behavior prevents this
    helper from ever replacing a real database accidentally.
    z'refusing to replace existing database: zschema not found: T)parentsexist_okr   days-   r   c                6    g | ]}t          |           z
  S rk   r   .0offsetrd   s     rS   
<listcomp>z.build_dashboard_v5_fixture.<locals>.<listcomp>w   s)    \\\f[9&+A+A+AA\\\rU   	   r/   zutf-8)encodingzECREATE TABLE dashboard_v5_synthetic_fixture (marker TEXT PRIMARY KEY)z=INSERT INTO dashboard_v5_synthetic_fixture(marker) VALUES (?)a  INSERT INTO apple_health_records
               (record_type,metric,start_date,end_date,value,value_text,unit,
                source_name,source_version,device,file_name,file_hash,record_hash,
                raw_json,imported_at)
               VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)HKQuantityType
heart_rateg      P@Nz	count/minzSynthetic Current Source1zSynthetic Devicezsynthetic-current.jsonzfixture-current-filezfixture-current-recordz{}
step_countg     H@countzSynthetic Stale Sourcezsynthetic-stale.jsonzfixture-stale-filezfixture-stale-recordresting_heart_rateg     N@zSynthetic Future Sourcezsynthetic-future.jsonzfixture-future-filezfixture-future-recordoxygen_saturationznot measured%zSynthetic Missing Value Sourcezsynthetic-missing.jsonzfixture-missing-filezfixture-missing-record   heart_rate_variabilityg      E@msg      N@sleep_analysisg      @hrg     @d      zfixture-explorer--zSynthetic Explorer Sourcez.jsonz-recordrI   af  INSERT INTO multimodal_correlation_results
                   (predictor,target,lag_days,medication_phase,n,eligible_target_days,
                    expected_target_days,target_coverage,missing_pairs,rho,p_value,q_value,status,
                    method,quality_flags,interpretation,computed_at)
                   VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)r?   r2   r3   r@   r4   r5   rA   r9   r7   r8   r;   r:   rB   r<   r=   r>   rC   rD   rE   r(   uG   Kein belastbares korrigiertes Signal; explorativ und keine Kausalität.r.   uO   Unzureichende Zielabdeckung; keine Korrelation berechnet und keine Kausalität.uG   Unzureichende vollständige Datenpaare oder Varianz; keine Kausalität.ah  INSERT INTO laborwerte
               (parameter_name,wert,einheit,reference_min,reference_max,
                abnahme_datum,befund_datum,wert_original,quelle,
                validierungsstatus,source_type,reference_range_source,
                verified_against_original,provenance_note,ermittlung_datum)
               VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)c                <    g | ]\  }}}}d |d|||||ddddddfS )zC-Reaktives Protein (CRP)zmg/Lsynthetic laboratory fixture	validiert	syntheticscanned_originalr   z1Synthetic test row; no person or source document. )rr   rV   valueref_minref_maxfixture_timestamps        rS   rt   z.build_dashboard_v5_fixture.<locals>.<listcomp>   sZ        1C	 0e%C[R]&+^`q  rU   )z
2024-01-104.205)z
2024-10-15z5.1r   6)z
2025-05-20z7.4NN)z
2025-12-01z8.8r   r   z12.5r   r   zFaktor VIII11850150z
2025-08-12r   r   r   r   zDSynthetic single-observation test row; no person or source document.zINSERT INTO medikamente(medikament_name,dosierung,anwendungsform,prescription_status,prescription_status_source,prescription_status_provenance,ermittlung_datum) VALUES(?,?,?,?,?,?,?)"SYNTHETIC_EVENT_ON_MEASUREMENT_GAPz10 mgr   fixturezsynthetic fixture!SYNTHETIC_ADMINISTERED_MEDICATIONactiveISYNTHETIC_PLANNED_MEDICATION_WITH_A_VERY_LONG_LABEL_FOR_RESPONSIVE_LAYOUTzHyrimoz / Adalimumabz40 mgsubkutanSYNTHETIC_CANCELLED_MEDICATIONendedzINSERT INTO medication_administrations
               (datum,medication_name,dose,route,event_type,scheduled_next_date,notes,source,created_at)
               VALUES(?,?,?,?,?,?,?,?,?)administeredztimeline gap fixturezdisplay as administered onlyplannedz must not be represented as taken	cancelledc                6    g | ]}t          |           z
  S ro   rp   rq   s     rS   rt   z.build_dashboard_v5_fixture.<locals>.<listcomp>   s)    WWW&yf'='='==WWWrU   )r/   ru      ))	breakfastzsynthetic breakfast componentr   )lunchzsynthetic lunch componentr   )dinnerzsynthetic dinner componentr   )snackzsynthetic snack componentr   completer   SYNTHETIC_COMPLETE_FOOD_MAPPINGzSynthetic Brandgr   zfixture-food-complete
incompleter   FSYNTHETIC_INCOMPLETE_FOOD_MAPPING_WITH_A_VERY_LONG_NAME_THAT_MUST_WRAPzfixture-food-incompletezsynthetic cucumber
classifiedfixture_mapping_v1highzsynthetic source classificationfixture_unmappedlowz"intentionally unmapped fixture row))r   nutrient.fiberg@r   r   )r   nutrient.sugar       @r   z2.0)r   znutrient.vitamin_cg      4@r   20)r   nutrient.sodiumg      $@mgz0.01)start)ONETWOTHREE
SYNTHETIC__EXPOSURE_DAY_   #   r]   r)   r   z	exposure-zfixture-exposure-z!synthetic SIGHi source fixture v1r   r   r   g      @znutrient.saturatedg      ?r   g      Y@   r   zfixture-mapping-assignsighi_referenceSIGHiz
fixture-v1zsynthetic mapping provenance sighi_mapping_load_v2zINSERT INTO nutrition_items
               (id,source,source_item_id,datum,meal,name,brand,amount,amount_unit,
                kcal,protein_g,carb_g,fat_g,item_hash,imported_at,updated_at)
               VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)zINSERT INTO nutrition_histamine_scores
               (item_id,canonical_food,sighi_score,traffic_light,tags,confidence,reason,scored_at)
               VALUES(?,?,?,?,?,?,?,?)zpINSERT INTO nutrition_item_nutrients(item_id,nutrient_key,value,unit,raw_value)
               VALUES(?,?,?,?,?)zINSERT OR IGNORE INTO histamine_food_rules
               (canonical_food,sighi_score,category,tags,notes,confidence,source,updated_at)
               VALUES(?,?,?,?,?,?,?,?)c           
     ,    g | ]\  }}}||d ddddfS )r   r   zsynthetic source ruler   zSIGHi fixture-v1r   )rr   _	canonicalscorer   s       rS   rt   z.build_dashboard_v5_fixture.<locals>.<listcomp>B  sZ      g  g  g  EX  EF  HQ  SXiY8OQWYkm~  g  g  grU   zNINSERT OR IGNORE INTO histamine_food_aliases(alias,canonical_food) VALUES(?,?)c                &    g | ]\  }}}d | d|fS )z
synthetic z aliasr   )rr   mealr   r   s       rS   rt   z.build_dashboard_v5_fixture.<locals>.<listcomp>F  s0    YYY8Ji'4'''3YYYrU   a~  INSERT INTO nutrition_mapping_provenance
               (action_id,normalized_name,decision,alias,canonical_food,sighi_score,confidence,
                mapping_method,source_label,source_version,note,ingredient_review_required,
                personal_tolerance_status,personal_tolerance_note,definition_version,affected_day)
               VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)zINSERT OR REPLACE INTO histamine_food_rules
               (canonical_food,sighi_score,category,confidence,source,updated_at)
               VALUES(?,1,'synthetic','high','synthetic_sighi_fixture','fixture-v1'))synthetic reviewed foodzINSERT INTO nutrition_review_queue
               (normalized_name,example_name,occurrence_count,first_seen,last_seen,suggested_canonical_food,suggested_score,reason,status,updated_at)
               VALUES(?,?,?,?,?,?,?,?,?,?)zFsynthetic incomplete food mapping with a very long name that must wrapr   zsynthetic missing mappingopendashboard_v5_fixture_workerscriptshealthz!health_dashboard_action_worker.pyzdashboard_v5.sprint6i_c_schemazdashboard_v5.medication_schemazuUPDATE medikamente SET business_revision=printf('%064x', id) WHERE prescription_status IN ('active','paused','ended')zAUPDATE medication_public_identity_key SET key=? WHERE singleton=1@7cf07cf07cf07cf07cf07cf07cf07cf07cf07cf07cf07cf07cf07cf07cf07cf0zDUPDATE medication_schema_meta SET installed_at='2026-06-15 12:00:00'z2026-06-15 12:00:00,c              3     K   | ]}d V  dS )?Nr   )rr   r   s     rS   	<genexpr>z-build_dashboard_v5_fixture.<locals>.<genexpr>u  s"      ========rU   c                ,    g | ]}t          |          S r   r[   rr   rV   s     rS   rt   z.build_dashboard_v5_fixture.<locals>.<listcomp>v  s    ???hsmm???rU   z4UPDATE nutrition_mapping_provenance SET applied_at=?zCUPDATE nutrition_daily_summary_v2 SET updated_at=? WHERE datum IN ()z?UPDATE nutrition_meal_summary SET updated_at=? WHERE datum IN (zUSELECT 1 FROM sqlite_master WHERE type='table' AND name='dashboard_schema_migrations'z3UPDATE dashboard_schema_migrations SET applied_at=?r6   r   daily_quick_scorezsynthetic complete dayzsynthetic incomplete dayz`INSERT INTO symptom_log(datum,symptom,schwergrad,kontext,notizen,created_at) VALUES(?,?,?,?,?,?)PRAGMA foreign_key_checkzfixture violates foreign keys: )
missing_oki  c                ,    g | ]}t          |          S r   r   r   s     rS   rt   z.build_dashboard_v5_fixture.<locals>.<listcomp>  s    !Q!Q!QC(3--!Q!Q!QrU   )rd   current_source_datestale_source_datefuture_source_datecomplete_symptom_daysincomplete_symptom_dayno_data_daysynthetic_only)8r	   existsFileExistsErroris_fileFileNotFoundErrorparentmkdirr   rangesqlite3connectRowrow_factoryexecutescript	read_textexecuter$   executemanyra   rL   rT   
isinstancerK   dictjsondumpsr[   	enumerateupperextendrW   casefold	importlibutilspec_from_file_locationr   loadermodule_from_specexec_moduleapply_document_schemaapply_media_schemaimport_moduleapply_schemabytesfromhexrecompute_nutrition_dayjoinfetchoner   commitfetchallRuntimeError	Exceptioncloseunlinkchmod)6rf   rd   re   r3   schemacurrentstalefuturer   r   r   
connectionexplorer_rowsrs   rV   metricr   unitkeycorrelation_resultsresultexposure_days
meal_specsnutrition_itemshistamine_rowsnutrient_rowsprovenance_rows	day_indexexposure_day
meal_indexr   r   r   item_idday_wordproduct_namekcalproteincarbsfat	action_idworker_specworker_modulerecomputed_daysnutrition_daydeterministic_timestampplaceholders
day_valuessymptom_rowsaphthae_event_daydimension_index	dimension	fk_errorsr   s6    `                                                   @rS   build_dashboard_v5_fixturer<  a   s    ']]F+F}} RPPPQQQ>> ? =V = =>>>
Mt444I1----G),,,,E9!,,,,F\\\\PUVWYZP[P[\\\(9!+<+<+<<	r 2 2 22K((J$[Jh  !1!17!1!C!CDDDS	
 	
 	
 	K%'	
 	
 	
 	8 "<71C1CYwEWEWY]_cep  sM  OR  Tf  h@  BX  Zr  tx  zC  DK  zL  zL  M!<51A1A9UCSCSU[]acj  mE  GJ  L^  `v  xL  Nd  fj  lu  v{  l|  l|  }!#769J9JIV\L]L]_ceikv  yR  TW  Yk  mD  F[  ]t  vz  |E  FL  |M  |M  N!#6	'8J8JIV]L^L^`dftvy  |\  ^a  cg  iA  CY  [s  uy  {D  EL  {M  {M  N		
 	
 	
 Arll 	 	F	v 6 6 66C)4&=$?%tf}kB!3"#4d;v4g>	(  #t ---&A++;&;;6;;$$$finninneUY[_/6HS---Y\OOOT9S>>&     	8
 	
 	
 	
 ;<<YG%k22-t44444) 	 	Ffd+++++@ 4L-vd|H/E<(4f\6JK]6^8$%56x8HI_8`8$%;<fX>NO`>a8$_5vl7KE7R<(3VL5I)5T8$fX&6
6/CZ8[8[h':55 ^] "(+/FFF jif%   0 	8    4353e__fc375    "5#tUL,X]2KN`bcZ\m	
 	
 	
: 	 E5wYXacv  yJ  K4g{HV_at  wH  I\^egrt|  H  J]  _p  q'*itUfg17KR[]p  sD  E		
 		
 		
 	, +	q(9(9(99::<`bikv  yG  IM  Oe  gp  rC  D'""$GR]_mos  vT  V_  ar  s+	q(9(9(99::  =H  JQ  S^  `i  ks  t  BK  QR  BS  BS  BS  tS  kT  kT  Vx  zC  EV  W+	q(9(9(99::<\^egrt  BF  Hj  lu  wH  I		
	
 
	
 
	
 XWWWJWWW

 	:x'8'8'Cdfwy|  B  DE  GH  JK  MN  Pg  iz  |M  N	<'):):H  GO  QU  W[  ]`  bf  hl  nr  tx  zS  Uf  hy  z

 $a7KVUv  yJ  KdI'95Bfhyz

 
 
 '0a'H'H'H 	 	#I|8A*8M8M  4
4T9eR0:=29q=ARDJJLLRRRRZ"_,z/Z!^+*n&&i)GY)G)G)G)GR^I_I_aegs  vG  IL  NQ  SW  Y`  bg  il  nT  BK  nT  nT  NR  nT  nT  Vg  iz  {   %%i>RTZ\  BS  T   $$ "2C*4Dc3sU_O_K`K`a "2C*4Dc3sU_O_K`K`a "6j1n8LcSVWZ]gjk]kWkSlSlm "3UZ"_5LdTWX]`jmo`oXoTpTpq	   ByAA4AA	&& 5 5 7 7<QZ\acik|  F  HT  Vt  vw  yB  DF  H_  ai  jv  aw  aw  x   /4 	: 	
 	
 	
 	* 		
 	
 	
 	$	
 	
 	

 	* g  g  g  g  \f  g  g  g		
 	
 	
 	\YYjYYY	
 	
 	
 	:
 	
 	
 	
 	X )		
 	
 	
 	. V  X`  bc  em  nu  ev  ev  x@  AH  xI  xI  Kd  fg  iD  FL  N_  `		
 	
 	
  n<<)9x'*MM
 
 1{1111!77DD&&}555++J777((444 @AANNzZZZ @AANNzZZZ D	
 	
 	
 	O]];'')	
 	
 	
 	R	
 	
 	
 4M373, 	W 	WM11*h}>U>UVVVV"7xx==_=====?????
B$&	
 	
 	
 	aR^aaa$2z2	
 	
 	
 	]l]]]$2z2	
 	
 	
 c
 

(**	 E(*   ')*;*;*;;'(=>> 	N 	NNIs.78J.K.K N N* 444!$(9!9!9AAqEE&8A=E##Xc]]Is5zzK^`x  {L  %M  N  N  N  NN ,CRC0 	X 	XI*@!A!A9cSf  iC  EV  !W  X  X  X  Xn	
 	
 	
 	&&'ABBKKMM	 	NLLLMMM	N   &&&	N	 	 	 	D		 	 	 	D	
LL  ,,'00%e__&v..!Q!Q;P!Q!Q!Q"*+A"B"B,,	 	 	sU   *lp; :r ;6q11r 6r 
rrsr21s2
r?<s>r??sc           
        t          |           }t          j        d| dd          	 fddD             }                    d                                          d                             d	                                                              d
                                          d                             d                                          d         t          d                     d          D                                           d                                          d}                                 n#                                  w xY w||dS )zGReturn structural acceptance checks without importing application code.zfile:z?mode=roT)uric                r    i | ]3}|                     d |                                           d         4S )zSELECT COUNT(*) FROM r   )r   r  )rr   tabler  s     rS   
<dictcomp>z$validate_fixture.<locals>.<dictcomp>  sT     
 
 
 :%%&Ee&E&EFFOOQQRST
 
 
rU   )apple_health_records
laborwertemedication_administrationsr!  nutrition_histamine_scoressymptom_logzPRAGMA integrity_checkr   r   zSELECT COUNT(*) FROM laborwerte
                   WHERE verified_against_original=1 AND CAST(wert AS REAL)>CAST(reference_max AS REAL)zSELECT COUNT(*) FROM (SELECT datum FROM symptom_log
                   WHERE kontext='daily_quick_score' GROUP BY datum HAVING COUNT(DISTINCT symptom)=7)c              3  &   K   | ]}|d          V  dS )r   Nr   )rr   rows     rS   r   z#validate_fixture.<locals>.<genexpr>  s6       ( (3A ( ( ( ( ( (rU   z:SELECT DISTINCT event_type FROM medication_administrationszSELECT SUM(canonical_food IS NOT NULL AND sighi_score IS NOT NULL),
                          SUM(canonical_food IS NULL OR sighi_score IS NULL)
                   FROM nutrition_histamine_scores)	integrityforeign_key_errorsverified_lab_outliersr   medication_statesfood_mapping_states)countschecks)r	   r   r   r   r  r  sortedr  )rf   dbrN  rO  r  s       @rS   validate_fixturerR    s   	gB!5!5!5!54@@@J
 
 
 

 
 
 $++,DEENNPPQRS","4"45O"P"P"Y"Y"["[%/%7%7k& & hjj& &0%7%7i& & hjj& "( ( (*:L:LL; ; ( ( ( " " $.#5#56$ $ hjj%
 
* 	
///s   DE E#Nonec            	     0   t          j        t                    } |                     ddd           |                     dt          j        t	          ddd	          
           |                                 }|j        rt          |j                  }n%t          t          j
        d                    dz  }t          ||j                  }t          t          j        t!          |          |t#          |          ddt$                               d S )N)descriptionoutputr   z-new SQLite path; omit for a temporary fixture)nargshelpz--anchor-daterb   r6   rc   )typedefaultzdashboard-v5-fixture-)prefixz	health.db)rd   )pathmanifest
validationr   )indentrZ  )argparseArgumentParser__doc__add_argumentr   fromisoformat
parse_argsrV  r	   tempfilemkdtempr<  rd   printr   r   rW   rR  rK   )parserargsrV  r]  s       rS   mainrk    s   $999F
2abbb
d.@$tUVXZJ[J[\\\D{ Vdk""h&.EFFFGG+U)&d>NOOOH	$*c&kkxO_`fOgOghhqr  }A  B  B  B  C  C  C  C  CrU   __main__)r%   r&   )rV   r   r%   rW   )rf   rg   rd   r   re   rg   r%   r&   )rf   rg   r%   r&   )r%   rS  )&rb  
__future__r   r`  importlib.utilr   r   r   rf  r   r   r   r   r   pathlibr	   typingr
   __file__resolveri   r   __annotations__r   r   r   r   r   r   r#   r$   rT   r[   ra   r<  rR  rk  __name__r   rU   rS   <module>ru     sf     # " " " " "         > > > > > > > > > > > > > >            d8nn$$&&.q1 1 1 1 1z)L8 8 8 8 8      $ # # # #     [  Z Z Z Z] ] ] ] ]        #F  E E E E, , , ,^   L L L L T1b)),	P P P P P Pf
"0 "0 "0 "0J
C 
C 
C 
C zDFFFFF rU   