' + bodyHtml + '
' + ''; } function openPrintDocument(title, bodyHtml, extraCss){ var doc = popupHtml(title, bodyHtml, extraCss); var blob = new Blob([doc], { type: 'text/html;charset=utf-8' }); var url = URL.createObjectURL(blob); var w = window.open(url, '_blank', 'noopener,noreferrer,width=900,height=700'); if (!w) { alert('Please allow popups to print.'); URL.revokeObjectURL(url); return; } setTimeout(function(){ try { URL.revokeObjectURL(url); } catch(e){} }, 60000); } async function barcode(){ try { var r = await fetch('/api/enterprise/barcode', { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({createdBy:'admin'}) }); var d = await r.json(); var code = esc(d.sampleCode || d.barcodeValue || ''); openPrintDocument('Barcode', '

MEDICORE LAB

Sample Barcode

' + code + '
' + code + '
', '.bar{display:inline-block;border:1px solid #111;padding:12px;width:260px;font-family:monospace;font-size:38px;letter-spacing:2px;margin:8px 0}'); } catch(e) { alert('Barcode failed: ' + (e && e.message ? e.message : e)); } } async function qr(){ try { var r = await fetch('/api/enterprise/verify-report', { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({reportType:'result'}) }); var d = await r.json(); var code = esc(d.verificationCode || ''); var url = esc(location.origin + (d.verifyUrl || '')); openPrintDocument('Verification QR', '

Report Verification

' + code + '
' + url + '
', '.qr{width:160px;height:160px;margin:20px auto;background:repeating-linear-gradient(45deg,#000 0 6px,#fff 6px 12px);border:8px solid #fff;box-shadow:0 0 0 1px #111}.url{font-size:12px;word-break:break-all;margin-top:10px}'); } catch(e) { alert('QR failed: ' + (e && e.message ? e.message : e)); } } async function bmi(){ var h = prompt('Height in cm?'); var w = prompt('Weight in kg?'); if (!h || !w) return; try { var r = await fetch('/api/enterprise/medical-calculators', { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({type:'bmi', heightCm:h, weightKg:w}) }); var d = await r.json(); alert('BMI = ' + (d.result && d.result.bmi ? d.result.bmi : 'โ€”')); } catch(e) { alert('BMI failed: ' + (e && e.message ? e.message : e)); } } async function ai(){ var v = prompt('Result value?'); if (!v) return; var low = prompt('Low range?'); var high = prompt('High range?'); try { var r = await fetch('/api/enterprise/ai-assistant', { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({value:v, low:low, high:high}) }); var d = await r.json(); alert('Flag: ' + (d.flag || '') + '\n' + (d.interpretation || '')); } catch(e) { alert('AI helper failed: ' + (e && e.message ? e.message : e)); } } window.__M27__ = Object.assign(window.__M27__ || {}, { barcode:barcode, qr:qr, bmi:bmi, ai:ai, openPrintDocument:openPrintDocument }); })();