# PostgreSQL TOBE ERD

`TOBE` PostgreSQL 스키마는 외래키가 실제로 설정된 물리 ERD입니다.

```mermaid
erDiagram
    tb_cd_grp["tb_cd_grp<br/>(코드 그룹 마스터)"] {
        string grp_cd PK
        string grp_nm
    }
    tb_cd["tb_cd<br/>(공통 코드 마스터)"] {
        string grp_cd PK
        string cd_val PK
        string cd_nm
    }
    tb_org["tb_org<br/>(기관 마스터)"] {
        string org_cd PK
        string org_nm
    }
    tb_dept["tb_dept<br/>(부서 마스터)"] {
        string dept_cd PK
        string org_cd FK
        string upr_dept_cd FK
        string dept_nm
    }
    tb_emp["tb_emp<br/>(직원 마스터)"] {
        string emp_no PK
        string org_cd FK
        string dept_cd FK
        string emp_nm
    }
    tb_pt["tb_pt<br/>(환자 마스터)"] {
        string pt_no PK
        string org_cd FK
        string pt_nm
    }
    tb_pt_cntc["tb_pt_cntc<br/>(환자 연락처)"] {
        string pt_no PK
        int cntc_seq PK
        string cntc_nm
    }
    tb_insr_pyr["tb_insr_pyr<br/>(보험자 마스터)"] {
        string pyr_cd PK
        string pyr_nm
    }
    tb_pt_insr["tb_pt_insr<br/>(환자 보험)"] {
        string pt_no PK
        string pyr_cd PK
        date eff_st_dt PK
    }
    tb_wd["tb_wd<br/>(병동 마스터)"] {
        string wd_cd PK
        string org_cd FK
        string dept_cd FK
    }
    tb_room["tb_room<br/>(병실 마스터)"] {
        string room_cd PK
        string wd_cd FK
        string dept_cd FK
    }

    tb_apnt["tb_apnt<br/>(예약 정보)"] {
        string apnt_no PK
        string org_cd FK
        string pt_no FK
        string dept_cd FK
        string dr_emp_no FK
    }
    tb_ckin["tb_ckin<br/>(체크인 정보)"] {
        string ckin_no PK
        string apnt_no FK
        string pt_no FK
    }
    tb_wait_q["tb_wait_q<br/>(대기열)"] {
        string wait_no PK
        string apnt_no FK
        string pt_no FK
        string dept_cd FK
    }
    tb_pt_ntf["tb_pt_ntf<br/>(환자 안내 알림)"] {
        string pt_ntf_no PK
        string pt_no FK
        string apnt_no FK
    }

    tb_enc["tb_enc<br/>(내원/진료 에피소드)"] {
        string enc_no PK
        string org_cd FK
        string pt_no FK
        string apnt_no FK
        string dept_cd FK
    }
    tb_adm["tb_adm<br/>(입원 정보)"] {
        string adm_no PK
        string enc_no FK
        string pt_no FK
        string room_cd FK
    }
    tb_chg_itm["tb_chg_itm<br/>(청구 항목 마스터)"] {
        string chg_cd PK
        string chg_nm
    }
    tb_enc_chg["tb_enc_chg<br/>(에피소드별 청구 내역)"] {
        string enc_no PK
        int chg_seq PK
        string chg_cd FK
    }
    tb_bill["tb_bill<br/>(수납 청구서)"] {
        string bill_no PK
        string enc_no FK
        string pt_no FK
    }
    tb_pay["tb_pay<br/>(수납 정보)"] {
        string pay_no PK
        string bill_no FK
    }
    tb_clm["tb_clm<br/>(보험 청구)"] {
        string clm_no PK
        string bill_no FK
        string pt_no FK
        string pyr_cd FK
        date eff_st_dt FK
    }

    tb_dx_mst["tb_dx_mst<br/>(진단 마스터)"] {
        string dx_cd PK
        string dx_nm
    }
    tb_med_mst["tb_med_mst<br/>(약품 마스터)"] {
        string med_cd PK
        string med_nm
    }
    tb_proc_mst["tb_proc_mst<br/>(처치/검사 오더 마스터)"] {
        string proc_cd PK
        string proc_nm
    }
    tb_vs["tb_vs<br/>(바이탈 사인)"] {
        string enc_no PK
        datetime msr_dtm PK
        string pt_no FK
    }
    tb_note["tb_note<br/>(진료 기록 노트)"] {
        string note_no PK
        string enc_no FK
        string pt_no FK
    }
    tb_enc_dx["tb_enc_dx<br/>(에피소드 진단)"] {
        string enc_no PK
        string dx_cd PK
        string dx_tp_cd PK
        string pt_no FK
    }
    tb_rx_ord["tb_rx_ord<br/>(투약 오더)"] {
        string ord_no PK
        string enc_no FK
        string pt_no FK
        string med_cd FK
    }
    tb_proc_ord["tb_proc_ord<br/>(처치 오더)"] {
        string ord_no PK
        string enc_no FK
        string pt_no FK
        string proc_cd FK
    }

    tb_spcm["tb_spcm<br/>(검체 정보)"] {
        string spcm_no PK
        string pt_no FK
        string enc_no FK
        string proc_ord_no FK
    }
    tb_lab_tst_mst["tb_lab_tst_mst<br/>(검사 항목 마스터)"] {
        string tst_cd PK
        string tst_nm
    }
    tb_lab_ord["tb_lab_ord<br/>(검사 오더)"] {
        string lab_ord_no PK
        string enc_no FK
        string pt_no FK
        string proc_ord_no FK
        string spcm_no FK
        string tst_cd FK
    }
    tb_lab_rslt["tb_lab_rslt<br/>(검사 결과)"] {
        string lab_ord_no PK
        int anl_seq PK
    }
    tb_img_exam_mst["tb_img_exam_mst<br/>(영상 검사 마스터)"] {
        string exam_cd PK
        string exam_nm
    }
    tb_img_ord["tb_img_ord<br/>(영상 오더)"] {
        string img_ord_no PK
        string enc_no FK
        string pt_no FK
        string proc_ord_no FK
        string exam_cd FK
    }
    tb_img_rslt["tb_img_rslt<br/>(영상 판독 결과)"] {
        string img_ord_no PK
        string rpt_st_cd
    }
    tb_dsps["tb_dsps<br/>(조제 정보)"] {
        string dsps_no PK
        string rx_ord_no FK
        string pt_no FK
    }

    tb_cd_grp ||--o{ tb_cd : has
    tb_org ||--o{ tb_dept : has
    tb_dept ||--o{ tb_dept : parent
    tb_org ||--o{ tb_emp : has
    tb_dept ||--o{ tb_emp : belongs
    tb_org ||--o{ tb_pt : has
    tb_pt ||--o{ tb_pt_cntc : has
    tb_insr_pyr ||--o{ tb_pt_insr : covers
    tb_pt ||--o{ tb_pt_insr : has
    tb_org ||--o{ tb_wd : has
    tb_dept ||--o{ tb_wd : belongs
    tb_wd ||--o{ tb_room : has
    tb_dept ||--o{ tb_room : belongs

    tb_pt ||--o{ tb_apnt : books
    tb_dept ||--o{ tb_apnt : receives
    tb_emp ||--o{ tb_apnt : attends
    tb_apnt ||--o{ tb_ckin : starts
    tb_pt ||--o{ tb_ckin : checks
    tb_apnt ||--o{ tb_wait_q : queues
    tb_pt ||--o{ tb_pt_ntf : notified

    tb_apnt ||--o{ tb_enc : converts
    tb_pt ||--o{ tb_enc : has
    tb_dept ||--o{ tb_enc : owns
    tb_enc ||--o{ tb_adm : admits
    tb_room ||--o{ tb_adm : assigned
    tb_chg_itm ||--o{ tb_enc_chg : billed
    tb_enc ||--o{ tb_enc_chg : charged
    tb_enc ||--o| tb_bill : billed
    tb_bill ||--o{ tb_pay : paid
    tb_bill ||--o{ tb_clm : claims
    tb_pt_insr ||--o{ tb_clm : uses

    tb_enc ||--o{ tb_vs : measures
    tb_enc ||--o{ tb_note : notes
    tb_dx_mst ||--o{ tb_enc_dx : diagnoses
    tb_enc ||--o{ tb_enc_dx : has
    tb_med_mst ||--o{ tb_rx_ord : orders
    tb_enc ||--o{ tb_rx_ord : has
    tb_proc_mst ||--o{ tb_proc_ord : orders
    tb_enc ||--o{ tb_proc_ord : has

    tb_proc_ord ||--o{ tb_spcm : produces
    tb_spcm ||--o{ tb_lab_ord : sampled
    tb_lab_tst_mst ||--o{ tb_lab_ord : ordered
    tb_lab_ord ||--o{ tb_lab_rslt : results
    tb_img_exam_mst ||--o{ tb_img_ord : ordered
    tb_img_ord ||--o| tb_img_rslt : results
    tb_rx_ord ||--o{ tb_dsps : dispensed
```
