pharmacy-pos-qr-system/docs/DRYSYRUP_CONVERSION.md
2026-03-12 10:14:17 +09:00

194 lines
5.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 건조시럽 환산계수 기능
## 개요
건조시럽(dry syrup)은 물로 희석하여 복용하는 시럽 형태의 의약품입니다. 복용량을 mL로 표시하지만, 실제 약 성분의 양은 g(그램)으로 환산해야 정확합니다.
**환산계수(conversion_factor)**를 사용하여 총 복용량(mL)을 실제 성분량(g)으로 변환합니다.
### 예시
- 오구멘틴듀오시럽 228mg/5ml
- 환산계수: 0.11
- 총량 120mL × 0.11 = **13.2g**
## 아키텍처
```
┌─────────────────────────────────────────────────────────────┐
│ Flask Backend (7001) │
├─────────────────────────────────────────────────────────────┤
│ /api/drug-info/conversion-factor/<sung_code> │
│ /pmr/api/label/preview (sung_code 파라미터 추가) │
├─────────────────────────────────────────────────────────────┤
│ DatabaseManager │
│ ├── MSSQL (192.168.0.4) - PIT3000 │
│ │ └── CD_GOODS.SUNG_CODE (성분코드) │
│ ├── PostgreSQL (192.168.0.39:5432/label10) │
│ │ └── drysyrup 테이블 (환산계수 23건) │
│ └── SQLite - 마일리지 등 │
└─────────────────────────────────────────────────────────────┘
```
## 데이터베이스
### PostgreSQL 연결 정보
```
Host: 192.168.0.39
Port: 5432
Database: label10
User: admin
Password: trajet6640
```
### drysyrup 테이블 스키마
| 컬럼명 | 타입 | 설명 |
|--------|------|------|
| ingredient_code | VARCHAR | 성분코드 (SUNG_CODE와 매칭) |
| conversion_factor | DECIMAL | 환산계수 (mL → g) |
| ingredient_name | VARCHAR | 성분명 |
| product_name | VARCHAR | 대표 제품명 |
### 매핑 관계
- MSSQL `PM_DRUG.CD_GOODS.SUNG_CODE` = PostgreSQL `drysyrup.ingredient_code`
## API 명세
### 1. 환산계수 조회 API
**Endpoint:** `GET /api/drug-info/conversion-factor/<sung_code>`
**응답 (성공):**
```json
{
"success": true,
"sung_code": "535000ASY",
"conversion_factor": 0.11,
"ingredient_name": "아목시실린수화물·클라불란산칼륨",
"product_name": "일성오구멘틴듀오시럽 228mg/5ml"
}
```
**응답 (데이터 없음/연결 실패):**
```json
{
"success": true,
"sung_code": "NOTEXIST",
"conversion_factor": null,
"ingredient_name": null,
"product_name": null
}
```
> ⚠️ 연결 실패나 데이터 없음에도 에러 없이 null 반환 (서비스 안정성 우선)
### 2. 라벨 미리보기 API (확장)
**Endpoint:** `POST /pmr/api/label/preview`
**Request Body:**
```json
{
"patient_name": "홍길동",
"med_name": "오구멘틴듀오시럽",
"dosage": 8,
"frequency": 3,
"duration": 5,
"unit": "mL",
"sung_code": "535000ASY"
}
```
**Response:**
```json
{
"success": true,
"image": "data:image/png;base64,...",
"conversion_factor": 0.11
}
```
### 라벨 출력 예시
환산계수가 있는 경우:
```
총120mL (13.2g)/5일분
```
환산계수가 없는 경우:
```
총120mL/5일분
```
## 코드 위치
### 수정된 파일
1. **dbsetup.py** - PostgreSQL 연결 관리
- `DatabaseConfig.POSTGRES_URL` 추가
- `DatabaseManager.get_postgres_engine()` 추가
- `DatabaseManager.get_postgres_session()` 추가
- `DatabaseManager.get_conversion_factor(sung_code)` 추가
2. **app.py** - 환산계수 조회 API
- `GET /api/drug-info/conversion-factor/<sung_code>`
3. **pmr_api.py** - 라벨 미리보기
- `preview_label()` - sung_code 파라미터 추가
- `create_label_image()` - conversion_factor 파라미터 추가
## 유료/무료 버전 구분 설계 (추후)
환산계수는 추후 유료 기능으로 분리 가능합니다.
### 설계 방안
1. **라이선스 체크**
- 환산계수 조회 전 라이선스 확인
- 무료 버전: `conversion_factor: null` 반환
- 유료 버전: 실제 값 반환
2. **API 분리**
- `/api/drug-info/conversion-factor` → 유료 전용
- 무료 버전은 API 자체를 비활성화
3. **현재 구현**
- 환산계수가 없어도 라벨 출력 정상 동작
- null 체크 후 기존 포맷 유지
## 예외처리
| 상황 | 동작 |
|------|------|
| PostgreSQL 연결 실패 | null 반환, 에러 로그 |
| 데이터 없음 | null 반환 |
| sung_code 미전달 | 환산계수 조회 skip |
| 환산계수 0 또는 음수 | 적용 안 함 (기존 포맷) |
## 테스트 방법
```bash
# 환산계수 조회 테스트
curl http://localhost:7001/api/drug-info/conversion-factor/535000ASY
# 존재하지 않는 코드 테스트
curl http://localhost:7001/api/drug-info/conversion-factor/NOTEXIST
# 라벨 미리보기 테스트 (PowerShell)
$body = @{
patient_name = "홍길동"
med_name = "오구멘틴듀오시럽"
dosage = 8
frequency = 3
duration = 5
unit = "mL"
sung_code = "535000ASY"
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:7001/pmr/api/label/preview" `
-Method Post -ContentType "application/json" -Body $body
```
## 변경 이력
| 날짜 | 내용 |
|------|------|
| 2026-03-12 | 최초 구현 |