Test TM

Test

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         Test TM
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  Test
// @match        *://*/*
// @grant        none

// ==/UserScript==

(function() {
    'use strict';
window.addEventListener('load', function() {




function getClientNumber() {
    console.log('window.parent.parent.frames.length:', window.parent.parent.frames.length);

        // Pak de derde frame (index 2) uit het frameset
        const mainframe = window.parent.parent.frames[2]; // of window.frames['mainframe']

        if (!mainframe) {
            console.error('Mainframe (derde frame) niet gevonden');
            return null;
        }

        // Pak het document uit de frame
        const frameDoc = mainframe.document;

        if (!frameDoc) {
            console.error('Kan niet bij frame document');
            return null;
        }

        console.log('Frame document gevonden');
        const container = frameDoc.getElementById('tab_contents3');
        console.log(container);

    if (!container) return null;

    // Zoek de tweede <tr> binnen de container
    const rows = container.querySelectorAll('table tbody tr');
    if (rows.length >= 2) {
        const secondRow = rows[1];
        const lastCell = secondRow.lastElementChild;

        if (lastCell) {
            const text = (lastCell.textContent || lastCell.innerText).trim();
            const numberMatch = text.match(/\d+/);
            if (numberMatch) {
                return numberMatch[0];
            }
        }
    }

    return null;
}

    const clientNumber = getClientNumber();

    if (clientNumber === null){
        console.log("kan clientnummer niet vinden");
    } else {
        console.log("haal data op")

        fetch("https://whisper.anzwerz.ai/api/get_treatment_data/", {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'X-API-Key': 'mijn-geheime-sleutel'
            },
            body: JSON.stringify({ patientnummer: String(clientNumber) })
        })
        .then(response => response.json())
        .then(data => {
            console.log('Snowflake resultaat:', data);
            const subjectief = data.response.subjectief;
            const objectief = data.response.objectief;
            const evaluatie = data.response.evaluatie;
            const plan = data.response.plan;
            const opmerkingen = data.response.opmerkingen;
            const afwijking = data.response.afwijking;

            console.log(evaluatie);


            const subjectiefeEl = document.getElementById('Subjectief');

            if (subjectiefeEl && subjectiefeEl.innerHTML == '' ){

                if (subjectiefeEl && subjectief) {
                    subjectiefeEl.innerHTML = subjectief;
                }


                const objectiefeEl = document.getElementById('Objectief');
                if (objectiefeEl && objectief) {
                    objectiefeEl.innerHTML = objectief;
                }

                const evaluatieEl = document.getElementById('Evaluatie');
                if (evaluatieEl && evaluatie) {
                    evaluatieEl.innerHTML = evaluatie;
                }

                const planEl = document.getElementById('PlanVanAanpak');
                if (planEl && plan) {
                    planEl.innerHTML = plan;
                }

                const opmerkingenEl = document.getElementById('Opmerkingen');
                if (opmerkingenEl && opmerkingen) {
                    opmerkingenEl.innerHTML = opmerkingen;
                }

                if (afwijking && afwijking !== ''){
                    const afwijkingEl = document.getElementById('afwijking');
                    afwijkingEl.checked = true;

                    const afwijkingomsEl = document.getElementById('afwijkingoms');
                    if (afwijkingomsEl && afwijking) {
                        afwijkingomsEl.value = afwijking;
                    }
                }
            }

        });

    }

}, false);
})();