db editor for admin page

This commit is contained in:
lehel 2025-10-01 21:27:31 +02:00
parent 3b67f50518
commit 3ceea8cb38
No known key found for this signature in database
GPG Key ID: 9C4F9D6111EE5CFA
6 changed files with 73 additions and 71 deletions

View File

@ -57,7 +57,7 @@ func TestChatService_MatchFound(t *testing.T) {
}
visit := Visit{
ID: "deworming",
Procedures: []Procedure{{Name: "Deworming tablet", Price: 30, DurationMin: 10}},
Procedures: []Procedure{{Name: "Deworming tablet", Price: 30, DurationMin: 10, Note: ""}},
Notes: "Bloodwork ensures organs are safe for treatment.",
}
var db VisitDBAPI = &testVisitDB{

15
db.yaml
View File

@ -5,9 +5,11 @@
- name: "Alap vérvizsgálat"
price: 12000
duration_minutes: 30
note: ""
- name: "Féregtelenítő kezelés"
price: 8000
duration_minutes: 15
note: ""
notes: "A kezelés előtt vérvizsgálat szükséges a biztonságos gyógyszeradás miatt."
- id: vaccination
@ -17,9 +19,11 @@
- name: "Általános állapotfelmérés"
price: 6000
duration_minutes: 15
note: ""
- name: "Oltás beadása"
price: 10000
duration_minutes: 10
note: ""
notes: "A kutyák oltási programja eltérhet az életkortól és korábbi oltásoktól függően."
- id: neutering
@ -29,9 +33,11 @@
- name: "Műtéti előzetes vizsgálat"
price: 15000
duration_minutes: 30
note: ""
- name: "Ivartalanító műtét"
price: 35000
duration_minutes: 90
note: ""
notes: "A műtét után 2-3 nap pihenő szükséges."
- id: dental_cleaning
@ -41,9 +47,11 @@
- name: "Altatás előtti vizsgálat"
price: 12000
duration_minutes: 20
note: ""
- name: "Fogkő eltávolítás ultrahanggal"
price: 25000
duration_minutes: 60
note: ""
notes: "Az altatás kockázata miatt minden esetben szükséges előzetes vizsgálat."
- id: checkup
@ -53,6 +61,7 @@
- name: "Teljes fizikai vizsgálat"
price: 10000
duration_minutes: 30
note: ""
notes: "Évente legalább egyszer javasolt a rutin állapotfelmérés."
- id: allergy
@ -62,6 +71,7 @@
- name: "Bőr- és vérvizsgálat"
price: 20000
duration_minutes: 45
note: ""
notes: "Az allergia gyakran étel vagy környezeti tényező miatt alakul ki."
- id: ultrasound
@ -71,6 +81,7 @@
- name: "Ultrahang vizsgálat"
price: 18000
duration_minutes: 30
note: ""
notes: "Terhesség vagy belső szervi problémák vizsgálatára gyakran használt módszer."
- id: bloodwork
@ -80,6 +91,7 @@
- name: "Teljes vérkép"
price: 15000
duration_minutes: 20
note: ""
notes: "Sok más vizsgálat alapja a laboreredmény."
- id: xray
@ -89,6 +101,7 @@
- name: "Röntgen vizsgálat"
price: 16000
duration_minutes: 25
note: ""
notes: "Törések, csontelváltozások vizsgálatára javasolt."
- id: diarrhea
@ -98,7 +111,9 @@
- name: "Állatorvosi konzultáció"
price: 8000
duration_minutes: 20
note: ""
- name: "Székletvizsgálat"
price: 10000
duration_minutes: 30
note: ""
notes: "Akut hasmenés esetén mindig javasolt a mihamarabbi vizsgálat."

1
log.go
View File

@ -28,6 +28,7 @@ type Procedure struct {
Name string `yaml:"name" json:"name"`
Price int `yaml:"price" json:"price"`
DurationMin int `yaml:"duration_minutes" json:"duration_minutes"`
Note string `yaml:"note" json:"note"`
}
// Visit represents a visit entry

39
ui.html
View File

@ -3,22 +3,16 @@
<head>
<meta charset="UTF-8">
<title>Vet Clinic Chat Assistant</title>
<style>
body { font-family: sans-serif; margin: 2em; }
#chatbox { width: 100%; max-width: 600px; margin: 0 auto; }
#messages { border: 1px solid #ccc; min-height: 120px; padding: 1em; margin-bottom: 1em; background: #fafafa; }
.msg-user { color: #333; }
.msg-bot { color: #007a3d; margin-bottom: 1em; }
#input { width: 80%; padding: 0.5em; }
#send { padding: 0.5em 1em; }
</style>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div id="chatbox">
<h2>Vet Clinic Chat Assistant</h2>
<div id="messages"></div>
<input id="input" type="text" placeholder="Type your message..." autofocus />
<button id="send">Send</button>
<body class="bg-gray-50 min-h-screen flex items-center justify-center">
<div id="chatbox" class="w-full max-w-md mx-auto bg-white rounded-xl shadow-lg p-6">
<h2 class="text-2xl font-bold mb-4 text-center text-green-700">Vet Clinic Chat Assistant</h2>
<div id="messages" class="border border-gray-300 min-h-[120px] p-3 mb-4 bg-gray-100 rounded-lg overflow-y-auto" style="max-height: 300px;"></div>
<div class="flex gap-2">
<input id="input" type="text" placeholder="Type your message..." autofocus class="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-400" />
<button id="send" class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition">Send</button>
</div>
</div>
<script>
const messages = document.getElementById('messages');
@ -26,7 +20,7 @@
const send = document.getElementById('send');
function appendMsg(text, who) {
const div = document.createElement('div');
div.className = who === 'user' ? 'msg-user' : 'msg-bot';
div.className = who === 'user' ? 'text-gray-800 mb-2' : 'text-green-700 mb-2';
div.textContent = text;
messages.appendChild(div);
messages.scrollTop = messages.scrollHeight;
@ -49,21 +43,14 @@
if (data.procedures) {
txt += "Procedures:\n";
data.procedures.forEach(function(p) {
txt += "- " + p.name + ": " + p.price + " Ft, " + p.duration_minutes + " perc\n";
txt += "- " + p + "\n";
});
}
if (data.total_price) txt += "Total: " + data.total_price + " Ft\n";
if (data.total_duration) txt += "Total duration: " + data.total_duration + " perc\n";
if (data.notes) txt += "Notes: " + data.notes + "\n";
appendMsg(txt, 'bot');
} else {
appendMsg('Sorry, no match found. Your message will be sent to the vet.', 'bot');
appendMsg(data.reply || 'No match found.', 'bot');
}
};
input.addEventListener('keydown', function(e) {
if (e.key === 'Enter') send.onclick();
});
}
</script>
</body>
</html>

View File

@ -3,23 +3,19 @@
<head>
<meta charset="UTF-8">
<title>Edit db.yaml</title>
<style>
body { font-family: sans-serif; margin: 2em; }
#editor { max-width: 900px; margin: 0 auto; }
textarea { width: 100%; height: 300px; margin-bottom: 1em; }
button { padding: 0.5em 1em; margin-right: 1em; }
#status { color: #007a3d; margin-bottom: 1em; }
</style>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist/js-yaml.min.js"></script>
</head>
<body>
<div id="editor">
<h2>Edit db.yaml</h2>
<div id="status"></div>
<button id="load">Load db.yaml</button>
<button id="add">Add Entry</button>
<button id="download">Download YAML</button>
<textarea id="yamlArea" placeholder="YAML will appear here..."></textarea>
<body class="bg-gray-50 min-h-screen flex items-center justify-center">
<div id="editor" class="w-full max-w-2xl mx-auto bg-white rounded-xl shadow-lg p-6">
<h2 class="text-2xl font-bold mb-4 text-center text-green-700">Edit db.yaml</h2>
<div id="status" class="mb-2 text-green-700"></div>
<div class="flex flex-wrap gap-2 mb-4">
<button id="load" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">Load db.yaml</button>
<button id="add" class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition">Add Entry</button>
<button id="download" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition">Download YAML</button>
</div>
<textarea id="yamlArea" placeholder="YAML will appear here..." class="w-full h-40 mb-4 p-2 border border-gray-300 rounded-lg bg-gray-100 text-sm"></textarea>
<div id="formArea"></div>
</div>
<script>
@ -68,21 +64,30 @@
if (!Array.isArray(data)) return;
data.forEach((entry, idx) => {
const div = document.createElement('div');
div.style.border = '1px solid #ccc';
div.style.padding = '1em';
div.style.marginBottom = '1em';
div.className = "border border-gray-300 rounded-lg p-4 mb-6 bg-gray-50";
div.innerHTML = `
<b>Entry #${idx+1}</b> <button onclick="removeEntry(${idx})">Remove</button><br>
<label>ID: <input type="text" value="${entry.id||''}" onchange="updateEntry(${idx}, 'id', this.value)"></label><br>
<label>Visit:<br><textarea rows="4" style="width:100%" onchange="updateEntry(${idx}, 'visit', this.value)">${entry.visit||''}</textarea></label><br>
<label>Keywords:</label>
<div id="keywords${idx}" style="margin-bottom:0.5em;"></div>
<input type="text" id="keywordInput${idx}" placeholder="Add keyword..." style="width:200px;">
<button type="button" onclick="addKeyword(${idx})">Add</button><br>
<label>Notes:<br><textarea rows="2" style="width:100%;height:48px;resize:vertical;" onchange="updateEntry(${idx}, 'notes', this.value)">${entry.notes||''}</textarea></label><br>
<b>Procedures:</b><br>
<div id="procedures${idx}"></div>
<button onclick="addProcedure(${idx})">Add Procedure</button>
<div class="flex items-center justify-between mb-2">
<span class="font-semibold text-lg">Entry #${idx+1}</span>
<button type="button" onclick="removeEntry(${idx})" class="px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600">Remove</button>
</div>
<label class="block mb-2">ID:
<input type="text" value="${entry.id||''}" onchange="updateEntry(${idx}, 'id', this.value)" class="mt-1 w-full px-3 py-2 border border-gray-300 rounded-lg" />
</label>
<label class="block mb-2">Visit:<br>
<textarea rows="4" class="mt-1 w-full px-3 py-2 border border-gray-300 rounded-lg" onchange="updateEntry(${idx}, 'visit', this.value)">${entry.visit||''}</textarea>
</label>
<label class="block mb-2">Keywords:</label>
<div id="keywords${idx}" class="flex flex-wrap gap-2 mb-2"></div>
<div class="flex gap-2 mb-2">
<input type="text" id="keywordInput${idx}" placeholder="Add keyword..." class="px-3 py-2 border border-gray-300 rounded-lg" style="width:200px;">
<button type="button" onclick="addKeyword(${idx})" class="px-3 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">Add</button>
</div>
<label class="block mb-2">Notes:<br>
<textarea rows="2" style="height:48px;resize:vertical;" class="mt-1 w-full px-3 py-2 border border-gray-300 rounded-lg" onchange="updateEntry(${idx}, 'notes', this.value)">${entry.notes||''}</textarea>
</label>
<b class="block mb-2">Procedures:</b>
<div id="procedures${idx}" class="mb-2"></div>
<button onclick="addProcedure(${idx})" class="px-3 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600">Add Procedure</button>
`;
formArea.appendChild(div);
renderKeywords(idx, entry.keywords||[]);
@ -109,7 +114,7 @@
window.addProcedure = function(idx) {
if (!Array.isArray(data[idx].procedures)) data[idx].procedures = [];
data[idx].procedures.push({name: '', price: 0, duration_minutes: 0});
data[idx].procedures.push({name: '', price: 0, duration_minutes: 0, note: ''});
renderForm();
yamlArea.value = jsyaml.dump(data);
};
@ -152,17 +157,10 @@
keywords.forEach((kw, kwIdx) => {
const span = document.createElement('span');
span.textContent = kw;
span.style.border = '1px solid #aaa';
span.style.padding = '2px 8px';
span.style.marginRight = '4px';
span.style.background = '#f0f0f0';
span.style.borderRadius = '12px';
span.style.display = 'inline-block';
span.style.marginBottom = '2px';
span.className = "inline-flex items-center bg-green-100 text-green-800 border border-green-300 rounded-full px-3 py-1 text-sm";
const btn = document.createElement('button');
btn.textContent = 'x';
btn.style.marginLeft = '4px';
btn.style.fontSize = '10px';
btn.className = "ml-2 text-xs bg-red-400 text-white rounded-full px-2 py-0.5 hover:bg-red-500";
btn.onclick = function() { removeKeyword(idx, kwIdx); };
span.appendChild(btn);
kwDiv.appendChild(span);
@ -174,12 +172,13 @@
procDiv.innerHTML = '';
procedures.forEach((proc, procIdx) => {
const pdiv = document.createElement('div');
pdiv.style.marginBottom = '0.5em';
pdiv.className = "mb-2 p-2 border border-gray-200 rounded-lg bg-white";
pdiv.innerHTML = `
<label>Name: <input type="text" value="${proc.name||''}" onchange="updateProcedure(${entryIdx},${procIdx},'name',this.value)"></label>
<label>Price: <input type="number" value="${proc.price||0}" onchange="updateProcedure(${entryIdx},${procIdx},'price',this.value)"></label>
<label>Duration (min): <input type="number" value="${proc.duration_minutes||0}" onchange="updateProcedure(${entryIdx},${procIdx},'duration_minutes',this.value)"></label>
<button onclick="removeProcedure(${entryIdx},${procIdx})">Remove</button>
<label class="mr-2">Name: <input type="text" value="${proc.name||''}" onchange="updateProcedure(${entryIdx},${procIdx},'name',this.value)" class="px-2 py-1 border border-gray-300 rounded-lg" /></label>
<label class="mr-2">Price: <input type="number" value="${proc.price||0}" onchange="updateProcedure(${entryIdx},${procIdx},'price',this.value)" class="px-2 py-1 border border-gray-300 rounded-lg w-20" /></label>
<label class="mr-2">Duration (min): <input type="number" value="${proc.duration_minutes||0}" onchange="updateProcedure(${entryIdx},${procIdx},'duration_minutes',this.value)" class="px-2 py-1 border border-gray-300 rounded-lg w-20" /></label>
<label class="block mt-2">Note:<br><input type="text" value="${proc.note||''}" onchange="updateProcedure(${entryIdx},${procIdx},'note',this.value)" class="mt-1 w-full px-2 py-1 border border-gray-300 rounded-lg text-sm" placeholder="Short note..." /></label>
<button onclick="removeProcedure(${entryIdx},${procIdx})" class="px-2 py-1 bg-red-500 text-white rounded hover:bg-red-600 mt-2">Remove</button>
`;
procDiv.appendChild(pdiv);
});

Binary file not shown.