from pathlib import Path
import json,re,html,base64
t=Path('/private/tmp');r=Path('/Users/vengurnagu/Desktop/Sense India')
groups=[]
def group(stage,title,instruction,items):groups.append(dict(stage=stage,title=title,instruction=instruction,items=items))
group(1,'Pupillary response','Observe without stimulation.',['Do pupils move constantly?','Do pupils react to changes in light?'])
group(1,'Blink reflex','Move a hand towards the learner’s face without making a draught.',['Does the learner blink?'])
group(1,'Response to light','Source procedure: use different lights in a darkened room.',['Responds to continuous light','Responds to flashing light','Responds to moving light'])
group(1,'Fixation','Use motivating objects and verbal encouragement; observe fixation on a bright object.',['Fixes eyes at 7 inches','Fixes eyes at 2 feet','Fixes eyes at 10 feet'])
group(1,'Eye preference','Show an interesting object. Cover each eye in turn and observe the response.',['Consistently holds objects near one eye','Left eye — record the observed response','Right eye — record the observed response'])
group(1,'Visual fields','Bring a visually interesting object or light slowly into the visual field from behind the learner. Note when it is seen.',['Above','Below','Right','Left'])
group(1,'Focus on objects','Show interesting objects at different distances and observe which are seen.',['Sees object at 7 inches','Sees object at 2 feet','Sees object at 10 feet'])
group(1,'Eye contact','Observe with familiar people in different situations, such as mealtimes.',['Brief eye contact','Eye contact for 3 seconds or more','Maintained eye contact'])
group(1,'Visual behaviours','Observe behaviours that may indicate use of residual vision.',['Light gazing','Hand flicking','Other visual behaviour — describe in comments'])
group(2,'Hand regard','Place a visually interesting toy in the learner’s hand; also play hand games.',['Looks at the toy in their hand','Looks at your hands during hand games'])
group(2,'Tracking','Move motivating objects slowly and observe visual tracking.',['Mid-line to left','Mid-line to right','Right to left across mid-line','Left to right across mid-line','Downwards','Upwards','Diagonally','Circular movement'])
group(2,'Transfer of attention','Use two torches or equally interesting objects; move one, then the other. Object spacing is pending client confirmation: English says 1 foot; Hindi says 2 feet.',['Shifts gaze at the same distance','Shifts gaze from near to distant','Shifts gaze from distant to near'])
group(2,'Scanning','Place three objects in a line and point along the line.',['Scans the line of objects'])
group(2,'Turning eyes towards an object','Touch the learner with an object and observe whether they turn to look.',['Turns to look to the left','Turns to look to the right'])
group(2,'Attempts to reach visually for objects','Place objects within the learner’s reach.',['Attempts to reach the objects'])
group(2,'Visual exploration','Observe whether the learner turns objects in their hand to explore visually.',['Sometimes','Often'])
group(2,'Object recognition','Observe recognition of familiar objects.',['Recognises a few familiar objects','Recognises many familiar objects'])
group(2,'Visual discrimination','Observe visual discrimination for each item.',['Size','Colour','Shape','Family members','Carers','Strangers'])
hearing=[
('Does the learner show any response to sound?','Examples: startles to sudden loud sound, blinks at a sound, smiles or calms down in response to music.'),
('Does the learner notice or attend to particular sounds?','Examples: a familiar voice or noise.'),
('How interested is the learner in environmental sounds?','Describe whether responses to auditory stimuli are consistent or inconsistent.'),
('What kinds of sound interest the learner?','Describe loud sounds, music or familiar environmental sounds, and effects of pitch, volume, direction and sound duration.'),
('Does the learner show interest in voices?','Examples: their mother’s or father’s voice.'),
('Does the response vary with distance from the sound?','Describe the distance and response.'),
('How loud must a sound be before attention is gained?','Describe the observation in comments. The source provides no measurement scale.'),
('Is the response affected by background noise?','Describe the effect observed.'),
('Does the learner show more interest in sounds from one side?','Record left, right or behind; whether the learner turns towards sounds; and responses from left, right, above and below.'),
('Does the learner recognise familiar sounds?','Describe the sounds and observed response.'),
('Can the learner pick out one sound from a range of sounds?','Describe the observation.'),
('Does the learner show awareness of sound versus no sound?','Example: behaviour changes when a particular sound stops.'),
('Does the learner move towards sounds?','Describe accuracy when using sound to orientate themselves.'),
('How quickly does the learner notice and respond to sounds?','Describe effects of time, place, position, comfort level and competing sensory stimuli.'),
('Are there sounds the learner dislikes or that cause distress?','Specify which sounds.'),
('Does the learner vocalise?','Describe the vocalisation.'),
('Are consonant sounds present as well as open vowel sounds?','Describe the sounds observed.')]
data=dict(groups=groups,hearing=hearing)
(t/'functional-data.json').write_text(json.dumps(data,ensure_ascii=False))
css='''*{box-sizing:border-box}body{margin:0;background:#f7f4f8;color:#302039;font:15px/1.5 Arial,sans-serif}header{background:#47224f;color:white;border-bottom:6px solid #f37933;padding:24px max(4vw,20px)}header a{color:white}h1{font-size:28px;margin:14px 0 8px}h2,h3{color:#47224f}a{color:#47224f}.shell{max-width:1350px;margin:24px auto;padding:0 20px}.notice{background:#fff0e5;border-left:4px solid #f37933;padding:16px}.toolbar{display:flex;gap:12px;flex-wrap:wrap;align-items:center;margin:18px 0}.layout{display:grid;grid-template-columns:235px minmax(0,1fr);gap:20px}nav{background:#47224f;padding:12px;border-radius:12px;align-self:start}button,input,textarea,select{font:inherit}button,a.button{padding:10px 14px;border:1px solid #d9cede;border-radius:7px;background:white;color:#47224f;cursor:pointer;text-decoration:none}nav button{display:block;width:100%;text-align:left;border:0;background:transparent;color:white;margin:5px 0}nav button[aria-current=step]{background:#f37933;color:#321637;font-weight:bold}.sheet{background:white;border:1px solid #e4dae7;border-radius:12px;padding:24px;min-width:0}.fields{display:grid;grid-template-columns:1fr 1fr;gap:18px}.field{display:flex;flex-direction:column;gap:6px}input,textarea,select{padding:10px;border:1px solid #d9cede;border-radius:6px;max-width:100%;width:100%;background:white;color:#302039}textarea{min-height:70px;resize:vertical}table{border-collapse:collapse;width:100%;table-layout:fixed}th,td{text-align:left;vertical-align:top;padding:12px;border-bottom:1px solid #e4dae7}th{background:#f0ebf2;color:#47224f}th:first-child{width:47%}th:nth-child(2){width:18%}.scroll{overflow-x:auto}.hint{font-size:13px;color:#6d6275}.actions{display:flex;gap:12px;justify-content:space-between;flex-wrap:wrap;margin-top:24px}.primary{background:#47224f;color:white}.badge{display:inline-block;background:#fff0e5;color:#853d12;padding:6px 10px;border-radius:7px}button:focus-visible,a:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible{outline:3px solid #f37933;outline-offset:3px}button:disabled{opacity:.5;cursor:default}.phone{max-width:430px}.phone .layout{display:block}.phone nav{display:flex;overflow:auto}.phone nav button{min-width:180px}.phone .fields{grid-template-columns:1fr}.phone table{min-width:650px}.phone .sheet{padding:16px}@media(max-width:760px){.layout{display:block}nav{display:flex;overflow:auto;margin-bottom:16px}nav button{min-width:180px}.fields{grid-template-columns:1fr}.sheet{padding:16px}table{min-width:650px}h1{font-size:24px}}@media print{header a,.toolbar,nav,.actions,#status{display:none!important}.layout{display:block}.shell{max-width:none}.sheet{border:0}.notice{font-size:12px}table{font-size:11px}tr{break-inside:avoid}}'''
logo=(r/'output/mockups/physiotherapy-assessment-mockups.html').read_text()
m=re.search(r'<img[^>]*src="([^"]+)"[^>]*>',logo)
logohtml='<img alt="Sense India" src="data:image/png;base64,'+base64.b64encode((r/'reference-documents/sense_logo.png').read_bytes()).decode()+'" style="width:63px;height:75px;object-fit:contain;float:right;background:white;padding:4px;border-radius:5px">'
page='''<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Functional Hearing &amp; Vision Assessment | Sense India</title><style>CSS</style></head><body><header>LOGO<a href="../../">← Sense India Demo</a><h1>Functional Hearing &amp; Vision Assessment</h1><p>Vision Stage 1 · Vision Stage 2 · Functional Hearing</p></header><main class="shell" id="app"><p class="notice"><strong>Draft mockup · Pending client confirmation.</strong> No age restriction is inferred from the filename “6-12”. Completion, review, sign-off, platform access, review intervals and interpretation remain pending. No score, diagnosis or referral is generated.</p><div class="toolbar"><span class="badge">Role: Pending client confirmation</span><span class="badge">English source wording</span><button id="device" type="button">Mobile preview</button><a class="button" href="../pdf/functional-hearing-vision-source.pdf" target="_blank" rel="noopener">English / Hindi source PDF</a></div><div class="layout"><nav id="nav" aria-label="Assessment sections"></nav><section class="sheet"><p class="hint" id="progress"></p><h2 id="title"></h2><div id="content"></div><div class="actions"><button id="back" type="button">Back</button><button id="save" type="button">Save demo draft</button><button id="next" type="button">Next</button></div><p id="status" role="status" aria-live="polite"></p></section></div><p class="hint">Observation prompts follow the supplied bilingual checklist. Source instructions are reference content; administration procedures require client approval. Demonstration details are fictional.</p></main><script>const data=DATA;</script><script>APPJS</script></body></html>'''
js=(t/'functional-app.js').read_text()
page=page.replace('CSS',css).replace('LOGO',logohtml).replace('DATA',json.dumps(data,ensure_ascii=False)).replace('APPJS',js)
(t/'functional-hearing-vision-mockups.html').write_text(page)
print('Prepared',sum(len(g['items']) for g in groups),'vision observations and',len(hearing),'numbered hearing observations.')
