# text.div
Generated Narrative: StructureMap vn-sm-bhyt-xml1-summary

map "http://fhir.hl7.org.vn/core/StructureMap/vn-sm-bhyt-xml1-summary" = "BHYTXML1SummaryLMStructureMap"

// Generated StructureMap scaffold for Bảng 1 tổng hợp KCB BHYT — Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML1SummaryLM.fsh` and remain aligned with the Python BHYT round-trip export adapter.

uses "http://fhir.hl7.org.vn/core/StructureDefinition/vn-core-bhyt-submission-bundle" alias BHYTSubmissionBundle as source // FHIR-native source bundle profile used by the repository round-trip adapter.
uses "http://fhir.hl7.org.vn/core/StructureDefinition/bhytXml1SummaryLm" alias BHYTXML1SummaryLM as target // Bảng 1 tổng hợp KCB BHYT — Logical Model

// Full QD 3176 XML1 field catalog. StructureMap/export rules must preserve source field names and financial semantics. Generated from logical-model `^mapping` annotations. Fields still missing a field-level `^mapping.map` entry remain outside this StructureMap and are tracked in `wiki/mappings/bhyt-output-data/machine/structuremap-coverage.json`.
group MapBHYTXML1SummaryLM(source sourceBundle : BHYTSubmissionBundle, target targetRow : BHYTXML1SummaryLM) {
  sourceBundle.entry as maLkSource -> targetRow.maLk "maLk"; // Target field: MA_LK - Mã liên kết hồ sơ FHIR path: VNCoreClaim.identifier[MALK].value
  sourceBundle.entry as sttSource -> targetRow.stt "stt"; // Target field: STT - Số thứ tự FHIR path: Derived export row order
  sourceBundle.entry as maBnSource -> targetRow.maBn "maBn"; // Target field: MA_BN - Mã người bệnh tại cơ sở FHIR path: VNCorePatient.identifier[MRN].value
  sourceBundle.entry as hoTenSource -> targetRow.hoTen "hoTen"; // Target field: HO_TEN - Họ tên người bệnh FHIR path: VNCorePatient.name.text
  sourceBundle.entry as ngaySinhSource -> targetRow.ngaySinh "ngaySinh"; // Target field: NGAY_SINH - Ngày sinh FHIR path: VNCorePatient.birthDate
  sourceBundle.entry as gioiTinhSource -> targetRow.gioiTinh "gioiTinh"; // Target field: GIOI_TINH - Giới tính FHIR path: VNCorePatient.gender
  sourceBundle.entry as maQuocTichSource -> targetRow.maQuocTich "maQuocTich"; // Target field: MA_QUOCTICH - Mã quốc tịch FHIR path: VNCorePatient.extension[nationality].valueCodeableConcept.coding.code
  sourceBundle.entry as maDanTocSource -> targetRow.maDanToc "maDanToc"; // Target field: MA_DANTOC - Mã dân tộc FHIR path: VNCorePatient.extension[ethnicity].valueCodeableConcept.coding.code
  sourceBundle.entry as maNgheNghiepSource -> targetRow.maNgheNghiep "maNgheNghiep"; // Target field: MA_NGHE_NGHIEP - Mã nghề nghiệp FHIR path: VNCorePatient.extension[occupation].valueCodeableConcept.coding.code
  sourceBundle.entry as diaChiSource -> targetRow.diaChi "diaChi"; // Target field: DIA_CHI - Địa chỉ FHIR path: VNCorePatient.address.text
  sourceBundle.entry as maTinhCuTruSource -> targetRow.maTinhCuTru "maTinhCuTru"; // Target field: MATINH_CU_TRU - Mã tỉnh cư trú FHIR path: VNCorePatient.address.extension[province].valueCodeableConcept.coding.code
  sourceBundle.entry as maHuyenCuTruSource -> targetRow.maHuyenCuTru "maHuyenCuTru"; // Target field: MAHUYEN_CU_TRU - Mã huyện cư trú legacy FHIR path: VNCorePatient.address.district
  sourceBundle.entry as maXaCuTruSource -> targetRow.maXaCuTru "maXaCuTru"; // Target field: MAXA_CU_TRU - Mã xã cư trú FHIR path: VNCorePatient.address.extension[ward].valueCodeableConcept.coding.code
  sourceBundle.entry as dienThoaiSource -> targetRow.dienThoai "dienThoai"; // Target field: DIEN_THOAI - Số điện thoại FHIR path: VNCorePatient.telecom.where(system='phone').value
  sourceBundle.entry as maTheBhytSource -> targetRow.maTheBhyt "maTheBhyt"; // Target field: MA_THE_BHYT - Mã thẻ BHYT FHIR path: VNCoreCoverage.identifier[BHYT].value | VNCorePatient.identifier[BHYT].value Mapping note: OHP/QD3176 export validator permits up to 2 BHYT card values; map repeated cards to focal/supplemental Coverage entries.
  sourceBundle.entry as maDkbdSource -> targetRow.maDkbd "maDkbd"; // Target field: MA_DKBD - Mã nơi đăng ký KCB ban đầu FHIR path: VNCoreCoverage.extension[primaryCareFacility].valueReference.identifier.value Mapping note: OHP/QD3176 export validator permits up to 2 values aligned with multiple BHYT cards; this remains the registered primary care facility, not MA_CSKCB.
  sourceBundle.entry as gtTheTuSource -> targetRow.gtTheTu "gtTheTu"; // Target field: GT_THE_TU - Giá trị thẻ từ ngày FHIR path: VNCoreCoverage.period.start Mapping note: OHP/QD3176 export validator permits up to 2 values aligned with multiple BHYT cards.
  sourceBundle.entry as gtTheDenSource -> targetRow.gtTheDen "gtTheDen"; // Target field: GT_THE_DEN - Giá trị thẻ đến ngày FHIR path: VNCoreCoverage.period.end Mapping note: OHP/QD3176 export validator permits up to 2 values aligned with multiple BHYT cards.
  sourceBundle.entry as lyDoVvSource -> targetRow.lyDoVv "lyDoVv"; // Target field: LY_DO_VV - Lý do vào viện FHIR path: VNCoreEncounter.reasonCode | VNCoreEncounter.reasonReference.resolve().code
  sourceBundle.entry as lyDoVntSource -> targetRow.lyDoVnt "lyDoVnt"; // Target field: LY_DO_VNT - Lý do vào nội trú FHIR path: VNCoreEncounter.hospitalization.admitSource | VNCoreEncounter.reasonCode Mapping note: Conditionally required for selected inpatient/day-treatment MA_LOAI_KCB values.
  sourceBundle.entry as maLyDoVntSource -> targetRow.maLyDoVnt "maLyDoVnt"; // Target field: MA_LY_DO_VNT - Mã lý do vào nội trú FHIR path: VNCoreEncounter.hospitalization.admitSource.coding.code
  sourceBundle.entry as chanDoanVaoSource -> targetRow.chanDoanVao "chanDoanVao"; // Target field: CHAN_DOAN_VAO - Chẩn đoán vào viện FHIR path: VNCoreEncounter.reasonCode | VNCoreComposition.section[chiefComplaint].text
  sourceBundle.entry as chanDoanRvSource -> targetRow.chanDoanRv "chanDoanRv"; // Target field: CHAN_DOAN_RV - Chẩn đoán ra viện FHIR path: VNCoreCondition.code.text | VNCoreComposition.section[diagnosis].text
  sourceBundle.entry as maBenhChinhSource -> targetRow.maBenhChinh "maBenhChinh"; // Target field: MA_BENH_CHINH - Mã bệnh chính FHIR path: VNCoreClaim.diagnosis.where(type='principal').diagnosisCodeableConcept | VNCoreCondition.code
  sourceBundle.entry as maBenhKtSource -> targetRow.maBenhKt "maBenhKt"; // Target field: MA_BENH_KT - Mã bệnh kèm theo FHIR path: VNCoreClaim.diagnosis.where(type!='principal').diagnosisCodeableConcept | VNCoreCondition.code
  sourceBundle.entry as maBenhYhctSource -> targetRow.maBenhYhct "maBenhYhct"; // Target field: MA_BENH_YHCT - Mã bệnh y học cổ truyền FHIR path: VNCoreClaim.diagnosis.diagnosisCodeableConcept.coding[yhct].code | VNCoreCondition.code.coding[yhct].code
  sourceBundle.entry as maPtttQtSource -> targetRow.maPtttQt "maPtttQt"; // Target field: MA_PTTT_QT - Mã phương thức thanh toán FHIR path: VNCoreClaim.extension[paymentMethod].valueCodeableConcept.coding.code
  sourceBundle.entry as maDoituongKcbSource -> targetRow.maDoituongKcb "maDoituongKcb"; // Target field: MA_DOITUONG_KCB - Mã đối tượng đến KCB FHIR path: VNCoreClaim.subType Mapping note: Do not map to Coverage.extension[bhytCardType]; this is visit classification, not the insured/card group.
  sourceBundle.entry as maNoiDiSource -> targetRow.maNoiDi "maNoiDi"; // Target field: MA_NOI_DI - Mã nơi đi FHIR path: VNCoreEncounter.hospitalization.origin.resolve().identifier[CSKCB].value
  sourceBundle.entry as maNoiDenSource -> targetRow.maNoiDen "maNoiDen"; // Target field: MA_NOI_DEN - Mã nơi đến FHIR path: VNCoreEncounter.hospitalization.destination.resolve().identifier[CSKCB].value
  sourceBundle.entry as maTaiNanSource -> targetRow.maTaiNan "maTaiNan"; // Target field: MA_TAI_NAN - Mã tai nạn FHIR path: VNCoreClaim.accident.type
  sourceBundle.entry as ngayVaoSource -> targetRow.ngayVao "ngayVao"; // Target field: NGAY_VAO - Ngày vào theo định dạng yyyyMMddHHmm FHIR path: VNCoreEncounter.period.start | VNCoreClaim.created
  sourceBundle.entry as ngayVaoNoiTruSource -> targetRow.ngayVaoNoiTru "ngayVaoNoiTru"; // Target field: NGAY_VAO_NOI_TRU - Ngày vào nội trú FHIR path: VNCoreEncounter.hospitalization | future admission instant extension
  sourceBundle.entry as ngayRaSource -> targetRow.ngayRa "ngayRa"; // Target field: NGAY_RA - Ngày ra theo định dạng yyyyMMddHHmm FHIR path: VNCoreEncounter.period.end | VNCoreClaim.created
  sourceBundle.entry as soNgayDtriSource -> targetRow.soNgayDtri "soNgayDtri"; // Target field: SO_NGAY_DTRI - Số ngày điều trị FHIR path: Derived from VNCoreEncounter.period.start/end | VNCoreEncounter.length.value
  sourceBundle.entry as ketQuaDtriSource -> targetRow.ketQuaDtri "ketQuaDtri"; // Target field: KET_QUA_DTRI - Kết quả điều trị FHIR path: VNCoreEncounter.extension[treatmentOutcome].valueCodeableConcept
  sourceBundle.entry as maLoaiRvSource -> targetRow.maLoaiRv "maLoaiRv"; // Target field: MA_LOAI_RV - Mã loại ra viện FHIR path: VNCoreEncounter.hospitalization.dischargeDisposition
  sourceBundle.entry as ngayTtoanSource -> targetRow.ngayTtoan "ngayTtoan"; // Target field: NGAY_TTOAN - Ngày thanh toán FHIR path: VNCoreExplanationOfBenefit.created | VNCoreClaimResponse.created
  sourceBundle.entry as tThuocSource -> targetRow.tThuoc "tThuoc"; // Target field: T_THUOC - Tổng tiền thuốc FHIR path: VNCoreClaim.extension[costSummary].extension[totalMedication].valueMoney.value | VNCoreExplanationOfBenefit.extension[costSummary].extension[totalMedication].valueMoney.value
  sourceBundle.entry as tVtytSource -> targetRow.tVtyt "tVtyt"; // Target field: T_VTYT - Tổng tiền vật tư y tế FHIR path: VNCoreClaim.extension[costSummary].extension[totalSupplies].valueMoney.value | VNCoreExplanationOfBenefit.extension[costSummary].extension[totalSupplies].valueMoney.value
  sourceBundle.entry as tTongchiBvSource -> targetRow.tTongchiBv "tTongchiBv"; // Target field: T_TONGCHI_BV - Tổng chi phí bệnh viện FHIR path: VNCoreClaim.total.value | VNCoreExplanationOfBenefit.total.amount
  sourceBundle.entry as tTongchiBhSource -> targetRow.tTongchiBh "tTongchiBh"; // Target field: T_TONGCHI_BH - Tổng chi phí thuộc phạm vi BHYT FHIR path: VNCoreExplanationOfBenefit.total.where(category='eligible').amount.value | VNCoreClaimResponse.total.where(category='eligible').amount.value
  sourceBundle.entry as tBnttSource -> targetRow.tBntt "tBntt"; // Target field: T_BNTT - Người bệnh tự trả FHIR path: VNCoreClaim.extension[costSummary].extension[totalPatientSelfPay].valueMoney.value | Derived from VNCoreClaimResponse.total.where(category='submitted').amount - .where(category='eligible').amount
  sourceBundle.entry as tBncctSource -> targetRow.tBncct "tBncct"; // Target field: T_BNCCT - Người bệnh cùng chi trả FHIR path: VNCoreClaim.extension[costSummary].extension[totalPatientCopay].valueMoney.value | VNCoreClaimResponse.total.where(category='copay').amount.value | VNCoreExplanationOfBenefit.total.where(category='copay').amount.value
  sourceBundle.entry as tBhttSource -> targetRow.tBhtt "tBhtt"; // Target field: T_BHTT - Quỹ BHYT thanh toán FHIR path: VNCoreClaim.extension[costSummary].extension[totalInsurance].valueMoney.value | VNCoreClaimResponse.total.where(category='benefit').amount.value | VNCoreExplanationOfBenefit.total.where(category='benefit').amount.value
  sourceBundle.entry as tNguonkhacSource -> targetRow.tNguonkhac "tNguonkhac"; // Target field: T_NGUONKHAC - Nguồn khác FHIR path: VNCoreClaim.extension[costSummary].extension[totalOtherFund].valueMoney.value | VNCoreExplanationOfBenefit.extension[costSummary].extension[totalOtherFund].valueMoney.value
  sourceBundle.entry as namQtSource -> targetRow.namQt "namQt"; // Target field: NAM_QT - Năm quyết toán FHIR path: VNCoreClaim.extension[paymentPeriod].extension[year]
  sourceBundle.entry as thangQtSource -> targetRow.thangQt "thangQt"; // Target field: THANG_QT - Tháng quyết toán FHIR path: VNCoreClaim.extension[paymentPeriod].extension[month]
  sourceBundle.entry as maLoaiKcbSource -> targetRow.maLoaiKcb "maLoaiKcb"; // Target field: MA_LOAI_KCB - Mã loại khám chữa bệnh FHIR path: VNCoreEncounter.type
  sourceBundle.entry as maKhoaSource -> targetRow.maKhoa "maKhoa"; // Target field: MA_KHOA - Mã khoa FHIR path: VNCoreClaim.item.extension[department].valueCodeableConcept.coding.code | VNCoreEncounter.serviceType
  sourceBundle.entry as maCskcbSource -> targetRow.maCskcb "maCskcb"; // Target field: MA_CSKCB - Mã cơ sở khám chữa bệnh FHIR path: VNCoreEncounter.serviceProvider.resolve().identifier[CSKCB].value | VNCoreClaim.provider.resolve().identifier[CSKCB].value Mapping note: Actual visit/submission provider. Do not fall back to MA_DKBD on Coverage.
  sourceBundle.entry as canNangSource -> targetRow.canNang "canNang"; // Target field: CAN_NANG - Cân nặng FHIR path: VNCoreObservationBodyWeight.valueQuantity.value
  sourceBundle.entry as ngayTaiKhamSource -> targetRow.ngayTaiKham "ngayTaiKham"; // Target field: NGAY_TAI_KHAM - Ngày tái khám FHIR path: VNCoreServiceRequest.occurrenceDateTime | Appointment.start
  sourceBundle.entry as maHsbaSource -> targetRow.maHsba "maHsba"; // Target field: MA_HSBA - Mã hồ sơ bệnh án FHIR path: VNCoreComposition.identifier.value | VNCoreDocumentReference.identifier.value
  sourceBundle.entry as maTtdvSource -> targetRow.maTtdv "maTtdv"; // Target field: MA_TTDV - Mã thủ trưởng đơn vị/người ký FHIR path: VNCoreComposition.author.resolve().identifier.value | VNCoreDocumentReference.author.resolve().identifier.value | VNCoreProvenance.signature.who.resolve().identifier.value
}

# title
Bảng 1 tổng hợp KCB BHYT — Logical Model — StructureMap

# publisher
Omi HealthTech / VN Core FHIR Community Initiative

# contact[].name
Omi HealthTech / VN Core FHIR Community Initiative

# description
Generated StructureMap scaffold for Bảng 1 tổng hợp KCB BHYT — Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML1SummaryLM.fsh` and remain aligned with the Python BHYT round-trip export adapter.

# purpose
Publish canonical, reviewable FHIR-to-BHYT XML mapping artifacts for XML1-XML12 without duplicating field-level mapping semantics across FSH, wiki, and export code.

# structure[].documentation
FHIR-native source bundle profile used by the repository round-trip adapter.

# structure[].documentation
Bảng 1 tổng hợp KCB BHYT — Logical Model

# group[].documentation
Full QD 3176 XML1 field catalog. StructureMap/export rules must preserve source field names and financial semantics. Generated from logical-model `^mapping` annotations. Fields still missing a field-level `^mapping.map` entry remain outside this StructureMap and are tracked in `wiki/mappings/bhyt-output-data/machine/structuremap-coverage.json`.

# group[].input[].documentation
Bảng 1 tổng hợp KCB BHYT — Logical Model

# group[].rule[].documentation
Target field: MA_LK - Mã liên kết hồ sơ FHIR path: VNCoreClaim.identifier[MALK].value

# group[].rule[].documentation
Target field: STT - Số thứ tự FHIR path: Derived export row order

# group[].rule[].documentation
Target field: MA_BN - Mã người bệnh tại cơ sở FHIR path: VNCorePatient.identifier[MRN].value

# group[].rule[].documentation
Target field: HO_TEN - Họ tên người bệnh FHIR path: VNCorePatient.name.text

# group[].rule[].documentation
Target field: NGAY_SINH - Ngày sinh FHIR path: VNCorePatient.birthDate

# group[].rule[].documentation
Target field: GIOI_TINH - Giới tính FHIR path: VNCorePatient.gender

# group[].rule[].documentation
Target field: DIA_CHI - Địa chỉ FHIR path: VNCorePatient.address.text

# group[].rule[].documentation
Target field: MAHUYEN_CU_TRU - Mã huyện cư trú legacy FHIR path: VNCorePatient.address.district

# group[].rule[].documentation
Target field: DIEN_THOAI - Số điện thoại FHIR path: VNCorePatient.telecom.where(system='phone').value

# group[].rule[].documentation
Target field: MA_THE_BHYT - Mã thẻ BHYT FHIR path: VNCoreCoverage.identifier[BHYT].value | VNCorePatient.identifier[BHYT].value Mapping note: OHP/QD3176 export validator permits up to 2 BHYT card values; map repeated cards to focal/supplemental Coverage entries.

# group[].rule[].documentation
Target field: MA_DKBD - Mã nơi đăng ký KCB ban đầu FHIR path: VNCoreCoverage.extension[primaryCareFacility].valueReference.identifier.value Mapping note: OHP/QD3176 export validator permits up to 2 values aligned with multiple BHYT cards; this remains the registered primary care facility, not MA_CSKCB.

# group[].rule[].documentation
Target field: GT_THE_TU - Giá trị thẻ từ ngày FHIR path: VNCoreCoverage.period.start Mapping note: OHP/QD3176 export validator permits up to 2 values aligned with multiple BHYT cards.

# group[].rule[].documentation
Target field: GT_THE_DEN - Giá trị thẻ đến ngày FHIR path: VNCoreCoverage.period.end Mapping note: OHP/QD3176 export validator permits up to 2 values aligned with multiple BHYT cards.

# group[].rule[].documentation
Target field: LY_DO_VV - Lý do vào viện FHIR path: VNCoreEncounter.reasonCode | VNCoreEncounter.reasonReference.resolve().code

# group[].rule[].documentation
Target field: LY_DO_VNT - Lý do vào nội trú FHIR path: VNCoreEncounter.hospitalization.admitSource | VNCoreEncounter.reasonCode Mapping note: Conditionally required for selected inpatient/day-treatment MA_LOAI_KCB values.

# group[].rule[].documentation
Target field: MA_LY_DO_VNT - Mã lý do vào nội trú FHIR path: VNCoreEncounter.hospitalization.admitSource.coding.code

# group[].rule[].documentation
Target field: CHAN_DOAN_VAO - Chẩn đoán vào viện FHIR path: VNCoreEncounter.reasonCode | VNCoreComposition.section[chiefComplaint].text

# group[].rule[].documentation
Target field: CHAN_DOAN_RV - Chẩn đoán ra viện FHIR path: VNCoreCondition.code.text | VNCoreComposition.section[diagnosis].text

# group[].rule[].documentation
Target field: MA_DOITUONG_KCB - Mã đối tượng đến KCB FHIR path: VNCoreClaim.subType Mapping note: Do not map to Coverage.extension[bhytCardType]; this is visit classification, not the insured/card group.

# group[].rule[].documentation
Target field: MA_TAI_NAN - Mã tai nạn FHIR path: VNCoreClaim.accident.type

# group[].rule[].documentation
Target field: NGAY_VAO - Ngày vào theo định dạng yyyyMMddHHmm FHIR path: VNCoreEncounter.period.start | VNCoreClaim.created

# group[].rule[].documentation
Target field: NGAY_VAO_NOI_TRU - Ngày vào nội trú FHIR path: VNCoreEncounter.hospitalization | future admission instant extension

# group[].rule[].documentation
Target field: NGAY_RA - Ngày ra theo định dạng yyyyMMddHHmm FHIR path: VNCoreEncounter.period.end | VNCoreClaim.created

# group[].rule[].documentation
Target field: SO_NGAY_DTRI - Số ngày điều trị FHIR path: Derived from VNCoreEncounter.period.start/end | VNCoreEncounter.length.value

# group[].rule[].documentation
Target field: MA_LOAI_RV - Mã loại ra viện FHIR path: VNCoreEncounter.hospitalization.dischargeDisposition

# group[].rule[].documentation
Target field: NGAY_TTOAN - Ngày thanh toán FHIR path: VNCoreExplanationOfBenefit.created | VNCoreClaimResponse.created

# group[].rule[].documentation
Target field: T_TONGCHI_BV - Tổng chi phí bệnh viện FHIR path: VNCoreClaim.total.value | VNCoreExplanationOfBenefit.total.amount

# group[].rule[].documentation
Target field: NAM_QT - Năm quyết toán FHIR path: VNCoreClaim.extension[paymentPeriod].extension[year]

# group[].rule[].documentation
Target field: THANG_QT - Tháng quyết toán FHIR path: VNCoreClaim.extension[paymentPeriod].extension[month]

# group[].rule[].documentation
Target field: MA_LOAI_KCB - Mã loại khám chữa bệnh FHIR path: VNCoreEncounter.type

# group[].rule[].documentation
Target field: MA_CSKCB - Mã cơ sở khám chữa bệnh FHIR path: VNCoreEncounter.serviceProvider.resolve().identifier[CSKCB].value | VNCoreClaim.provider.resolve().identifier[CSKCB].value Mapping note: Actual visit/submission provider. Do not fall back to MA_DKBD on Coverage.

# group[].rule[].documentation
Target field: CAN_NANG - Cân nặng FHIR path: VNCoreObservationBodyWeight.valueQuantity.value

# group[].rule[].documentation
Target field: NGAY_TAI_KHAM - Ngày tái khám FHIR path: VNCoreServiceRequest.occurrenceDateTime | Appointment.start

# group[].rule[].documentation
Target field: MA_HSBA - Mã hồ sơ bệnh án FHIR path: VNCoreComposition.identifier.value | VNCoreDocumentReference.identifier.value