#!/usr/bin/env python3 """Example normalizer for PIT3000 drug info rows. This file does not connect to production DB. Replace the stub functions with pyodbc/pymssql calls. """ from __future__ import annotations import json def normalize_drug_info(drugcode: str, goods: dict, detail: dict, images: list[dict], pictograms: list[dict]) -> dict: dik_code = goods.get('DIK_CODE') or '' sung_code = goods.get('SUNG_CODE') or '' return { 'drugcode': drugcode, 'dik_code': dik_code, 'sung_code': sung_code, 'sung_code_kind': 'ingredient_code', 'names': { 'etcname': detail.get('ETCNAME'), 'splname': detail.get('SPLNAME'), 'ingredient_name_en': detail.get('SUNG_ENM'), }, 'classification': { 'print_type': detail.get('PRINT_TYPE'), 'effctname': detail.get('EFFCTNAME'), 'character': detail.get('CHARACT'), }, 'drug_info': { 'save_medi': detail.get('SAVE_MEDI'), 'indic_medi': detail.get('INDIC_MEDI'), 'effect': detail.get('EFFECT'), 'adr': detail.get('ADR'), 'interaction': detail.get('INTERACTION'), 'gen_medi': detail.get('GEN_MEDI'), }, 'images': images, 'pictograms': pictograms, 'external_links': { 'health_kr_simple': f'https://health.kr/searchDrug/result_drug_simple.asp?drug_cd={dik_code}', 'health_kr_zoom': f'https://www.health.kr/drug_info/sb/zoom.asp?drug_code={dik_code}&print_front=&print_back=', 'pharm_or_kr_zoom': f'https://www.pharm.or.kr/search/zoom.asp?drug_code={dik_code}', }, } if __name__ == '__main__': sample = normalize_drug_info( 'A000000001', {'DIK_CODE': '123456789', 'SUNG_CODE': '1234567TB'}, { 'ETCNAME': '샘플정', 'SPLNAME': '샘플제약', 'SUNG_ENM': 'Sample ingredient', 'PRINT_TYPE': '해열진통소염제', 'EFFCTNAME': '정제', 'CHARACT': '흰색 원형 정제', 'SAVE_MEDI': '실온 보관', 'INDIC_MEDI': '1일 3회 식후 복용', 'EFFECT': '효능/효과 예시', 'ADR': '주의사항 예시', 'INTERACTION': '상호작용 예시', 'GEN_MEDI': '복약지도 예시', }, [{'source': 'PM_IMAGE..DrugImg', 'expr1': '1', 'url': '/api/drugs/A000000001/images/1.jpg'}], [{'pic_code': 'P001', 'source': 'PM_DRUG..CD_PICTOGRAM', 'url': '/api/drugs/A000000001/pictograms/P001.jpg'}], ) print(json.dumps(sample, ensure_ascii=False, indent=2))