javascript:%2F* Physician Sign Out Vitals %2F I-O reset. Test ONLY on dummy records.%0A Browser bookmarklet%3B no network calls or PHI export. *%2F%0A(async () %3D> %7B%0A 'use strict'%3B%0A const APP %3D 'PSO Vital %2B I%2FO Clear by Joel'%3B%0A if (!%2F%5E(www%5C.)%3Fphysiciansignout%5C.com%24%2F.test(location.hostname) %7C%7C location.pathname !%3D%3D '%2Fpatients') %7B%0A alert(APP %2B '%3A Open the Physician Sign Out Patients page.')%3B return%3B%0A %7D%0A if (window.__psoVitalsIORunning) %7B alert(APP %2B ' is already running.')%3B return%3B %7D%0A const sleep %3D ms %3D> new Promise(r %3D> setTimeout(r%2C ms))%3B%0A const visible %3D el %3D> !!(el %26%26 el.isConnected %26%26 el.getClientRects().length %26%26 getComputedStyle(el).visibility !%3D%3D 'hidden' %26%26 getComputedStyle(el).display !%3D%3D 'none')%3B%0A const norm %3D el %3D> (el%3F.textContent %7C%7C '').replace(%2F%5Cs%2B%2Fg%2C ' ').trim()%3B%0A const wait %3D async (get%2C description%2C timeout %3D 10000) %3D> %7B const start %3D Date.now()%3B while (Date.now()-start < timeout) %7B const found%3Dget()%3B if(found) return found%3B await sleep(150)%3B %7D throw Error('Timed out%3A ' %2B description)%3B %7D%3B%0A const click %3D (el%2C desc) %3D> %7B if(!visible(el)) throw Error('Missing or hidden%3A ' %2B desc)%3B el.click()%3B %7D%3B%0A const dialogs %3D () %3D> %5B...document.querySelectorAll('.mbsc-fr')%5D.filter(visible)%3B%0A const action %3D (root%2Clabel) %3D> %7B%0A const options%3D%5B...root.querySelectorAll('a%2Cbutton%2C%5Brole%3D"button"%5D%2C.mbsc-fr-btn-s > div')%5D.filter(x%3D>visible(x)%26%26norm(x)%3D%3D%3Dlabel)%3B%0A return options.find(x%3D>!%5B...x.children%5D.some(y%3D>visible(y)%26%26norm(y)%3D%3D%3Dlabel))%7C%7Coptions.at(-1)%7C%7Cnull%3B%0A %7D%3B%0A const editor %3D () %3D> dialogs().reverse().find(d %3D> action(d%2C'Save'))%3B%0A const roots%3D%5B...document.querySelectorAll('%5Bid%5E%3D"p_h_d_"%5D')%5D%3B%0A const openPanels%3Droots.filter(visible)%3B%0A const fieldsSelector%3D'input%3Anot(%5Btype%3D"hidden"%5D)%3Anot(%5Btype%3D"checkbox"%5D)%3Anot(%5Btype%3D"radio"%5D)%3Anot(%5Btype%3D"submit"%5D)%3Anot(%5Btype%3D"button"%5D)%2C textarea%2C %5Bcontenteditable%3D"true"%5D'%3B%0A const editable %3D e %3D> visible(e) %26%26 !e.disabled %26%26 !e.readOnly%3B%0A const values %3D el %3D> %5B...el.querySelectorAll(fieldsSelector)%5D.filter(editable)%3B%0A const suffix%3Del%3D>el.id.replace(%2F%5Ep_h_d_%2F%2C '')%3B%0A function nameFor(panel) %7B%0A %2F%2F Read the patient identity from the labelled INFO field%2C not from the%0A %2F%2F first comma-containing link (which may be a diagnosis or problem).%0A const clean %3D s %3D> (s %7C%7C '').replace(%2F%5Cs%2B%2Fg%2C ' ').trim()%3B%0A const valid %3D s %3D> %7B%0A const v %3D clean(s)%3B%0A return v.length >%3D 3 %26%26 v.length <%3D 100 %26%26%0A !%2F%5E(%3F%3Aname%7Cinfo%7Cnotes%7Cvitals%7Clabs%7Cmeds%7Ctasks%7Cbilling%7Cimages)%5Cb%2Fi.test(v) %26%26%0A !%2F%5Cb(%3F%3Adiagnosis%7Cappendicitis%7Cabd pain)%5Cb%2Fi.test(v) %26%26%0A !%2F%5B%5Cr%5Cn%5D%2F.test(v)%3B%0A %7D%3B%0A const parse %3D s %3D> %7B%0A const v %3D clean(s)%3B%0A const m %3D v.match(%2F%5EName%5Cs*%3A%5Cs*(.%2B)%24%2Fi)%3B%0A return m %26%26 valid(m%5B1%5D) %3F m%5B1%5D %3A null%3B%0A %7D%3B%0A %2F%2F The patient details panel has a Name%3A label followed by its value.%0A const nodes %3D %5B...panel.querySelectorAll('label%2Cspan%2Cdiv%2Ctd%2Cth%2Cstrong%2Cb%2Cp')%5D%0A .filter(el %3D> visible(el) %26%26 el.children.length <%3D 2)%3B%0A for (const node of nodes) %7B%0A const direct %3D parse(node.textContent)%3B%0A if (direct) return direct%3B%0A if (!%2F%5EName%5Cs*%3A%3F%24%2Fi.test(clean(node.textContent))) continue%3B%0A const holders %3D %5Bnode%2C node.parentElement%5D.filter(Boolean)%3B%0A for (const holder of holders) %7B%0A let sibling %3D holder.nextElementSibling%3B%0A for (let tries%3D0%3B sibling %26%26 tries<2%3B tries%2B%2B%2Csibling%3Dsibling.nextElementSibling) %7B%0A if (!visible(sibling)) continue%3B%0A const link %3D sibling.matches('a') %3F sibling %3A sibling.querySelector('a')%3B%0A const text %3D clean(link%3F.textContent %7C%7C sibling.textContent)%3B%0A if (valid(text) %26%26 !%2F%5E(%3F%3Aprovider%7Cmrn%7Croom%7Cdate of birth%7Csex%7Cpriority)%5Cs*%3A%2Fi.test(text)) return text%3B%0A %7D%0A %7D%0A %2F%2F Support a label%2Fvalue in the same wrapper%2C with a labelled child.%0A const wrapper %3D node.parentElement%3B%0A if (wrapper) %7B%0A const valueNode %3D %5B...wrapper.children%5D.find(e %3D> e !%3D%3D node %26%26 visible(e))%3B%0A if (valueNode %26%26 valid(valueNode.textContent)) return clean(valueNode.textContent)%3B%0A %7D%0A %7D%0A %2F%2F Fail closed%3A do not substitute arbitrary comma-separated link text.%0A return null%3B%0A %7D%0A function findColumn(panel%2C kind) %7B%0A %2F%2F Resolve the actual visible header%2C not an nth-child position.%0A const canonical %3D s %3D> s.toUpperCase().replace(%2F%5Cs%2B%2Fg%2C'').replace(%2F%5C%2F%2Fg%2C'')%3B%0A const target %3D kind %3D%3D%3D 'Vitals' %3F 'VITALS' %3A 'IOS'%3B%0A const headings %3D %5B...panel.querySelectorAll('div%2Cspan%2Cth%2Ctd%2Ch2%2Ch3%2Ch4')%5D%0A .filter(e %3D> visible(e) %26%26 canonical(norm(e)) %3D%3D%3D target %26%26%0A !%5B...e.children%5D.some(c %3D> visible(c) %26%26 canonical(norm(c)) %3D%3D%3D target))%3B%0A if (headings.length !%3D%3D 1) throw Error(kind%2B'%3A expected one visible column heading%2C found '%2Bheadings.length)%3B%0A const header %3D headings%5B0%5D%3B%0A const hr %3D header.getBoundingClientRect()%3B%0A const center %3D hr.left %2B hr.width%2F2%3B%0A %2F%2F Search only the structural row containing the existing edit icons.%0A const row %3D panel.querySelector('%3Ascope > div%3Afirst-child > div > div%3Anth-child(3)')%3B%0A if (!row) throw Error('Could not locate patient content row')%3B%0A const cols %3D %5B...row.children%5D.filter(e %3D> visible(e))%3B%0A const scored %3D cols.map(col %3D> %7B%0A const r %3D col.getBoundingClientRect()%3B%0A return %7Bcol%2C distance%3AMath.abs((r.left%2Br.width%2F2)-center)%2Cr%7D%3B%0A %7D).filter(v%3D>v.r.left <%3D center%2B8 %26%26 v.r.right >%3D center-8)%3B%0A if (scored.length !%3D%3D 1) throw Error(kind%2B'%3A column geometry ambiguous ('%2Bscored.length%2B' matches)')%3B%0A const col %3D scored%5B0%5D.col%3B%0A const images %3D %5B...col.querySelectorAll('img')%5D.filter(visible)%3B%0A %2F%2F Recorder shows a single edit image as a direct child of this column.%0A const direct %3D %5B...col.children%5D.filter(e%3D>e.tagName%3D%3D%3D'IMG' %26%26 visible(e))%3B%0A const candidates %3D direct.length %3F direct %3A images.filter(e%3D>%2Fedit%7Cpencil%2Fi.test(%5Be.alt%2Ce.title%2Ce.getAttribute('src')%5D.join(' ')))%3B%0A if (candidates.length !%3D%3D 1) throw Error(kind%2B'%3A cannot uniquely identify its edit icon ('%2Bcandidates.length%2B' matches)')%3B%0A return candidates%5B0%5D%3B%0A %7D%0A function requireEditorTitle(dlg%2Ckind) %7B%0A const target %3D kind %3D%3D%3D 'Vitals' %3F 'VITALS' %3A 'IOS'%3B%0A const canonical %3D s %3D> s.toUpperCase().replace(%2F%5Cs%2B%2Fg%2C'').replace(%2F%5C%2F%2Fg%2C'')%3B%0A const titleNodes %3D %5B...dlg.querySelectorAll('.mbsc-fr-hdr%2C.mbsc-fr-title%2C.mbsc-fr-c%2C.mbsc-fr-w h3%2C.mbsc-fr-w h4')%5D%0A .filter(visible)%3B%0A const title %3D titleNodes.find(e %3D> canonical(norm(e)) %3D%3D%3D target %26%26%0A !%5B...e.children%5D.some(c%3D>canonical(norm(c))%3D%3D%3Dtarget))%3B%0A if (!title) %7B%0A const matches %3D %5B...dlg.querySelectorAll('div%2Cspan%2Ch1%2Ch2%2Ch3%2Ch4')%5D%0A .filter(e%3D>visible(e)%26%26canonical(norm(e))%3D%3D%3Dtarget %26%26 !%5B...e.children%5D.some(c%3D>canonical(norm(c))%3D%3D%3Dtarget))%3B%0A if(matches.length!%3D%3D1) throw Error(kind%2B'%3A editor title cannot be verified%3B no values changed')%3B%0A %7D%0A %7D%0A if (dialogs().length) %7B alert(APP%2B'%3A Close any existing edit popup first%2C then click the bookmark again. Nothing changed.')%3B return%3B %7D%0A const plans%3DopenPanels.map((panel%2Cindex)%3D>(%7Bid%3Apanel.id%2Cname%3AnameFor(panel)%2Cindex%3Aindex%2B1%7D))%3B%0A if(!plans.length) %7Balert(APP%2B'%3A No expanded patient panels. No changes made.')%3Breturn%3B%7D%0A if(plans.some(p%3D>!p.name)) %7Balert(APP%2B'%3A Could not locate the Name%3A value in every expanded patient card. No changes made. Please provide a redacted screenshot of the INFO Name field if this persists.')%3Breturn%3B%7D%0A try %7B for(const p of plans)%7B const panel%3Ddocument.getElementById(p.id)%3B findColumn(panel%2C'Vitals')%3B findColumn(panel%2C'I%2FO')%3B %7D%7D catch(e)%7Balert(APP%2B'%3A '%2Be.message%2B'%5CnNothing changed.')%3Breturn%3B%7D%0A const selectedNames%3Dplans.map(p%3D>%60%24%7Bp.index%7D. %24%7Bp.name%7D%60).join('%5Cn')%3B%0A if(!confirm(%60%24%7BAPP%7D%5Cn%5CnEXPANDED PATIENTS TO CHANGE%3A%5Cn%24%7BselectedNames%7D%5Cn%5CnExisting values may not be recoverable. Run only with authorization%3B verify after saving. Proceed%3F%60))return%3B%0A window.__psoVitalsIORunning%3Dtrue%3B%0A const summary%3D%7Bcompleted%3A0%2Cvit%3A0%2Cio%3A0%7D%3B%0A let current%3D'none'%2Cstage%3D''%3B%0A const changeValue%3D(field%2Cvalue)%3D>%7B%0A if(field.isContentEditable)%7Bfield.textContent%3Dvalue%3Bfield.dispatchEvent(new InputEvent('input'%2C%7Bbubbles%3Atrue%2CinputType%3A'deleteContentBackward'%7D))%3B%7D%0A else %7B const setter%3DObject.getOwnPropertyDescriptor(field.tagName%3D%3D%3D'TEXTAREA'%3FHTMLTextAreaElement.prototype%3AHTMLInputElement.prototype%2C'value')%3F.set%3B if(setter)setter.call(field%2Cvalue)%3Belse field.value%3Dvalue%3B field.dispatchEvent(new Event('input'%2C%7Bbubbles%3Atrue%7D))%3Bfield.dispatchEvent(new Event('change'%2C%7Bbubbles%3Atrue%7D))%3B %7D%0A %7D%3B%0A try %7B%0A for (const p of plans) %7B%0A current%3Dp.name%3B%0A for (const %5Bkind%2Ctotal%2CclearCount%5D of %5B%5B'Vitals'%2C6%2C5%5D%2C%5B'I%2FO'%2C5%2C4%5D%5D) %7B%0A stage%3D%60opening %24%7Bkind%7D%60%3B%0A const panel%3Ddocument.getElementById(p.id)%3B%0A if(!visible(panel))throw Error('Patient card was collapsed during operation')%3B%0A click(findColumn(panel%2Ckind)%2Ckind%2B' edit icon')%3B%0A stage%3D%60checking %24%7Bkind%7D editor%60%3B%0A const dlg%3Dawait wait(editor%2Ckind%2B' Save dialog')%3B%0A requireEditorTitle(dlg%2Ckind)%3B%0A let fields%3Dvalues(dlg)%3B%0A %2F%2F Never guess if the actual form does not match the expected 6 Vitals %2F 5 I%2FO fields.%0A if(fields.length!%3D%3Dtotal)throw Error(%60%24%7Bkind%7D editor has %24%7Bfields.length%7D editable fields%2C expected %24%7Btotal%7D. No values changed in this editor. Close it with Cancel%2C then report this count.%60)%3B%0A if(fields.some(e%3D>!e.matches('input%2Ctextarea'))) throw Error('Unsupported rich-text field%3B stopped')%3B%0A const preserved%3Dfields.slice(clearCount).map(e%3D>e.value)%3B%0A stage%3D%60clearing %24%7Bkind%7D%60%3B%0A for(const field of fields.slice(0%2CclearCount)) changeValue(field%2C'')%3B%0A if(fields.slice(0%2CclearCount).some(e%3D>e.value!%3D%3D'')) throw Error(%60%24%7Bkind%7D%3A field did not clear%60)%3B%0A if(fields.slice(clearCount).some((e%2Ci)%3D>e.value!%3D%3Dpreserved%5Bi%5D)) throw Error(%60%24%7Bkind%7D%3A protected final field changed%3B stopped without saving%60)%3B%0A stage%3D%60saving %24%7Bkind%7D%60%3B%0A click(action(dlg%2C'Save')%2Ckind%2B' Save')%3B%0A await wait(()%3D>!visible(dlg)%2Ckind%2B' dialog to close')%3B%0A if(kind%3D%3D%3D'Vitals') summary.vit%2B%2B%3B else summary.io%2B%2B%3B%0A %7D%0A summary.completed%2B%2B%3B%0A %7D%0A alert(%60FINISHED%5Cn%5CnPatients changed%3A%5Cn%24%7Bplans.slice(0%2Csummary.completed).map(p%3D>p.name).join('%5Cn')%7D%5Cn%5CnVERIFY values in each patient%3A saving was detected%2C but server persistence must be checked manually.%60)%3B%0A %7D catch(e) %7B%0A console.error(APP%2C%7Bcurrent%2Cstage%2Cerror%3Ae%7D)%3B%0A alert(%60%24%7BAPP%7D — STOPPED%5Cn%5CnPatient%3A %24%7Bcurrent%7D%5CnStep%3A %24%7Bstage%7D%5CnReason%3A %24%7Be.message%7D%5Cn%5CnCompleted patients%3A %24%7Bsummary.completed%7D%5CnVitals saved%3A %24%7Bsummary.vit%7D%5CnI%2FO saved%3A %24%7Bsummary.io%7D%5Cn%5CnPartial changes possible. Review all affected patient records before retrying.%60)%3B%0A %7D finally %7Bwindow.__psoVitalsIORunning%3Dfalse%3B%7D%0A%7D)()%3B%0A
javascript:%2F* Physician Sign Out LAB Reset — TEST WITH SYNTHETIC PATIENTS ONLY.%0A Deletes ALL detected existing LAB records on expanded patient cards%2C then%0A restores blank templates of the same types and counts as those deleted.%0A Destructive%3B back up data and validate in a test environment first.%0A Uses site UI only%3B no network exports.%0A*%2F%0A(async () %3D> %7B%0A 'use strict'%3B%0A const APP %3D 'Clear Labs by Joel'%3B%0A const SUPPORTED %3D %5B'ABG'%2C 'BMP'%2C 'Coagulation'%2C 'CBC'%2C 'Liver'%2C 'Renal'%2C 'ICU'%5D%3B%0A const ALIASES %3D %7B%0A 'arterial blood gas'%3A'ABG'%2C 'basic metabolic panel'%3A'BMP'%2C%0A 'complete blood count'%3A'CBC'%2C 'lft'%3A'Liver'%2C 'lfts'%3A'Liver'%2C%0A 'coags'%3A'Coagulation'%0A %7D%3B%0A const normalize %3D label %3D> %7B%0A const key %3D String(label %7C%7C '').replace(%2F%5Cs%2B%2Fg%2C ' ').trim().toLowerCase()%3B%0A return ALIASES%5Bkey%5D %7C%7C SUPPORTED.find(name %3D> name.toLowerCase() %3D%3D%3D key) %7C%7C null%3B%0A %7D%3B%0A if (!%2F(%5E%7C%5C.)physiciansignout%5C.com%24%2Fi.test(location.hostname) %7C%7C location.pathname !%3D%3D '%2Fpatients') %7B%0A alert(APP %2B '%3A Open the patients page first.')%3B return%3B%0A %7D%0A if (window.__psoLabResetRunning) %7B alert(APP %2B '%3A Already running.')%3B return%3B %7D%0A const sleep %3D ms %3D> new Promise(r %3D> setTimeout(r%2C ms))%3B%0A const txt %3D e %3D> (e%3F.textContent %7C%7C '').replace(%2F%5Cs%2B%2Fg%2C ' ').trim()%3B%0A const visible %3D e %3D> !!(e%3F.isConnected %26%26 e.getClientRects().length %26%26 getComputedStyle(e).display !%3D%3D 'none' %26%26 getComputedStyle(e).visibility !%3D%3D 'hidden')%3B%0A const wait %3D async (fn%2C label%2C ms %3D 10000) %3D> %7B%0A const start %3D Date.now()%3B%0A while (Date.now() - start < ms) %7B const result %3D fn()%3B if (result) return result%3B await sleep(150)%3B %7D%0A throw Error('Timed out waiting for ' %2B label)%3B%0A %7D%3B%0A const press %3D (node%2C label) %3D> %7B if (!visible(node)) throw Error('Missing or invisible ' %2B label)%3B node.click()%3B %7D%3B%0A const centerX %3D el %3D> %7B const r %3D el.getBoundingClientRect()%3B return r.left %2B r.width %2F 2%3B %7D%3B%0A const dialogs %3D () %3D> %5B...document.querySelectorAll('.mbsc-fr')%5D.filter(visible)%3B%0A const action %3D (dialog%2C name) %3D> %7B%0A if (!dialog) return null%3B%0A const options %3D %5B...dialog.querySelectorAll('a%2Cbutton%2C%5Brole%3D"button"%5D%2C.mbsc-fr-btn-s > div')%5D%0A .filter(e %3D> visible(e) %26%26 txt(e).toLowerCase() %3D%3D%3D name.toLowerCase())%3B%0A return options.find(e %3D> !%5B...e.children%5D.some(c %3D> visible(c) %26%26 txt(c).toLowerCase() %3D%3D%3D name.toLowerCase())) %7C%7C options.at(-1) %7C%7C null%3B%0A %7D%3B%0A const dialogWith %3D name %3D> dialogs().reverse().find(d %3D> action(d%2Cname))%3B%0A const panels %3D %5B...new Map(%5B...document.querySelectorAll('%5Bid%5E%3D"p_h_d_"%5D')%5D%0A .filter(visible).map(p %3D> %5Bp.id%2Cp%5D)).values()%5D%3B%0A if (!panels.length) %7B alert(APP %2B '%3A No expanded patient cards detected.')%3B return%3B %7D%0A const labelOf %3D p %3D> %7B%0A const label %3D %5B...p.querySelectorAll('*')%5D.find(e %3D> visible(e) %26%26 e.children.length %3D%3D%3D 0 %26%26 txt(e) %3D%3D%3D 'Name%3A')%3B%0A return txt(label%3F.nextElementSibling) %7C%7C p.id%3B%0A %7D%3B%0A function labBounds(panel) %7B%0A %2F%2F Locate header by its actual text%3B no fixed nth-child and no assumed screen x.%0A const leaves %3D %5B...panel.querySelectorAll('*')%5D.filter(e %3D> visible(e) %26%26%0A %5B'LAB'%2C'LABS'%2C'VITALS'%2C'I%2FOS'%2C'I%2FO'%2C'MEDS'%2C'INFO'%5D.includes(txt(e).toUpperCase()) %26%26%0A !%5B...e.children%5D.some(c %3D> txt(c) %3D%3D%3D txt(e)))%3B%0A const header %3D leaves.find(e %3D> %5B'LAB'%2C'LABS'%5D.includes(txt(e).toUpperCase()))%3B%0A if (!header) throw Error(labelOf(panel) %2B '%3A LAB header not found')%3B%0A const hx %3D centerX(header)%3B%0A const neighbors %3D leaves.filter(e %3D> e !%3D%3D header)%3B%0A const left %3D neighbors.filter(e %3D> centerX(e) < hx).sort((a%2Cb) %3D> centerX(b)-centerX(a))%5B0%5D%3B%0A const right %3D neighbors.filter(e %3D> centerX(e) > hx).sort((a%2Cb) %3D> centerX(a)-centerX(b))%5B0%5D%3B%0A if (!left %7C%7C !right) throw Error(labelOf(panel) %2B '%3A cannot safely determine LAB boundaries')%3B%0A return %7Bleft%3A(centerX(left)%2Bhx)%2F2%2C right%3A(centerX(right)%2Bhx)%2F2%2C top%3Aheader.getBoundingClientRect().bottom%7D%3B%0A %7D%0A const inLab %3D (el%2C b) %3D> visible(el) %26%26 centerX(el) > b.left %26%26 centerX(el) < b.right %26%26 el.getBoundingClientRect().top >%3D b.top - 2%3B%0A function findRows(panel) %7B%0A const b %3D labBounds(panel)%3B%0A %2F%2F Site lab row identifier%2C checked against dynamic column geometry.%0A const rows %3D %5B...panel.querySelectorAll('%5Bid%5E%3D"la_i_"%5D')%5D.filter(r %3D> visible(r) %26%26 %5B...r.querySelectorAll('a')%5D.some(a %3D> inLab(a%2Cb)))%3B%0A const result %3D rows.map(row %3D> %7B%0A const link %3D %5B...row.querySelectorAll('a')%5D.find(a %3D> visible(a) %26%26 txt(a))%3B%0A if (!link) throw Error(labelOf(panel) %2B '%3A lab row ' %2B row.id %2B ' has no usable label')%3B%0A return %7Bid%3Arow.id%2C name%3Atxt(link)%2C link%7D%3B%0A %7D)%3B%0A if (new Set(result.map(r %3D> r.id)).size !%3D%3D result.length) throw Error('Duplicate lab row IDs detected')%3B%0A return result%3B%0A %7D%0A function addButton(panel) %7B%0A const b %3D labBounds(panel)%3B%0A const imgs %3D %5B...panel.querySelectorAll('img')%5D.filter(img %3D> inLab(img%2Cb))%3B%0A const matches %3D imgs.filter(img %3D> %2Fadd%7Cplus%7Cnew%7Cinsert%2Fi.test(%5Bimg.src%2Cimg.alt%2Cimg.title%5D.join(' ')))%3B%0A const candidates %3D matches.length %3F matches %3A imgs.filter(img %3D> img.getBoundingClientRect().top > b.top %2B 100)%3B%0A if (candidates.length !%3D%3D 1) throw Error(labelOf(panel) %2B '%3A LAB plus icon ambiguous (' %2B candidates.length %2B ')')%3B%0A return candidates%5B0%5D%3B%0A %7D%0A let plan%3B%0A try %7B%0A plan %3D panels.map(p %3D> %7B%0A const b %3D labBounds(p)%3B%0A const rows %3D findRows(p)%3B%0A addButton(p)%3B%0A const recognized %3D rows.filter(r %3D> normalize(r.name))%3B%0A const skipped %3D rows.filter(r %3D> !normalize(r.name))%3B%0A return %7Bid%3Ap.id%2C label%3AlabelOf(p)%2C rows%2C recognized%2C skipped%2C restore%3Arecognized.map(r%3D>normalize(r.name))%7D%3B%0A %7D)%3B%0A %7D catch (e) %7B alert(APP %2B ' — NO CHANGES%5Cn%5Cn' %2B e.message)%3B return%3B %7D%0A const total %3D plan.reduce((n%2Cp) %3D> n%2Bp.recognized.length%2C0)%3B%0A const untouched %3D plan.reduce((n%2Cp) %3D> n%2Bp.skipped.length%2C0)%3B%0A const patientList %3D plan.map((p%2Ci) %3D> %60%24%7Bi%2B1%7D. %24%7Bp.label%7D%3A %24%7Bp.recognized.length%7D to clear %5B%24%7Bp.recognized.map(r%3D>r.name).join('%2C ')%7C%7C'none'%7D%5D%60 %2B (p.skipped.length %3F %60%3B KEEP %24%7Bp.skipped.length%7D %5B%24%7Bp.skipped.map(r%3D>r.name).join('%2C ')%7D%5D%60 %3A '')).join('%5Cn')%3B%0A if (!total) %7B alert(APP %2B ' — NO CHANGES%5Cn%5CnNo recognized template records to reset. Unknown labels were left untouched.')%3B return%3B %7D%0A const ok %3D confirm(%60%24%7BAPP%7D%5Cn%5CnExisting values may not be recoverable. Test only with synthetic records in an authorized environment.%5Cn%5CnPATIENTS TO CHANGE%3A%5Cn%24%7BpatientList%7D%5Cn%5CnTotal labs found to clear%3A %24%7Btotal%7D%5CnUnknown Labs%3A %24%7Buntouched%7D%5Cn%5CnOnly recognized labs are deleted and recreated. Any unrecognized labs will be left unchanged. Proceed%3F%60)%3B%0A if (!ok) return%3B%0A window.__psoLabResetRunning %3D true%3B%0A let current %3D ''%2C phase %3D ''%2C deleted %3D 0%2C added %3D 0%3B%0A const finished %3D %5B%5D%3B%0A try %7B%0A for (const entry of plan) %7B%0A const panel %3D () %3D> document.getElementById(entry.id)%3B%0A current %3D entry.label%3B%0A %2F%2F Fail if rows have changed after preflight%3B avoids deleting newly added labs.%0A const now %3D findRows(panel())%3B%0A if (now.length !%3D%3D entry.rows.length %7C%7C now.some((r%2Ci)%3D>r.id!%3D%3Dentry.rows%5Bi%5D.id %7C%7C r.name!%3D%3Dentry.rows%5Bi%5D.name))%0A throw Error('Lab list changed since preview%3B stopped to prevent deleting unexpected records')%3B%0A for (const row of entry.recognized) %7B%0A phase %3D 'opening ' %2B row.name%3B%0A const live %3D findRows(panel()).find(r%3D>r.id%3D%3D%3Drow.id)%3B%0A if (!live %7C%7C live.name!%3D%3Drow.name) throw Error('Lab entry changed during run')%3B%0A if (dialogs().length) throw Error('Unexpected popup open before lab deletion')%3B%0A press(live.link%2C row.name)%3B%0A const menu %3D await wait(()%3D>dialogWith('Delete')%2C'Delete menu for '%2Brow.name)%3B%0A phase %3D 'requesting delete of ' %2B row.name%3B%0A press(action(menu%2C'Delete')%2C'Delete')%3B%0A const confirmDialog %3D await wait(()%3D>dialogWith('Yes')%2C'confirmation for '%2Brow.name)%3B%0A phase %3D 'confirming delete of ' %2B row.name%3B%0A press(action(confirmDialog%2C'Yes')%2C'Yes')%3B%0A await wait(()%3D>!findRows(panel()).some(r%3D>r.id%3D%3D%3Drow.id)%2C'removal of '%2Brow.name)%3B%0A deleted%2B%2B%3B%0A await wait(()%3D>dialogs().length%3D%3D%3D0%2C'close of deletion popup')%3B%0A %7D%0A if (findRows(panel()).length !%3D%3D entry.skipped.length %7C%7C !entry.skipped.every(old%3D>findRows(panel()).some(r%3D>r.id%3D%3D%3Dold.id %26%26 r.name%3D%3D%3Dold.name))) throw Error('Unexpected lab list after deletion%3B protected entries may have changed')%3B%0A let addedForPatient %3D 0%3B%0A for (const type of entry.restore) %7B%0A phase %3D 'opening LAB add menu for '%2Btype%3B%0A press(addButton(panel())%2C'LAB add button')%3B%0A const chooser %3D await wait(()%3D>dialogs().at(-1)%2C'LAB chooser')%3B%0A if (%2FNew Medication%2Fi.test(txt(chooser)) %7C%7C !SUPPORTED.every(n%3D>action(chooser%2Cn)))%0A throw Error('Unexpected chooser%3B looks unlike LAB options')%3B%0A const desired %3D action(chooser%2Ctype)%3B%0A if (!desired) throw Error(type %2B ' missing from LAB options')%3B%0A phase %3D 'selecting '%2Btype%3B%0A press(desired%2Ctype)%3B%0A const editor %3D await wait(()%3D>dialogWith('Save')%2C'editor for '%2Btype)%3B%0A const filled %3D %5B...editor.querySelectorAll('input%2Ctextarea%2Cselect')%5D.filter(e%3D>visible(e)%26%26%0A !%5B'hidden'%2C'checkbox'%2C'radio'%2C'button'%2C'submit'%5D.includes(e.type) %26%26 String(e.value%7C%7C'').trim())%3B%0A if (filled.length) throw Error('New '%2Btype%2B' editor has populated inputs%3B not saving')%3B%0A phase %3D 'saving '%2Btype%3B%0A press(action(editor%2C'Save')%2C'Save')%3B%0A const expectedTypeCount %3D entry.restore.slice(0%2CaddedForPatient%2B1).filter(n%3D>n%3D%3D%3Dtype).length%3B%0A await wait(()%3D>findRows(panel()).filter(r%3D>normalize(r.name)%3D%3D%3Dtype).length>%3DexpectedTypeCount%2C'new '%2Btype%2B' row')%3B%0A added%2B%2B%3B addedForPatient%2B%2B%3B%0A await wait(()%3D>dialogs().length%3D%3D%3D0%2C'close of add popup')%3B%0A %7D%0A const end %3D findRows(panel())%3B%0A const expectedCounts %3D new Map()%3B%0A for (const type of entry.restore) expectedCounts.set(type%2C(expectedCounts.get(type)%7C%7C0)%2B1)%3B%0A const actualCounts %3D new Map()%3B%0A for (const row of end) if (normalize(row.name)) actualCounts.set(normalize(row.name)%2C(actualCounts.get(normalize(row.name))%7C%7C0)%2B1)%3B%0A const skippedStillThere %3D entry.skipped.every(old%3D>end.some(r%3D>r.id%3D%3D%3Dold.id %26%26 r.name%3D%3D%3Dold.name))%3B%0A if (!skippedStillThere %7C%7C end.length !%3D%3D entry.rows.length %7C%7C %5B...expectedCounts%5D.some((%5Btype%2Ccount%5D)%3D>actualCounts.get(type)!%3D%3Dcount))%0A throw Error('Final LAB entries did not match the original template type%2Fcount inventory')%3B%0A finished.push(entry.label)%3B%0A %7D%0A alert(%60%24%7BAPP%7D%5Cn%5CnFINISHED%5Cn%5CnPatients changed%3A%5Cn%24%7Bfinished.map((name%2Ci)%3D>%60%24%7Bi%2B1%7D. %24%7Bname%7D%60).join('%5Cn')%7D%5Cn%5CnLabs detected to clear%3A %24%7Btotal%7D%5CnLabs preserved (unsupported)%3A %24%7Buntouched%7D%5CnLabs deleted%3A %24%7Bdeleted%7D%5CnBlank templates added%3A %24%7Badded%7D%5Cn%5CnVERIFY values in each patient%3A saving was detected%2C but server persistence must be checked manually.%60)%3B%0A %7D catch (err) %7B%0A console.error(APP%2C%7Bcurrent%2Cphase%2Cdeleted%2Cadded%2Cerror%3Aerr%7D)%3B%0A alert(%60%24%7BAPP%7D — STOPPED%3B PARTIAL CHANGES POSSIBLE%5Cn%5CnPatient%3A %24%7Bcurrent%7D%5CnStep%3A %24%7Bphase%7D%5CnError%3A %24%7Berr.message%7D%5Cn%5CnLab records deleted%3A %24%7Bdeleted%7D%2F%24%7Btotal%7D%5CnBlank panels added%3A %24%7Badded%7D%2F%24%7Btotal%7D%5CnPatients fully completed%3A %24%7Bfinished.length%7D%2F%24%7Bplan.length%7D%5Cn%5CnInspect affected patient records before rerunning.%60)%3B%0A %7D finally %7B window.__psoLabResetRunning %3D false%3B %7D%0A%7D)()%3B%0A