BỘ Y TẾ -------
CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập - Tự do - Hạnh phúc ---------------
Số: 3376/QĐ-BYT
Hà Nội, ngày 30 tháng 8 năm 2023
QUYẾT ĐỊNH
VỀ VIỆC BAN HÀNH “ĐỀ CƯƠNG QUY TRÌNH KỸ THUẬT XÉT NGHIỆM”
BỘ TRƯỞNG BỘ Y TẾ
Căn cứ Luật Khám bệnh, chữa bệnh năm 2009;
Căn cứ Nghị định số 95/2022/NĐ-CP của Chính phủ quy định chức năng, nhiệm vụ, quyền hạn và cơ cấu tổ chức của Bộ Y tế;
Căn cứ Quyết định số 2538/QĐ-BYT ngày 15/06/2023 về việc Ban hành Danh mục chuyên môn kỹ thuật trong khám bệnh, chữa bệnh để làm cơ sở xây dựng định mức kinh tế kỹ thuật;
Theo đề nghị của Cục trưởng Cục Quản lý Khám, chữa bệnh, Bộ Y tế.
QUYẾT ĐỊNH:
Điều 1. Ban hành kèm theo Quyết định này “Đề cương quy trình kỹ thuật xét nghiệm” để làm cơ sở cho các cơ sở khám bệnh, chữa bệnh xây dựng quy trình kỹ thuật xét nghiệm.
Điều 2. Quyết định này có hiệu lực kể từ ngày ký, ban hành.
Điều 3. Các Ông, Bà: Chánh Văn phòng Bộ; Cục trưởng Cục Quản lý Khám, chữa bệnh; Chánh Thanh tra Bộ; Cục trưởng, Vụ trưởng các Cục, Vụ thuộc Bộ Y tế; Giám đốc các bệnh viện, viện có giường bệnh trực thuộc Bộ Y tế; Giám đốc Sở Y tế các tỉnh, thành phố trực thuộc Trung ương; Thủ trưởng y tế ngành và các cơ quan, đơn vị liên quan chịu trách nhiệm thi hành Quyết định này./.
Nơi nhận: - Như Điều 3; - Bộ trưởng (để b/c); - Lưu: VT, KCB.
KT. BỘ TRƯỞNG THỨ TRƯỞNG Trần Văn Thuấn
ĐỀ CƯƠNG TÀI LIỆU CHUYÊN MÔN
HƯỚNG DẪN QUY TRÌNH KỸ THUẬT XÉT NGHIỆM (Ban hành kèm theo Quyết định số 3376/QĐ-BYT ngày 30 tháng 8 năm 2023 của Bộ trưởng Bộ Y tế)
I. Quy định chung
1. Đối tượng áp dụng: Người tham gia xây dựng tài liệu chuyên môn Hướng dẫn quy trình kỹ thuật (QTKT) trong khám bệnh, chữa bệnh.
2. Phạm vi áp dụng: xây dựng các tài liệu chuyên môn Hướng dẫn QTKT trong khám bệnh, chữa bệnh.
3. Tên QTKT
a) Tên: Hướng dẫn QTKT về tên Chươngb) Trong mỗi Chương: có nhiều QTKT được xây dựng theo các giai đoạn khác nhau, có thể đặt tên theo tập như Hướng dẫn quy trình kỹ thuật về Vi sinh Tập 1, Hướng dẫn quy trình kỹ thuật lấy, bảo quản và vận chuyển bệnh phẩm xét nghiệm vi sinh hoặc tên gọi cụ thể khác theo thống nhất của Hội đồng thẩm định QTKT.
II. Đề cương của 01 cuốn Hướng dẫn QTKT
1. Bìa2. Quyết định ban hành
3. Lời nói đầu
4. Danh sách Hội đồng thẩm định và, hoặc Ban biên soạn
5. Mục lục
6. Danh mục bảng, biểu đồ, hình (nếu có)
7. Danh mục chữ viết tắt
8. Các bài viết cụ thể
9. Các phụ lục (nếu có)
III. Đề cương 01 QTKT
1. Định dạng (format) QTKT
1.1. Font chữ Times New Roman, cỡ chữ 14, khoảng cách dòng: 1; khoảng cách giữa các đoạn: trước: 6pt, sau: 6pt, lề trên: 2,5 cm, lề dưới: 2 cm, lề trái: 3cm, lề phải: 2,5cm, đánh dấu trang ở giữa, bên trên). Phần mục lục: khoảng cách giữa các đoạn: trước 6 pt, sau 6pt.
1.2. Thứ tự các mục: mục 1: viết chữ in hoa, đậm; dưới mục 1 là 1.1: viết chữ thường, đậm; dưới mục 1.1. là mục 1.1.1: chữ thường; a: chữ thường, nghiêng; gạch đầu dòng (-), dưới gạch đầu dòng là ( ), tiếp đến là dấu (.) Trong trường hợp các mục không có nhiều nội dung, bắt đầu bằng gạch đầu dòng.
1.3. Độ dài mỗi bài: trung bình dưới 10 trang A4. Một số bài có thể nhiều hoặc ít số trang hơn.
2. Nội dung QTKT
1. ĐẠI CƯƠNG
1.1. Mục đích của kỹ thuật
1.2. Định nghĩa, nguyên lý
2. CHUẨN BỊ
2.1. Người thực hiện: Nhân lực trực tiếp. Thông tin bao gồm nhân lực (bác sỹ, kỹ thuật viên...), số lượng.
2.2. Vật tư: được sử dụng trực tiếp, bao gồm dụng cụ, sinh phẩm, hóa chất và vật tư khác... được sử dụng trực tiếp để thực hiện kỹ thuật (không bao gồm vật tư để thực hiện các công việc quản lý, điều hành), về hoá chất, sinh phẩm bao gồm cả hoá chất, sinh phẩm dùng trong xét nghiệm, nội kiểm, ngoại kiểm, hóa chất chuẩn, tham chiếu (nêu rõ thành phần, điều kiện bảo quản).
2.3. Trang thiết bị: được sử dụng trực tiếp (không bao gồm các trang thiết bị phục vụ quản lý, điều hành, như máy điều hoà, đèn chiếu sáng...).
2.4. Chuẩn bị mẫu bệnh phẩm
2.4.1. Đối với QTKT lấy mẫu bệnh phẩm
- Chuẩn bị người bệnh: người bệnh được giải thích về việc lấy mẫu bệnh phẩm, hướng dẫn người bệnh phối hợp để lấy mẫu theo đúng yêu cầu.
- Loại mẫu bệnh phẩm (huyết tương, huyết thanh, nước tiểu...).
- Dụng cụ lấy mẫu, chứa mẫu, bảo quản.
- Điều kiện bảo quản và vận chuyển mẫu bệnh phẩm
- Tiêu chuẩn mẫu bệnh phẩm (thể tích, số lượng, chất lượng...)
2.4.2. Đối với QTKT về thực hiện xét nghiệm: chuẩn bị mẫu bệnh phẩm:
- Loại mẫu bệnh phẩm (huyết tương, huyết thanh, nước tiểu...).
- Tiêu chuẩn mẫu bệnh phẩm (thể tích, số lượng, chất lượng...)
…
2.5. Phiếu chỉ định xét nghiệm
Kiểm tra phiếu chỉ định xét nghiệm: ghi đầy đủ thông tin theo quy định: họ tên người bệnh, tuổi, giường bệnh, tên khoa phòng, chẩn đoán, loại mẫu bệnh phẩm, thời gian lấy mẫu bệnh phẩm...
2.6. Thời gian thực hiện kỹ thuật (ước tính, đơn vị là giờ).
2.7. Địa điểm thực hiện kỹ thuật.
3. AN TOÀN
Nêu các vấn đề an toàn cần lưu ý khi thực hiện kỹ thuật (nếu cần thiết), có thể bao gồm:
- Quy định về an toàn cho người thực hiện và dự phòng nguy cơ trước, trong và sau phơi nhiễm (có thể xây dựng quy định riêng nếu cần).
- Quy định hiệu chuẩn vật tư, thiết bị (có thể xây dựng quy định riêng nếu cần).
- Quy định về an toàn điện và phòng tránh cháy nổ
- Quy định về an toàn hóa chất: có bảng chỉ dẫn an toàn từng loại hóa chất (có thể xây dựng quy định riêng nếu cần).
- Quy định về an toàn sinh học
- Quy định kiểm soát môi trường: đánh giá các yếu tố vi khí hậu như nhiệt độ, độ ẩm, ánh sáng, tiếng ồn...
4. CÁC BƯỚC TIẾN HÀNH
4.1. Các bước thực hiện
Nêu các bước thực hiện chính theo trình tự, cụ thể, ngắn gọn và dễ hiểu
4.1.1 Bước 1
4.1.2 Bước 2...
4.2. Nhận định kết quả
- Xem xét kết quả QC (có thể chạy QC trước hoặc QC song song tùy thuộc loại xét nghiệm): Nêu giới hạn ngưỡng kết quả nội kiểm và hành động khắc phục khi QC không đạt. QC đạt yêu cầu sẽ đọc kết quả xét nghiệm.
- Đọc kết quả và nhận định kết quả
Đọc kết quả (xét nghiệm có thể là định lượng, bán định lượng, định tính) dựa trên kết quả đo, kết quả quan sát.
Nhận định kết quả: dựa trên kết quả ngưỡng (khoảng chuẩn sinh học, giá trị quyết định lâm sàng, ngưỡng xét nghiệm...).
- Phiên giải và báo cáo kết quả: Phiên giải kết quả dựa ngưỡng xét nghiệm, giá trị quyết định lâm sàng...để phiên giải và báo cáo kết quả bằng bản điện tử và/hoặc bán cứng
- Biện luận kết quả cho những trường hợp bất thường
4.3. Trả kết quả và lưu trữ hồ sơ
Trả kết quả theo quy trình liên quan, ghi vào biểu mẫu có liên quan đến quy trình và lưu hồ sơ xét nghiệm.
5. NHỮNG SAI SÓT VÀ XỬ TRÍ
5.1. Trước khi thực hiện kỹ thuật
5.2. Trong quá trình thực hiện kỹ thuật
5.3. Sau khi thực hiện kỹ thuật
Nêu rõ các nguồn biến đổi/ sai lệch kết quả tiềm ẩn, các chất ảnh hưởng đến kết quả (như lipid máu, tan máu, bilirubin máu, thuốc...) hoặc các phản ứng chéo.
6. TIÊU CHUẨN ĐÁNH GIÁ VÀ KIỂM TRA CHẤT LƯỢNG
- Yêu cầu thực hiện nội kiểm chất lượng.
- Yêu cầu thực hiện ngoại kiểm hoặc so sánh liên phòng hoặc kiểm tra mẫu mù.
7. TÀI LIỆU THAM KHẢO
Lập danh sách các tài liệu tham khảo chính, cập nhật.
lồng nhau (bên trong) hay không
const memberID = 0;
const vbID = '32ea0ff4d4bbaa92d8ae061a5f6984ce';
// State management cho phân tích
let isAnalyzing = false; // Có đang phân tích không
let currentAnalyzingAddress = null; // Address đang được phân tích
let currentAnalyzingElement = null; // Element đang được phân tích
let currentAnalyzingBadge = null; // Badge của element đang phân tích
let isPanelOpen = false; // Panel phân tích có đang mở không
console.log('Tiện ích loaded - memberID:', memberID, 'vbID:', vbID);
function isInViewportAndTabNoiDung(element) {
const rect = element.getBoundingClientRect();
const buffer = 1500; // Buffer to preload content below the viewport (approx. 50+ lines)
const viewHeight = window.innerHeight || document.documentElement.clientHeight;
const isInViewport = rect.top < viewHeight + buffer && rect.bottom >= 0;
const isInTabNoiDung = $(element).closest('#tab_noi_dung_vb').length > 0;
return isInViewport && isInTabNoiDung;
}
function getAddress(element) {
const validTags = ['trichyeu', 'cancu', 'phan', 'chuong', 'muc', 'tieumuc', 'dieu', 'khoan', 'diem'];
const $parent = $(element).closest(validTags.join(','));
if (!$parent.length) {
return null;
}
let addr = $parent.attr('address');
if (!addr && $parent.prop('tagName').toLowerCase() === 'trichyeu') {
addr = 'trichyeu';
$parent.attr('address', addr);
}
return addr || null;
}
function processTnplClasses($element) {
const tnplKeysInLine = new Set(); // key = slug hoặc text (thường là slug)
$element.find('tnpl').each(function () {
const $tnpl = $(this);
const tnplSlug = ($tnpl.attr('slug') || '').trim().toLowerCase();
const tnplKey = tnplSlug || $tnpl.text().trim().toLowerCase();
// Đã xử lý trong cùng dòng => bỏ
if (tnplKeysInLine.has(tnplKey)) {
return;
}
tnplKeysInLine.add(tnplKey);
let tnplExists = false;
// Chỉ duyệt các tnpl đã được tô màu (class on)
$('tnpl.on').each(function () {
const $existingTnpl = $(this);
const existingSlug = ($existingTnpl.attr('slug') || '').trim().toLowerCase();
const existingKey = existingSlug || $existingTnpl.text().trim().toLowerCase();
if (
existingKey === tnplKey &&
isInViewportAndTabNoiDung($existingTnpl[0])
) {
tnplExists = true;
return false; // break each
}
});
if (!tnplExists) {
$tnpl.addClass('on');
}
});
}
function processQueue() {
while (pendingRequests < maxConcurrentRequests && requestQueue.length > 0) {
const task = requestQueue.shift();
pendingRequests++;
task()
.always(() => {
pendingRequests--;
processQueue();
});
}
}
function processVisibleParagraphs() {
try {
$('#tab_noi_dung_vb p:not([is-posted="1"])').each(function () {
let $element = $(this);
if (isInViewportAndTabNoiDung(this)) {
$element.attr('is-posted', '1');
$element.addClass('loading-content');
let p_innerHTML = $element.html();
let address = null;
if (cac_cau_hinh.loai_noi_dung.includes('docs')) {
address = getAddress($element);
}
const isSubP = $element.parents('p').length > 0;
if (isSubP && !allow_sub_p) {
$element.removeClass('loading-content');
return; // Không gửi nếu không cho phép
}
const postData = { p_content: p_innerHTML, cac_cau_hinh, address };
if (isSubP && allow_sub_p) {
postData.sub_p = 1;
}
requestQueue.push(() =>
$.ajax({
url: '//tnpl' + (Math.floor(Math.random() * 10) + 1) + '.hethongphapluat.com/tien-ich/tim.tien.ich.php',
type: 'POST',
data: postData,
success: function(response) {
$element.html(response);
processTnplClasses($element);
// Đợi CTTD và các tiện ích load xong rồi mới attach badge
if (memberID === 4 && typeof attachPhanTichBadge === 'function') {
setTimeout(function() {
// $element chính là thẻ p, kiểm tra và attach badge trực tiếp
const $parent = $element.closest('phan, chuong, muc, tieumuc, dieu, khoan, diem');
if ($parent.length > 0 && $parent.find('.badge-phan-tich[data-for="' + $parent.attr('address') + '"]').length === 0) {
const address = $parent.attr('address');
$element.attr('data-address', address);
// Lấy tên loại thẻ cho tooltip
const parentType = getParentTypeName($parent.prop('tagName').toLowerCase());
// Append badge VÀO PARENT (dieu, khoan,...) thay vì vào để tránh xung đột CTTD
const $badge = $('Phân tích ');
$parent.append($badge);
// Thêm class để CSS set position: relative CHỈ cho element có badge
$parent.addClass('has-phan-tich-badge');
}
// Xử lý các p con (nếu có sub-p)
attachPhanTichBadge($element);
}, 300); // Đợi 300ms để CTTD render xong
}
},
complete: function() {
$element.removeClass('loading-content');
}
})
);
processQueue();
}
});
} catch(e) {
console.error('Lỗi processVisibleParagraphs:', e);
}
}
$(window).on('scroll resize', function () {
processVisibleParagraphs();
});
console.log('Bắt đầu processVisibleParagraphs lần đầu...');
processVisibleParagraphs();
console.log('processVisibleParagraphs lần đầu hoàn thành');
// Chức năng phân tích điều luật (chỉ cho member_id = 4)
if (memberID === 4) {
// Modal cảnh báo
function showWarningModal(message) {
// Tạo modal nếu chưa có
if ($('#warningModal').length === 0) {
const modalHTML = `
`;
$('body').append(modalHTML);
}
$('#warningModalBody').html('' + message + '
');
$('#warningModal').modal('show');
}
// Hàm lấy tên tiếng Việt của thẻ
function getParentTypeName(tagName) {
const typeNames = {
'phan': 'Phần',
'chuong': 'Chương',
'muc': 'Mục',
'tieumuc': 'Tiểu mục',
'dieu': 'Điều',
'khoan': 'Khoản',
'diem': 'Điểm'
};
return typeNames[tagName] || 'Nội dung';
}
function attachPhanTichBadge($container) {
const validTags = 'phan, chuong, muc, tieumuc, dieu, khoan, diem';
$container.find('p').each(function() {
const $p = $(this);
const $parent = $p.closest(validTags);
if ($parent.length > 0) {
const address = $parent.attr('address');
// Kiểm tra đã có badge cho parent này chưa
if ($parent.find('.badge-phan-tich[data-for="' + address + '"]').length === 0) {
// Lưu address vào data attribute
$p.attr('data-address', address);
// Lấy tên loại thẻ cho tooltip
const parentType = getParentTypeName($parent.prop('tagName').toLowerCase());
// Append badge vào PARENT, không vào
const $badge = $('Phân tích ');
$parent.append($badge);
// Thêm class để CSS set position: relative CHỈ cho element có badge
$parent.addClass('has-phan-tich-badge');
}
}
});
}
// Helper: Escape HTML entities
function escapeHtml(text) {
const map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return String(text).replace(/[&<>"']/g, function(m) { return map[m]; });
}
// Helper: Convert Markdown to HTML (đơn giản)
function markdownToHtml(markdown) {
if (!markdown) return '';
let html = markdown;
// Headers
html = html.replace(/^### (.*$)/gim, '
$1 ');
html = html.replace(/^## (.*$)/gim, '$1 ');
html = html.replace(/^# (.*$)/gim, '$1 ');
// Bold
html = html.replace(/\*\*(.*?)\*\*/g, '$1 ');
// Italic
html = html.replace(/\*(.*?)\*/g, '$1 ');
// Blockquote
html = html.replace(/^> (.*$)/gim, '$1 ');
html = html.replace(/^> (.*$)/gim, '$1 ');
// Lists (unordered)
html = html.replace(/^\- (.*$)/gim, '$1 ');
html = html.replace(/(.*<\/li>)/s, '');
// Lists (ordered)
html = html.replace(/^\d+\. (.*$)/gim, ' $1 ');
// Line breaks và paragraphs
html = html.split('\n\n').map(para => {
para = para.trim();
if (para.startsWith('')) {
return para;
}
if (para) {
return '' + para.replace(/\n/g, ' ') + '
';
}
return '';
}).join('\n');
// Clean up multiple line breaks
html = html.replace(/\n{3,}/g, '\n\n');
return html;
}
// Panel fixed position
function closePhanTichPanel() {
const $panel = $('#phanTichPanel');
if ($panel.length) {
$panel.removeClass('show');
setTimeout(() => {
$panel.remove();
}, 300);
}
// Reset highlight và badge khi đóng panel
if (currentAnalyzingElement) {
currentAnalyzingElement.removeClass('highlight-border-persistent');
}
if (currentAnalyzingBadge) {
currentAnalyzingBadge.text('Phân tích').removeClass('analyzing');
currentAnalyzingBadge.data('analyzing', false);
currentAnalyzingBadge.data('hovering', false);
currentAnalyzingBadge.css({display: 'none'}); // Ẩn badge khi đóng
}
// Reset tất cả các element khác (trong trường hợp có nhiều)
$('#tab_noi_dung_vb .highlight-border-persistent').removeClass('highlight-border-persistent');
$('#tab_noi_dung_vb .badge-phan-tich-container.analyzing').each(function() {
$(this).text('Phân tích').removeClass('analyzing').data('analyzing', false);
});
// Check: có CTTD pointer đang mở không?
const $visiblePointers = $('.pointer:visible');
const hadCTTDOpen = $visiblePointers.length > 0;
if (hadCTTDOpen) {
// CÓ CTTD đang mở → giữ rightdocinfo ẩn
console.log('ℹ️ CTTD pointer is visible, keeping rightdocinfo hidden');
} else {
// KHÔNG có CTTD → SHOW lại rightdocinfo
const $rightdocinfo = $('#rightdocinfo');
if ($rightdocinfo.length > 0) {
$rightdocinfo.show();
console.log('✅ Showing rightdocinfo back (no CTTD pointer)');
}
}
// Reset state
isAnalyzing = false;
currentAnalyzingAddress = null;
currentAnalyzingElement = null;
currentAnalyzingBadge = null;
isPanelOpen = false; // Đánh dấu panel đã đóng
console.log('✅ Panel closed, state reset, isPanelOpen = false');
}
// Panel đã song song với rightdocinfo → không cần MutationObserver nữa
console.log('✅ Panel running in standalone mode (parallel to rightdocinfo)');
// Resize event để update panel dimensions khi browser resize
let resizeTimer;
$(window).on('resize', function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
if (isPanelOpen && $('#phanTichPanel').length > 0) {
updatePanelDimensions();
console.log('✅ Panel dimensions updated on window resize');
}
}, 250); // Debounce 250ms
});
// Function để detect và áp dụng dimensions từ rightdocinfo
function updatePanelDimensions() {
const $panel = $('#phanTichPanel');
const $rightdocinfo = $('#rightdocinfo');
const $docRightCol = $('#doc-right-col');
if ($panel.length === 0) return;
// Ưu tiên: doc-right-col > rightdocinfo
let $reference = $docRightCol.length > 0 ? $docRightCol : $rightdocinfo;
// Nếu reference bị ẩn (display:none), tạm show để get dimensions
let wasHidden = false;
if ($reference.length > 0 && !$reference.is(':visible')) {
wasHidden = true;
$reference.css('visibility', 'hidden').show();
}
if ($reference.length > 0) {
const refWidth = $reference.outerWidth();
const refOffset = $reference.offset();
if (refWidth && refOffset) {
// Tính vị trí right từ edge màn hình
const windowWidth = $(window).width();
const rightPosition = windowWidth - (refOffset.left + refWidth);
$panel.css({
'width': refWidth + 'px',
'right': rightPosition + 'px'
});
console.log('✅ Panel dimensions updated:', {
width: refWidth + 'px',
right: rightPosition + 'px',
reference: $reference.attr('id')
});
} else {
console.warn('⚠️ Could not get dimensions from reference element');
}
// Restore trạng thái hidden nếu cần
if (wasHidden) {
$reference.hide().css('visibility', '');
}
} else {
console.warn('⚠️ No reference element found for panel dimensions');
}
}
function openPhanTichPanel(address, vbID) {
console.log('openPhanTichPanel called with address:', address);
console.log('Current state - isAnalyzing:', isAnalyzing, 'currentAnalyzingAddress:', currentAnalyzingAddress);
// Kiểm tra nếu đang phân tích element khác
if (isAnalyzing && currentAnalyzingAddress && currentAnalyzingAddress !== address) {
const currentName = getElementDisplayName(currentAnalyzingAddress);
console.warn('Already analyzing:', currentAnalyzingAddress, 'Cannot analyze:', address);
showWarningModal('Vui lòng chờ phân tích ' + currentName + ' hoàn tất...');
return;
}
// Nếu đang phân tích cùng element → không làm gì
if (isAnalyzing && currentAnalyzingAddress === address) {
console.log('Already analyzing this element, ignoring duplicate request');
return;
}
// Panel sẽ fixed position append vào body
const $rightdocinfo = $('#rightdocinfo');
// KHÔNG ẨN CTTD pointer - cho phép CTTD và panel cùng tồn tại
console.log('Panel opening, CTTD pointer can stay visible');
// ẨN rightdocinfo để tiết kiệm không gian
if ($rightdocinfo.length > 0) {
$rightdocinfo.hide();
console.log('Hidden rightdocinfo to save space');
}
// XÓA highlight persistent của TẤT CẢ elements cũ trước
$('#tab_noi_dung_vb .highlight-border-persistent').removeClass('highlight-border-persistent');
console.log('Removed all previous highlight-border-persistent');
// Tìm element đang được phân tích và badge của nó
const $element = $('[address="' + address + '"]');
const $badge = $element.find('.badge-phan-tich-container[data-for="' + address + '"]').first();
// Set state
isAnalyzing = true;
currentAnalyzingAddress = address;
currentAnalyzingElement = $element;
currentAnalyzingBadge = $badge;
console.log('State set:', {
isAnalyzing: isAnalyzing,
currentAnalyzingAddress: currentAnalyzingAddress,
elementFound: $element.length > 0,
badgeFound: $badge.length > 0
});
// Thêm highlight persistent cho element MỚI này
$element.addClass('highlight-border-persistent');
// Thay đổi badge thành "Đang phân tích..." và giữ hiển thị
if ($badge.length > 0) {
$badge.text('Đang phân tích...').addClass('analyzing');
// Giữ badge hiển thị và ở đúng vị trí
$badge.data('analyzing', true);
$badge.data('hovering', true); // Prevent auto-hide
console.log('Badge set to analyzing state');
// Đảm bảo badge hiển thị ở đúng vị trí (vì dùng position: fixed)
showPhanTichBadgeForParent($element);
}
// Tạo panel nếu chưa có - fixed position append vào body
if ($('#phanTichPanel').length === 0) {
const panelHTML = `
Đang phân tích...
Đang phân tích...
`;
// Append vào body (fixed position không cần container cụ thể)
$('body').append(panelHTML);
// Detect width từ rightdocinfo và áp dụng cho panel
updatePanelDimensions();
// Trigger show và set flag
setTimeout(() => {
$('#phanTichPanel').addClass('show');
isPanelOpen = true;
console.log('✅ Panel opened (fixed position), isPanelOpen = true');
}, 10);
} else {
$('#phanTichPanelBody').html(`
Đang phân tích...
Đang phân tích...
`);
// Update dimensions khi re-open
updatePanelDimensions();
$('#phanTichPanel').addClass('show');
isPanelOpen = true;
console.log('✅ Panel re-opened (fixed position), isPanelOpen = true');
}
// Bind nút đóng và ESC
$(document).off('click.closePhanTich').on('click.closePhanTich', '.close-phan-tich', function() {
closePhanTichPanel();
});
$(document).off('keyup.closePhanTich').on('keyup.closePhanTich', function(e) {
if (e.key === 'Escape') closePhanTichPanel();
});
// Bind nút refresh - phân tích lại
$(document).off('click.refreshPhanTich').on('click.refreshPhanTich', '.btn-refresh-phan-tich', function(e) {
e.preventDefault();
e.stopPropagation();
const $btn = $(this);
const $icon = $btn.find('i');
// Disable button và thêm animation
$btn.prop('disabled', true);
$icon.addClass('fa-spin');
console.log('🔄 Refresh: Phân tích lại address:', address);
// Show loading trong panel
$('#phanTichPanelBody').html(`
Đang phân tích lại...
Đang xóa cache và phân tích lại...
`);
// Gọi API xóa cache trước
deletePhanTichCache(address, vbID, function(deleteSuccess) {
if (deleteSuccess) {
console.log('✅ Cache deleted, now re-analyzing...');
// Sau khi xóa cache, gọi lại API phân tích
callPhanTichAPI(address, vbID, function() {
// Enable lại button
$btn.prop('disabled', false);
$icon.removeClass('fa-spin');
});
} else {
console.error('❌ Failed to delete cache');
$('#phanTichPanelBody').html(`
Lỗi! Không thể xóa cache. Vui lòng thử lại.
`);
$btn.prop('disabled', false);
$icon.removeClass('fa-spin');
}
});
});
// Gọi API phân tích (dùng function helper)
callPhanTichAPI(address, vbID);
}
// Helper: Gọi API phân tích (tách riêng để dùng lại)
function callPhanTichAPI(address, vbID, callback) {
const randomServer = Math.floor(Math.random() * 10) + 1;
$.ajax({
url: '//tnpl' + randomServer + '.hethongphapluat.com/tien-ich/phan.tich.dieu.luat.php',
type: 'POST',
contentType: 'application/json',
timeout: 300000, // 5 phút
data: JSON.stringify({
address: address,
vb_id: vbID
}),
success: function(response) {
console.log('Analysis complete for:', address, response);
// Reset badge về trạng thái bình thường (nhưng vẫn hiển thị)
if (currentAnalyzingBadge) {
currentAnalyzingBadge.text('Phân tích').removeClass('analyzing');
currentAnalyzingBadge.data('analyzing', false);
console.log('Badge reset to normal state');
}
// Reset state analyzing để có thể phân tích element khác
isAnalyzing = false;
console.log('State reset: isAnalyzing = false, can analyze other elements now');
if (response.ok) {
// Render kết quả phân tích
let html = '';
html += '';
html += '
' + escapeHtml(response.ten_van_ban) + ' ';
if (response.so_hieu) {
html += 'Số hiệu: ' + escapeHtml(response.so_hieu) + ' ';
}
html += 'Điều khoản: ' + escapeHtml(response.address) + ' ';
if (response.from_cache) {
html += ' Cache ';
}
html += '
';
html += '' + markdownToHtml(response.phan_tich) + '
';
if (response.usage) {
html += '';
html += 'Thống kê: ';
html += 'Input tokens: ' + (response.usage.promptTokenCount || 0) + ', ';
html += 'Output tokens: ' + (response.usage.candidatesTokenCount || 0);
html += '
';
}
$('#phanTichPanelBody').html(html);
} else {
$('#phanTichPanelBody').html(`
Lỗi! ${escapeHtml(response.error || 'Không thể phân tích điều luật.')}
Vui lòng thử lại sau.
`);
}
if (callback) callback();
},
error: function(xhr, status, error) {
console.error('Analysis error:', error);
// Reset badge về trạng thái bình thường
if (currentAnalyzingBadge) {
currentAnalyzingBadge.text('Phân tích').removeClass('analyzing');
currentAnalyzingBadge.data('analyzing', false);
}
// Reset state analyzing
isAnalyzing = false;
let errorMsg = error;
if (xhr.responseJSON && xhr.responseJSON.error) {
errorMsg = xhr.responseJSON.error;
}
$('#phanTichPanelBody').html(`
Lỗi! Không thể kết nối đến server phân tích.
Chi tiết: ${escapeHtml(errorMsg)}
`);
if (callback) callback();
}
});
}
// Helper: Xóa cache phân tích
function deletePhanTichCache(address, vbID, callback) {
const randomServer = Math.floor(Math.random() * 10) + 1;
$.ajax({
url: '//tnpl' + randomServer + '.hethongphapluat.com/tien-ich/delete.phan.tich.cache.php',
type: 'POST',
contentType: 'application/json',
timeout: 10000,
data: JSON.stringify({
address: address,
vb_id: vbID
}),
success: function(response) {
console.log('Delete cache response:', response);
if (callback) callback(response.ok || false);
},
error: function(xhr, status, error) {
console.error('Delete cache error:', error);
if (callback) callback(false);
}
});
}
// Helper: Lấy tên hiển thị của element từ address
function getElementDisplayName(address) {
if (!address) return 'nội dung';
const $element = $('[address="' + address + '"]');
if ($element.length === 0) return address;
// Parse address: vd "dieu_3_khoan_29" -> "Khoản 29 Điều 3"
// Address format: lớn đến nhỏ (phan > chuong > muc > dieu > khoan > diem)
const parts = address.split('_');
const displayParts = [];
for (let i = 0; i < parts.length; i += 2) {
if (i + 1 < parts.length) {
const type = getParentTypeName(parts[i]);
const num = parts[i + 1];
displayParts.push(type + ' ' + num);
}
}
// Reverse để hiển thị từ nhỏ đến lớn: "Khoản 29 Điều 3" (thay vì "Điều 3 Khoản 29")
return displayParts.reverse().join(' ');
}
function openPhanTichModal(address, vbID) {
// Tạo modal nếu chưa có
if ($('#modalPhanTich').length === 0) {
const modalHTML = `
Đang phân tích...
Đang phân tích...
`;
$('body').append(modalHTML);
}
// Reset và hiển thị modal với loading
$('#modalPhanTichBody').html(`
Đang phân tích...
Đang phân tích...
`);
$('#modalPhanTich').modal('show');
// AJAX request
const randomServer = Math.floor(Math.random() * 10) + 1;
$.ajax({
url: '//tnpl' + randomServer + '.hethongphapluat.com/tien-ich/phan.tich.dieu.luat.php',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
address: address,
vb_id: vbID
}),
success: function(response) {
if (response.ok) {
// Render kết quả phân tích
let html = '';
// Header thông tin văn bản
html += '';
html += '
' + escapeHtml(response.ten_van_ban) + ' ';
if (response.so_hieu) {
html += 'Số hiệu: ' + escapeHtml(response.so_hieu) + ' ';
}
html += 'Điều khoản: ' + escapeHtml(response.address) + ' ';
html += '';
// Nội dung phân tích (Markdown -> HTML)
html += '';
html += markdownToHtml(response.phan_tich);
html += '
';
// Thông tin usage (nếu có)
if (response.usage) {
html += '';
html += 'Thống kê: ';
html += 'Input tokens: ' + (response.usage.promptTokenCount || 0) + ', ';
html += 'Output tokens: ' + (response.usage.candidatesTokenCount || 0);
html += '
';
}
$('#modalPhanTichBody').html(html);
} else {
$('#modalPhanTichBody').html(`
Lỗi! ${escapeHtml(response.error || 'Không thể phân tích điều luật.')}
Vui lòng thử lại sau.
`);
}
},
error: function(xhr, status, error) {
let errorMsg = error;
if (xhr.responseJSON && xhr.responseJSON.error) {
errorMsg = xhr.responseJSON.error;
}
$('#modalPhanTichBody').html(`
Lỗi! Không thể kết nối đến server phân tích.
Chi tiết: ${escapeHtml(errorMsg)}
`);
}
});
}
// Helpers: show/hide badge cho parent element (dieu, khoan,...) với position: fixed
function showPhanTichBadgeForParent($parent) {
// Lấy badge CỦA CHÍNH parent này (match data-for với address của parent)
const parentAddress = $parent.attr('address');
const $badge = $parent.find('.badge-phan-tich-container[data-for="' + parentAddress + '"]').first();
if ($badge.length === 0) {
console.warn('No badge found for parent:', parentAddress);
return;
}
// Ẩn TẤT CẢ các badge khác để tránh overlap
$('.badge-phan-tich-container').not($badge).each(function() {
const $otherBadge = $(this);
// Chỉ ẩn badge KHÔNG đang analyzing
if (!$otherBadge.data('analyzing')) {
$otherBadge.css({display: 'none'});
}
});
// Show badge tạm để tính width
$badge.css({display: 'inline-block', opacity: 0, visibility: 'hidden'});
const badgeWidth = $badge.outerWidth();
// Tính toán vị trí fixed dựa trên offset của parent
const offset = $parent.offset();
const scrollTop = $(window).scrollTop();
const scrollLeft = $(window).scrollLeft();
// Position badge top-right của parent và show
$badge.css({
display: 'inline-block',
visibility: 'visible',
opacity: 1,
top: (offset.top - scrollTop) + 'px',
left: (offset.left + $parent.outerWidth() - badgeWidth - scrollLeft - 5) + 'px' // -5px padding
});
console.log('Showing badge for:', parentAddress, 'at position:', $badge.css('top'), $badge.css('left'));
$parent.addClass('highlight-border');
}
function hidePhanTichBadgeForParent($parent) {
const $badge = $parent.find('.badge-phan-tich-container').first();
if ($badge.length === 0) return;
$badge.css({display: 'none', opacity: 0});
$parent.removeClass('highlight-border');
}
// Biến lưu element đang hover
let currentHoveredElement = null;
let hoverDebounceTimer = null;
// Dùng mousemove để track chính xác element nào đang được hover
$(document).on('mousemove', '#tab_noi_dung_vb', function(e) {
// Tìm element gần nhất (phan, chuong, muc, dieu, khoan, diem) tại vị trí chuột
const $target = $(e.target).closest('phan, chuong, muc, tieumuc, dieu, khoan, diem');
if ($target.length === 0) {
// Không hover vào element nào
return;
}
const address = $target.attr('address');
// Nếu đang hover vào cùng element → skip
if (currentHoveredElement && currentHoveredElement[0] === $target[0]) {
return;
}
// Clear debounce timer cũ
if (hoverDebounceTimer) {
clearTimeout(hoverDebounceTimer);
}
// Debounce để tránh trigger quá nhiều
hoverDebounceTimer = setTimeout(function() {
// Element thay đổi
console.log('Hover changed to:', address);
// Set flag hovering cho element mới
$target.data('hovering', true);
// Cancel timeout nếu có
const timeoutId = $target.data('hideTimeout');
if (timeoutId) {
clearTimeout(timeoutId);
}
// Ẩn badge của TẤT CẢ elements khác
$('#tab_noi_dung_vb phan, #tab_noi_dung_vb chuong, #tab_noi_dung_vb muc, #tab_noi_dung_vb tieumuc, #tab_noi_dung_vb dieu, #tab_noi_dung_vb khoan, #tab_noi_dung_vb diem')
.not($target)
.each(function() {
const $el = $(this);
// Chỉ xóa highlight-border, KHÔNG xóa highlight-border-persistent
$el.removeClass('highlight-border');
// Ẩn badge nếu KHÔNG đang analyzing
const $badge = $el.find('.badge-phan-tich-container');
if ($badge.length && !$badge.data('analyzing')) {
$badge.css({display: 'none'});
}
});
// Attach badge nếu chưa có
if (address && $target.find('.badge-phan-tich-container[data-for="' + address + '"]').length === 0) {
const parentType = getParentTypeName($target.prop('tagName').toLowerCase());
const $badge = $('Phân tích ');
console.log('Creating badge for address:', address, 'parentType:', parentType);
$target.append($badge);
$target.addClass('has-phan-tich-badge');
}
// Show badge cho element này
if ($target.find('.badge-phan-tich-container').length > 0) {
showPhanTichBadgeForParent($target);
}
// Update current hovered element
currentHoveredElement = $target;
}, 50); // Debounce 50ms
});
// Event delegation cho hover ra khỏi #tab_noi_dung_vb
$(document).on('mouseleave', '#tab_noi_dung_vb', function(e) {
// Clear current hovered element
currentHoveredElement = null;
// Ẩn tất cả badge không đang analyzing sau một khoảng thời gian
setTimeout(function() {
if (currentHoveredElement === null) {
// Chỉ ẩn nếu thực sự không hover vào element nào
$('#tab_noi_dung_vb phan, #tab_noi_dung_vb chuong, #tab_noi_dung_vb muc, #tab_noi_dung_vb tieumuc, #tab_noi_dung_vb dieu, #tab_noi_dung_vb khoan, #tab_noi_dung_vb diem')
.each(function() {
const $el = $(this);
const $badge = $el.find('.badge-phan-tich-container');
if ($badge.length && !$badge.data('analyzing')) {
$badge.css({display: 'none'});
}
});
console.log('Mouse left tab_noi_dung_vb, hiding all badges');
}
}, 300);
});
// Event delegation cho hover ra khỏi parent (giữ lại cho badge behavior)
$(document).on('mouseleave', '#tab_noi_dung_vb phan, #tab_noi_dung_vb chuong, #tab_noi_dung_vb muc, #tab_noi_dung_vb tieumuc, #tab_noi_dung_vb dieu, #tab_noi_dung_vb khoan, #tab_noi_dung_vb diem', function(e) {
const $parent = $(this);
const parentAddress = $parent.attr('address');
const $badge = $parent.find('.badge-phan-tich-container[data-for="' + parentAddress + '"]').first();
// Set flag parent not hovering
$parent.data('hovering', false);
// Nếu badge đang analyzing thì KHÔNG ẩn, GIỮ hiển thị
if ($badge.length > 0 && $badge.data('analyzing')) {
console.log('Badge is analyzing, keep visible');
return;
}
// Delay để có thời gian di chuột vào badge
const timeoutId = setTimeout(() => {
// Chỉ ẩn nếu cả parent và badge đều không hover và không analyzing
if ($badge.length > 0 && !$parent.data('hovering') && !$badge.data('hovering') && !$badge.data('analyzing')) {
hidePhanTichBadgeForParent($parent);
}
}, 300); // Tăng lên 300ms
$parent.data('hideTimeout', timeoutId);
});
// Hover vào badge → giữ hiển thị
$(document).on('mouseenter', '.badge-phan-tich-container', function(e) {
e.stopPropagation();
const $badge = $(this);
const $parent = $badge.parent();
$badge.data('hovering', true);
// Cancel timeout của parent
const timeoutId = $parent.data('hideTimeout');
if (timeoutId) {
clearTimeout(timeoutId);
}
});
// Hover ra khỏi badge → ẩn nếu không hover parent
$(document).on('mouseleave', '.badge-phan-tich-container', function(e) {
const $badge = $(this);
$badge.data('hovering', false);
const $parent = $badge.parent();
// Nếu badge đang analyzing thì KHÔNG ẩn, GIỮ hiển thị
if ($badge.data('analyzing') || $badge.hasClass('analyzing')) {
console.log('Badge is analyzing on mouseleave, keep visible');
return;
}
setTimeout(() => {
// Chỉ ẩn nếu cả parent và badge đều không hover và không analyzing
if (!$parent.data('hovering') && !$badge.data('hovering') && !$badge.data('analyzing') && !$badge.hasClass('analyzing')) {
hidePhanTichBadgeForParent($parent);
}
}, 300);
});
// Event delegation cho hover vào badge → hiện tooltip
$(document).on('mouseenter', '.badge-phan-tich, .badge-phan-tich-container, .badge-phan-tich-fixed', function() {
const $badge = $(this);
const parentType = $badge.attr('data-parent-type') || 'Nội dung';
if ($badge.find('.badge-tooltip').length === 0) {
const $tooltip = $('Phân tích chi tiết nội dung ' + parentType + ' này ');
$badge.append($tooltip);
setTimeout(() => $tooltip.addClass('show'), 10);
}
});
// Event delegation cho hover ra khỏi badge → ẩn tooltip
$(document).on('mouseleave', '.badge-phan-tich, .badge-phan-tich-container, .badge-phan-tich-fixed', function() {
const $tooltip = $(this).find('.badge-tooltip');
if ($tooltip.length > 0) {
$tooltip.removeClass('show');
setTimeout(() => $tooltip.remove(), 300);
}
});
// Event delegation cho click badge → mở panel
$(document).on('click', '.badge-phan-tich, .badge-phan-tich-container, .badge-phan-tich-fixed', function(e) {
e.preventDefault();
e.stopPropagation();
const $badge = $(this);
console.log('Badge clicked! Element:', $badge[0]);
console.log('Badge parent:', $badge.parent().prop('tagName'), $badge.parent().attr('address'));
console.log('Badge data-for:', $badge.attr('data-for'));
console.log('Badge data-parent-type:', $badge.attr('data-parent-type'));
// Nếu badge đang analyzing thì không cho click
if ($badge.hasClass('analyzing') || $badge.data('analyzing')) {
console.log('Badge is analyzing, click ignored');
return;
}
// Lấy address từ data-for attribute
const address = $badge.attr('data-for');
console.log('Will analyze address:', address, 'vbID:', vbID);
if (address && vbID) {
openPhanTichPanel(address, vbID);
} else {
console.error('Missing address or vbID', {address, vbID});
showWarningModal('Không tìm thấy địa chỉ điều luật hoặc ID văn bản!');
}
});
// Ẩn badge khi click vào CTTD
$(document).on('click', 'cttd.chuthichtudong span, dctk span, dctd span', function(e) {
console.log('CTTD clicked');
// Ẩn TẤT CẢ badge KHÔNG đang analyzing
$('.badge-phan-tich-container').each(function() {
const $badge = $(this);
if (!$badge.data('analyzing') && !$badge.hasClass('analyzing')) {
$badge.css({display: 'none'});
console.log('Hiding badge:', $badge.attr('data-for'));
}
});
});
// Update badge position khi scroll hoặc resize (vì dùng position: fixed)
function updateBadgePositions() {
$('.badge-phan-tich-container:visible').each(function() {
const $badge = $(this);
const $parent = $badge.parent();
// Cập nhật position nếu parent đang hover HOẶC badge đang analyzing
if ($parent.length && ($parent.is(':hover') || $badge.data('analyzing'))) {
// Re-calculate position
const offset = $parent.offset();
const scrollTop = $(window).scrollTop();
const scrollLeft = $(window).scrollLeft();
const badgeWidth = $badge.outerWidth();
$badge.css({
top: (offset.top - scrollTop) + 'px',
left: (offset.left + $parent.outerWidth() - badgeWidth - scrollLeft - 5) + 'px'
});
}
});
}
$(window).on('scroll', updateBadgePositions);
$(window).on('resize', updateBadgePositions);
}
});
Tra cứu thuật ngữ với từ hoặc cụm từ đã chọn?
×
Quyết định 3376/QĐ-BYT năm 2023 về "Đề cương quy trình kỹ thuật xét nghiệm" do Bộ trưởng Bộ Y tế ban hành