◊
FallVetPaper
v1 · prime 967
.
');w.document.close();w.print()} function renderDocuments(v){const docs=state.documents.sort((a,b)=>b.createdAt-a.createdAt);v.innerHTML=`

Documents

${docs.length}
${docs.length?`${docs.map(d=>``).join('')}
DateTemplateCodeStatusHash
${dateStr(d.createdAt)}${esc(d.templateName)}${esc(d.code)}${d.status}${esc(d.hash)}
`:'
No documents.
'}`} function renderPractice(v){const f=state.firm||{};v.innerHTML=`

Practice Setup

`} async function savePracticeForm(){const f=state.firm||{id:uid('fi'),ts:now()};f.name=$('#fName').value.trim();f.email=$('#fEmail').value.trim();f.address=$('#fAddr').value.trim();f.phone=$('#fPhone').value.trim();f.rcvsNumber=$('#fRcvs').value.trim();f.updatedAt=now();state.firm=f;await idbPut('firms',f);await auditLog('practice.saved');toast('Saved');render()} function renderClients(v){v.innerHTML=`

Clients

${state.clients.length}
${state.clients.length?`${state.clients.map(c=>{const n=c.ownerName||((c.title||'')+' '+(c.firstName||'')+' '+(c.lastName||'')).trim()||c.id.slice(0,8);const a=(c.animals||[])[0]||{};return ``}).join('')}
OwnerAnimalSpecies
${esc(n)}${esc(a.name||'—')}${esc(a.species||'—')}
`:'
Clients sync from fallvetonboard.
'}`} const T0_QA=[ {q:/consent|informed|owner/i,a:'RCVS Code of Professional Conduct (Chapter 11): obtain informed consent before treatment. Explain: diagnosis, prognosis, treatment options, risks, costs. Consent should be documented. Emergency: treat without consent if in the animal\'s best interest and owner cannot be contacted. Under 16: parental consent required. Non-owner presenting: establish authority to consent.'}, {q:/euthanasia|put.?down|pts/i,a:'Animal Welfare Act 2006: euthanasia must be carried out humanely. RCVS: euthanasia is a clinical decision — can refuse if not in the animal\'s interest, but cannot refuse if animal is suffering and no alternative. Methods: IV barbiturate injection (pentobarbitone). Schedule 2 CD — record in register. Owner consent should be documented. Remains: offer individual/communal cremation or owner to take home.'}, {q:/controlled.?drug|cd|schedule|register/i,a:'Misuse of Drugs Regulations 2001: vets can possess, supply, and administer Schedule 2-5 CDs. Schedule 2 (ketamine, methadone, morphine, pethidine): bound register, safe storage (BS2881), running balance, annual stockcheck, destruction witnessed. Schedule 3 (buprenorphine, midazolam): safe custody required, no register needed. Schedule 4 (diazepam, zolazepam): invoice records only. Quarterly reconciliation recommended by RCVS.'}, {q:/referral|specialist|second.?opinion/i,a:'RCVS Code 3: client has right to seek a second opinion or referral. Vet should refer when case is beyond competence. Referral letter should include: signalment, history, clinical findings, diagnostics, treatment to date, reason for referral. Referral does not transfer clinical responsibility until the referral practice accepts the case. Referral fees are the client\'s responsibility.'}, {q:/vaccination|vaccine|titre/i,a:'WSAVA vaccination guidelines: core vaccines (dogs: DHP; cats: FPV, FHV, FCV) — primary course + 12-month booster, then every 3 years. Non-core based on risk. Titre testing available as alternative to booster vaccination. Rabies: required for APHA Pet Passport (travel). No UK legal requirement for vaccination (unlike some countries). Record batch number, expiry, and site.'}, {q:/insurance|claim|pre.?existing/i,a:'Vet completes the clinical section of the insurance claim form. Must be accurate and complete. Pre-existing conditions: must disclose to insurer. Common issues: policy exclusions, excess, co-payment, annual/lifetime limits. Direct claims: some insurers pay practice directly. Vet cannot refuse to complete a claim form. Fee chargeable for completion. Fraud Act 2006 applies to false claims.'}, {q:/rcvs|code|conduct|fitness/i,a:'RCVS (Royal College of Veterinary Surgeons) regulates the veterinary profession. Code of Professional Conduct: 10 principles. Fitness to Practise: disciplinary committee can warn, suspend, or remove from register. Annual renewal fee required. Practice Standards Scheme: voluntary accreditation (Core, GP, Hospital). CPD: minimum 35 hours over 3 years (RCVS requirement).'}, {q:/record|clinical|notes|soap/i,a:'RCVS requires adequate clinical records. SOAP format recommended: Subjective (history), Objective (examination), Assessment (diagnosis), Plan (treatment). Records must include: date, animal ID, owner, clinical findings, treatment, medications dispensed, consent obtained. Retain for minimum 7 years. Digital records: must be backed up. Records belong to the practice, not the client — but client has right to request copies.'}]; function askT0(q){for(const r of T0_QA){if(r.q.test(q))return {answer:r.a,source:'T0 · UK veterinary rules'}}return null} async function askT3(q){if(!state.settings.anthropicKey)return null;try{const res=await fetch('https://api.anthropic.com/v1/messages',{method:'POST',headers:{'x-api-key':state.settings.anthropicKey,'anthropic-version':'2023-06-01','content-type':'application/json'},body:JSON.stringify({model:'claude-sonnet-4-20250514',max_tokens:600,messages:[{role:'user',content:'You are a UK veterinary practice expert. RCVS, VSA 1966, controlled drugs, animal welfare. Concise.\n\n'+q}]})});if(!res.ok)return null;const j=await res.json();return {answer:j.content?.[0]?.text,source:'T3 · Anthropic'}}catch(e){return null}} function renderQA(v){v.innerHTML=`

Q & A

T0 + T3 BYOK
${(state.ui.chat||[]).map(m=>`
${esc(m.text)}${m.source?`
${esc(m.source)}
`:''}
`).join('')}
`;const box=$('#chatBox');if(box)box.scrollTop=box.scrollHeight} async function askQ(){const inp=$('#chatIn');if(!inp)return;const q=inp.value.trim();if(!q)return;inp.value='';if(!state.ui.chat)state.ui.chat=[];state.ui.chat.push({role:'user',text:q});render();let r=askT0(q);if(!r)r=await askT3(q);state.ui.chat.push(r?{role:'bot',text:r.answer,source:r.source}:{role:'bot',text:'No T0 match. Add BYOK key for T3.',source:'system'});persistUI();render()} function openModal(type){const modal=$('#modal');$('#modalTitle').textContent='Settings';modal.classList.add('open');$('#modalBody').innerHTML=`
`} function closeModal(){$('#modal').classList.remove('open')} function saveSettings(){state.settings.anthropicKey=$('#sKey').value.trim();state.settings.auditChain=$('#sAudit').checked;$('#tierBadge').textContent=state.settings.anthropicKey?'T3':'T0';persistUI();closeModal();toast('Saved');render()} function exportAll(){const d={tool:TOOLNAME,v:VERSION,ts:now(),firm:state.firm,clients:state.clients,documents:state.documents};const b=new Blob([JSON.stringify(d,null,2)],{type:'application/json'});const u=URL.createObjectURL(b);const a=document.createElement('a');a.href=u;a.download='fallvetpaper-export.json';a.click();URL.revokeObjectURL(u);toast('Exported')} function importAll(){const inp=document.createElement('input');inp.type='file';inp.accept='.json';inp.onchange=async()=>{const f=inp.files[0];if(!f)return;try{const d=JSON.parse(await f.text());if(d.firm){state.firm=d.firm;await idbPut('firms',d.firm)}for(const k of['clients','documents']){if(Array.isArray(d[k]))for(const r of d[k]){state[k].push(r);await idbPut(k,r)}}persistUI();toast('Imported');render()}catch(e){toast('Failed')}};inp.click()} async function wipeAll(){if(!confirm('Wipe ALL data?'))return;for(const s of['clients','firms','documents','audit','state']){const tx=db.transaction(s,'readwrite');tx.objectStore(s).clear();await new Promise(r=>{tx.oncomplete=r})}location.reload()} async function seedDemo(){if(state.clients.length||state.firm)return; const firm={id:uid('fi'),name:'Demo Veterinary Practice',address:'3 Green Lane, London SW6 4AB',email:'info@demovets.co.uk',phone:'020 7890 1234',rcvsNumber:'XVP-12345',updatedAt:now(),isDemo:true}; state.firm=firm;await idbPut('firms',firm); const c1={id:uid('cl'),ownerName:'Sarah Mitchell',phone:'07700 900111',email:'s.mitchell@email.co.uk',address:'42 Park Road, London SW6 5QR',animals:[{name:'Max',species:'Dog',breed:'Labrador Retriever',age:'6 years',sex:'Male',neutered:'Yes',microchip:'981234567890123',colour:'Golden',dob:'2020-03-15'}],ts:now(),isDemo:true}; const c2={id:uid('cl'),ownerName:'David Chen',phone:'07700 900222',email:'d.chen@email.co.uk',address:'15 Elm Street, London SW6 3TT',animals:[{name:'Luna',species:'Cat',breed:'British Shorthair',age:'3 years',sex:'Female',neutered:'Yes',microchip:'981987654321098',colour:'Blue',dob:'2023-01-10'}],ts:now(),isDemo:true}; state.clients.push(c1,c2);await idbPut('clients',c1);await idbPut('clients',c2); await auditLog('demo.seeded',{reasoning:'first boot'});await persistUI()} (async function boot(){try{await openDB();await loadAll();await seedDemo();initMesh();$('#tierBadge').textContent=state.settings.anthropicKey?'T3':'T0';render()}catch(e){console.error('[fallvetpaper] boot error:',e);document.getElementById('view').innerHTML='
Boot error: '+esc(e.message)+'
'}})();