This commit is contained in:
Dwi Swandhana
2026-05-08 18:32:53 +07:00
parent 35d8211a65
commit 4d942523d1
+44 -23
View File
@@ -166,7 +166,7 @@ DEVICE_CONFIGS = [
'protocol': 'serial', 'flag_column': 'flg_vitek2'
},
{
'port': 'COM5', 'baud_rate': 19200, 'device_type': 'bd', 'alat_name': 'BACTEC',
'port': 'COM5', 'baud_rate': 9600, 'device_type': 'bd', 'alat_name': 'BACTEC',
'protocol': 'serial', 'flag_column': 'flg_bd1'
},
#BD_MGIT yang di dalam ruangan isolasi
@@ -2536,38 +2536,50 @@ def parse_and_save_vitek_result(raw_data, port_name="VITEK"):
def split_patient_name(full_name):
"""
Pecah nama pasien menjadi first_name dan last_name.
- Jika ada '^', diasumsikan format ASTM/HL7: Last^First.
- Jika nama biasa, token terakhir = last_name, sisanya = first_name.
Return: last_name, first_name
ASTM format: LAST^FIRST
"""
if not full_name:
return "NO", "NAME"
return "NAME", "NO"
raw = str(full_name).strip()
if not raw:
return "NO", "NAME"
return "NAME", "NO"
first_name = ""
last_name = ""
# Hapus karakter ASTM berbahaya
raw = (
raw.replace("\x00", "")
.replace("\r", " ")
.replace("\n", " ")
.replace("|", " ")
.replace("&", " ")
)
if "^" in raw:
parts = [p.strip() for p in raw.split("^") if p.strip()]
if len(parts) >= 2:
last_name = parts[0]
first_name = parts[1]
elif len(parts) == 1:
first_name = parts[0]
parts = [p.strip() for p in raw.split("^")]
last_name = parts[0] if len(parts) > 0 and parts[0] else "NAME"
first_name = parts[1] if len(parts) > 1 and parts[1] else "NO"
else:
tokens = raw.split()
if len(tokens) >= 2:
last_name = tokens[-1]
first_name = " ".join(tokens[:-1])
last_name = tokens[-1]
elif len(tokens) == 1:
first_name = tokens[0]
last_name = "NAME"
first_name = (first_name or "NO").upper()[:20]
last_name = (last_name or "NAME").upper()[:20]
return first_name, last_name
first_name = first_name.upper()[:20]
last_name = last_name.upper()[:20]
return last_name, first_name
def sanitize_astm_field(value, *, uppercase=False, max_len=None, allow_component_sep=False):
"""
@@ -2989,7 +3001,7 @@ def create_astm_order_message(order):
sex = "M" if sex_raw.startswith("L") else "F"
# Lokasi / Ruangan (Field 26) sebaiknya berupa kode singkat agar tidak ditrunkasi LIS.
raw_location = sanitize_astm_field(getattr(order, 'ruangan', "UT"), uppercase=True, max_len=40)
raw_location = sanitize_astm_field(getattr(order, 'ruangan', "UT"), uppercase=True, max_len=10)
location = re.sub(r"[^A-Z0-9]", "", raw_location)[:10]
if not location:
location = "UT"
@@ -3009,11 +3021,18 @@ def create_astm_order_message(order):
# --- 2. KONSTRUKSI RECORD DENGAN INDEX PASTI ---
# --- RECORD HEADER (H) ---
head = r"H|\^&|||LIS||||||||1"
h_rec = [""] * 14
h_rec[0] = "H" # H,1 Record Type
h_rec[1] = r"\^&" # H,2 Delimiter
h_rec[4] = "MyLIS" # H,5 Sender Name
h_rec[12] = "V1.00" # H,13 Version
h_rec[13] = datetime.datetime.now().strftime("%Y%m%d%H%M%S") # H,14 Message DateTime
head = "|".join(h_rec)
# --- RECORD PATIENT (P) ---
# Kita buat array kosong sebanyak 30 kolom dulu
p_rec = [""] * 30
p_rec = [""] * 35
p_rec[0] = "P" # Field 1: Record Type
p_rec[1] = "1" # Field 2: Sequence
p_rec[2] = pid # Field 3: Patient ID (Practice)
@@ -3023,10 +3042,12 @@ def create_astm_order_message(order):
p_rec[7] = "" # Field 8: Birthdate
p_rec[8] = sex # Field 9: Sex (Index 8)
# ... Field 10-25 biarkan kosong ...
p_rec[25] = location # Field 26: Location (Index 25)
p_rec[25] = "1" # Field 26: Location (Index 25)
p_rec[32] = "MIKRO" # Hospital Service
p_rec[33] = raw_location# Hospital Client (Raw, untuk referensi internal)
# Potong array sampai index 26 saja (sisanya buang) lalu gabung
pat_str = "|".join(p_rec[:26])
pat_str = "|".join(p_rec[:35])
# --- RECORD ORDER (O) ---
o_rec = [""] * 30
@@ -3057,7 +3078,7 @@ def create_astm_order_message(order):
seq = "1"
# Isi Frame: [Seq] [Data] [ETX]
frame_body = f"{seq}{message_content}\x03"
frame_body = f"{seq}{message_content}\r\x03"
# Hitung Checksum
chk = calculate_astm_checksum(frame_body)