Ansico-Medcalc/ansico-medcalc/ansico-medcalc.php

195 lines
10 KiB
PHP

<?php
/**
* Plugin Name: Ansico Medcalc
* Plugin URI: https://ansico.dk/Ansico/Ansico-Medcalc
* Description: Medicinske beregnere til WordPress: GO-FAR og Glasgow Blatchford Score (GBS).
* Version: 1.0
* Author: Andreas Andersen (Ansico)
* Author URI: https://ansico.dk
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: ansico-medcalc
* Requires at least: 5.8
* Tested up to: 6.9.4
*
* Ansico Medcalc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Registrerer scripts til Gutenberg editoren.
*/
function ansico_medcalc_enqueue_block_assets() {
wp_enqueue_script(
'ansico-medcalc-block-js',
plugins_url( 'block.js', __FILE__ ),
array( 'wp-blocks', 'wp-element', 'wp-editor' ),
'1.0',
true
);
}
add_action( 'enqueue_block_editor_assets', 'ansico_medcalc_enqueue_block_assets' );
/**
* Render funktion for GO-FAR blokken.
*/
function ansico_medcalc_render_gofar_block($attributes) {
ob_start();
?>
<div class="ansico-medcalc-container" style="max-width: 600px; margin: 20px auto; padding: 25px; border: 2px solid #005a9c; border-radius: 12px; background: #ffffff; font-family: sans-serif; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">
<h2 style="color: #005a9c; margin-top: 0; border-bottom: 2px solid #f0f0f0; padding-bottom: 10px;">GO-FAR Score Beregner</h2>
<form id="ansico-gofar-form" style="margin-top: 20px;">
<div style="margin-bottom: 20px;">
<label style="font-weight: 600; display: block; margin-bottom: 8px;">Alder</label>
<select id="gofar-age" style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px;">
<option value="0">< 70 år (0)</option>
<option value="2">70-74 år (+2)</option>
<option value="5">75-79 år (+5)</option>
<option value="6">80-84 år (+6)</option>
<option value="11">≥ 85 år (+11)</option>
</select>
</div>
<div style="display: flex; flex-direction: column; gap: 10px;">
<label><input type="checkbox" class="gofar-check" value="-15"> Neurologisk intakt v. indlæggelse (-15)</label>
<label><input type="checkbox" class="gofar-check" value="10"> Større traume (+10)</label>
<label><input type="checkbox" class="gofar-check" value="8"> Akut apopleksi (+8)</label>
<label><input type="checkbox" class="gofar-check" value="7"> Metastaserende/Hæmatologisk kræft (+7)</label>
<label><input type="checkbox" class="gofar-check" value="7"> Sepsis (+7)</label>
<label><input type="checkbox" class="gofar-check" value="7"> Medicinsk ikke-kardiologisk diagnose (+7)</label>
<label><input type="checkbox" class="gofar-check" value="6"> Leverinsufficiens (+6)</label>
<label><input type="checkbox" class="gofar-check" value="6"> Indlagt fra plejehjem (+6)</label>
<label><input type="checkbox" class="gofar-check" value="5"> Hypotension/Hypoperfusion (+5)</label>
<label><input type="checkbox" class="gofar-check" value="4"> Nyreinsufficiens eller dialyse (+4)</label>
<label><input type="checkbox" class="gofar-check" value="4"> Respiratorisk insufficiens (+4)</label>
<label><input type="checkbox" class="gofar-check" value="1"> Pneumoni (+1)</label>
</div>
</form>
<div style="background: #f4f7f9; padding: 20px; border-radius: 8px; margin-top: 25px; text-align: center;">
<div style="font-size: 18px;">Score: <strong id="gofar-score-val">0</strong></div>
<div style="font-size: 22px; color: #005a9c; font-weight: bold;" id="gofar-result">Over gennemsnittet (> 15%)</div>
</div>
</div>
<script>
(function() {
const age = document.getElementById('gofar-age');
const checks = document.querySelectorAll('.gofar-check');
function calc() {
if(!age) return;
let s = parseInt(age.value);
checks.forEach(c => { if(c.checked) s += parseInt(c.value); });
document.getElementById('gofar-score-val').textContent = s;
let res = s >= 24 ? "Meget lav (< 1%)" : s >= 14 ? "Lav (1 - 3%)" : s >= -5 ? "Gennemsnitlig (3 - 15%)" : "Over gennemsnittet (> 15%)";
document.getElementById('gofar-result').textContent = res;
}
if (age) {
age.onchange = calc; checks.forEach(c => c.onchange = calc); calc();
}
})();
</script>
<?php
return ob_get_clean();
}
/**
* Render funktion for GBS blokken.
*/
function ansico_medcalc_render_gbs_block($attributes) {
ob_start();
?>
<div class="ansico-medcalc-container" style="max-width: 600px; margin: 20px auto; padding: 25px; border: 2px solid #d32f2f; border-radius: 12px; background: #ffffff; font-family: sans-serif; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">
<h2 style="color: #d32f2f; margin-top: 0; border-bottom: 2px solid #f0f0f0; padding-bottom: 10px;">Glasgow Blatchford Score (GBS)</h2>
<form id="ansico-gbs-form" style="margin-top: 20px;">
<div style="margin-bottom: 15px;">
<label style="font-weight: 600; display: block; margin-bottom: 5px;">Køn</label>
<select id="gbs-gender" style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ddd;">
<option value="mand">Mand</option>
<option value="kvinde">Kvinde</option>
</select>
</div>
<div style="margin-bottom: 15px;">
<label style="font-weight: 600; display: block; margin-bottom: 5px;">Karbamid (Urea) mmol/L</label>
<select id="gbs-urea" style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ddd;">
<option value="0">< 6.5 (0)</option>
<option value="2">6.5 - 7.9 (+2)</option>
<option value="3">8.0 - 9.9 (+3)</option>
<option value="4">10.0 - 24.9 (+4)</option>
<option value="6">≥ 25.0 (+6)</option>
</select>
</div>
<div style="margin-bottom: 15px;">
<label style="font-weight: 600; display: block; margin-bottom: 5px;">Hæmoglobin (Hb) mmol/L</label>
<select id="gbs-hb" style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ddd;">
</select>
</div>
<div style="margin-bottom: 15px;">
<label style="font-weight: 600; display: block; margin-bottom: 5px;">Systolisk Blodtryk mmHg</label>
<select id="gbs-sbp" style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ddd;">
<option value="0">≥ 110 (0)</option>
<option value="1">100 - 109 (+1)</option>
<option value="2">90 - 99 (+2)</option>
<option value="3">< 90 (+3)</option>
</select>
</div>
<div style="display: flex; flex-direction: column; gap: 8px; margin-top: 15px;">
<label><input type="checkbox" class="gbs-check" value="1"> Puls ≥ 100 (+1)</label>
<label><input type="checkbox" class="gbs-check" value="1"> Melæna (sort afføring) (+1)</label>
<label><input type="checkbox" class="gbs-check" value="2"> Synkope (besvimelse) (+2)</label>
<label><input type="checkbox" class="gbs-check" value="2"> Leversygdom (kronisk/akut) (+2)</label>
<label><input type="checkbox" class="gbs-check" value="2"> Hjertesvigt (+2)</label>
</div>
</form>
<div style="background: #fff5f5; padding: 20px; border-radius: 8px; margin-top: 25px; text-align: center; border: 1px solid #feb2b2;">
<div style="font-size: 18px;">GBS Score: <strong id="gbs-score-val">0</strong></div>
<div style="font-size: 20px; color: #c53030; font-weight: bold; margin-top: 5px;" id="gbs-result">Lav risiko</div>
</div>
</div>
<script>
(function() {
const gender = document.getElementById('gbs-gender');
const urea = document.getElementById('gbs-urea');
const hb = document.getElementById('gbs-hb');
const sbp = document.getElementById('gbs-sbp');
const checks = document.querySelectorAll('.gbs-check');
function updateHb() {
if(!gender || !hb) return;
const isMand = gender.value === 'mand';
hb.innerHTML = isMand ?
`<option value="0">≥ 8,1 (0)</option><option value="1">7,5 - 8,0 (+1)</option><option value="3">6,2 - 7,4 (+3)</option><option value="6">< 6,2 (+6)</option>` :
`<option value="0">≥ 7,5 (0)</option><option value="1">6,2 - 7,4 (+1)</option><option value="6">< 6,2 (+6)</option>`;
calc();
}
function calc() {
if(!urea || !hb || !sbp) return;
let s = parseInt(urea.value) + parseInt(hb.value) + parseInt(sbp.value);
checks.forEach(c => { if(c.checked) s += parseInt(c.value); });
document.getElementById('gbs-score-val').textContent = s;
document.getElementById('gbs-result').textContent = s === 0 ? "Lav risiko (Ambulant opfølgning muligt)" : "Høj risiko (Kræver indlæggelse/udredning)";
}
if (gender) {
gender.onchange = updateHb; urea.onchange = calc; hb.onchange = calc; sbp.onchange = calc;
checks.forEach(c => c.onchange = calc);
updateHb();
}
})();
</script>
<?php
return ob_get_clean();
}
/**
* Registrerer blokkene.
*/
function ansico_medcalc_register_blocks() {
register_block_type( 'ansico/medcalc-gofar', array( 'render_callback' => 'ansico_medcalc_render_gofar_block' ) );
register_block_type( 'ansico/medcalc-gbs', array( 'render_callback' => 'ansico_medcalc_render_gbs_block' ) );
}
add_action( 'init', 'ansico_medcalc_register_blocks' );