# text.div
Generated Narrative: StructureMap vn-sm-bhyt-xml3-service

map "http://fhir.hl7.org.vn/core/StructureMap/vn-sm-bhyt-xml3-service" = "BHYTXML3ServiceLMStructureMap"

// Generated StructureMap scaffold for Bảng 3 DVKT và vật tư BHYT — Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML3ServiceLM.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/bhytXml3ServiceLm" alias BHYTXML3ServiceLM as target // Bảng 3 DVKT và vật tư BHYT — Logical Model

// Full QD 3176 XML3 field catalog. Rows are derived from non-medication service, supply, device, procedure, and bed-day claim items. 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 MapBHYTXML3ServiceLM(source sourceBundle : BHYTSubmissionBundle, target targetRow : BHYTXML3ServiceLM) {
  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ự dòng FHIR path: VNCoreClaim.item.where(category!='8').sequence
  sourceBundle.entry as maDichVuSource -> targetRow.maDichVu "maDichVu"; // Target field: MA_DICH_VU - Mã dịch vụ kỹ thuật FHIR path: VNCoreClaim.item.where(category!='8').productOrService.coding.code | VNCoreServiceRequest.code.coding.code Mapping note: Conditionally required when MA_VAT_TU is absent or MA_NHOM is not 10.
  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 | VNCoreClaim.item.extension[paymentMethod].valueCodeableConcept.coding.code
  sourceBundle.entry as maVatTuSource -> targetRow.maVatTu "maVatTu"; // Target field: MA_VAT_TU - Mã vật tư y tế FHIR path: VNCoreDevice.identifier[medicalDeviceItemCode].value | VNCoreClaim.item.where(category!='8').productOrService.coding.code Mapping note: Conditionally required when MA_DICH_VU is absent or MA_NHOM=10; do not collapse medical supplies into service codes when Device is available.
  sourceBundle.entry as maNhomSource -> targetRow.maNhom "maNhom"; // Target field: MA_NHOM - Mã nhóm chi phí theo QĐ 3176 FHIR path: ConceptMap/vn-cm-qd3176-cost-group-to-q697-cost-category -> VNCoreClaim.item.where(category!='8').category.coding.code Mapping note: Source code system is QD 3176 MA_NHOM. Export/import must bridge through the ConceptMap instead of assigning the QD 697 target code directly.
  sourceBundle.entry as tenVatTuSource -> targetRow.tenVatTu "tenVatTu"; // Target field: TEN_VAT_TU - Tên vật tư y tế FHIR path: VNCoreDevice.deviceName.name | VNCoreClaim.item.where(category!='8').productOrService.text | display
  sourceBundle.entry as tenDichVuSource -> targetRow.tenDichVu "tenDichVu"; // Target field: TEN_DICH_VU - Tên dịch vụ kỹ thuật FHIR path: VNCoreClaim.item.where(category!='8').productOrService.text | VNCoreServiceRequest.code.text | display
  sourceBundle.entry as donViTinhSource -> targetRow.donViTinh "donViTinh"; // Target field: DON_VI_TINH - Đơn vị tính FHIR path: VNCoreClaim.item.where(category!='8').quantity.unit
  sourceBundle.entry as phamViSource -> targetRow.phamVi "phamVi"; // Target field: PHAM_VI - Phạm vi thanh toán FHIR path: VNCoreClaim.item.where(category!='8').extension[insuranceCostInfo].extension[scope].valueCodeableConcept
  sourceBundle.entry as soLuongSource -> targetRow.soLuong "soLuong"; // Target field: SO_LUONG - Số lượng FHIR path: VNCoreClaim.item.where(category!='8').quantity.value
  sourceBundle.entry as donGiaBvSource -> targetRow.donGiaBv "donGiaBv"; // Target field: DON_GIA_BV - Đơn giá bệnh viện FHIR path: VNCoreClaim.item.where(category!='8').unitPrice.value | VNCoreClaim.item.extension[hospitalUnitPrice].valueMoney.value Mapping note: Hospital charge price; keep separate from the BHYT price to avoid financial round-trip loss.
  sourceBundle.entry as donGiaBhSource -> targetRow.donGiaBh "donGiaBh"; // Target field: DON_GIA_BH - Đơn giá BHYT FHIR path: VNCoreClaim.item.where(category!='8').extension[insuranceCostInfo].extension[insuranceUnitPrice].valueMoney.value Mapping note: BHYT-covered unit price; do not collapse into Claim.item.unitPrice when hospital and insurance prices differ.
  sourceBundle.entry as tyleTtDvSource -> targetRow.tyleTtDv "tyleTtDv"; // Target field: TYLE_TT_DV - Tỷ lệ thanh toán dịch vụ FHIR path: VNCoreClaim.item.where(category!='8').extension[insuranceCostInfo].extension[servicePaymentRatio].valueDecimal
  sourceBundle.entry as tyleTtBhSource -> targetRow.tyleTtBh "tyleTtBh"; // Target field: TYLE_TT_BH - Tỷ lệ thanh toán BHYT FHIR path: VNCoreClaim.item.where(category!='8').extension[insuranceCostInfo].extension[paymentRatio].valueDecimal
  sourceBundle.entry as thanhTienBvSource -> targetRow.thanhTienBv "thanhTienBv"; // Target field: THANH_TIEN_BV - Thành tiền bệnh viện FHIR path: VNCoreClaim.item.where(category!='8').net.value | VNCoreClaim.item.extension[hospitalLineAmount].valueMoney.value Mapping note: Hospital line amount; keep separate from BHYT line amount.
  sourceBundle.entry as thanhTienBhSource -> targetRow.thanhTienBh "thanhTienBh"; // Target field: THANH_TIEN_BH - Thành tiền BHYT FHIR path: VNCoreClaim.item.where(category!='8').extension[insuranceCostInfo].extension[insuranceLineAmount].valueMoney.value
  sourceBundle.entry as mucHuongSource -> targetRow.mucHuong "mucHuong"; // Target field: MUC_HUONG - Mức hưởng FHIR path: VNCoreClaim.item.where(category!='8').extension[insuranceCostInfo].extension[benefitLevel].valueDecimal
  sourceBundle.entry as tBnttSource -> targetRow.tBntt "tBntt"; // Target field: T_BNTT - Người bệnh tự trả FHIR path: Derived from VNCoreClaimResponse.item[serviceLine].adjudication.where(category='submitted').amount - .where(category='eligible').amount | Derived from VNCoreExplanationOfBenefit.item[serviceLine].adjudication.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: VNCoreClaimResponse.item[serviceLine].adjudication.where(category='copay').amount.value | VNCoreExplanationOfBenefit.item[serviceLine].adjudication.where(category='copay').amount.value
  sourceBundle.entry as tBhttSource -> targetRow.tBhtt "tBhtt"; // Target field: T_BHTT - Quỹ BHYT thanh toán FHIR path: VNCoreClaimResponse.item[serviceLine].adjudication.where(category='benefit').amount.value | VNCoreExplanationOfBenefit.item[serviceLine].adjudication.where(category='benefit').amount.value
  sourceBundle.entry as maKhoaSource -> targetRow.maKhoa "maKhoa"; // Target field: MA_KHOA - Mã khoa FHIR path: VNCoreClaim.item.where(category!='8').extension[department].valueCodeableConcept.coding.code
  sourceBundle.entry as maGiuongSource -> targetRow.maGiuong "maGiuong"; // Target field: MA_GIUONG - Mã giường FHIR path: VNCoreEncounter.location.location.resolve().identifier.value Mapping note: Conditionally required for bed-day MA_NHOM values 14, 15, 16.
  sourceBundle.entry as maBacSiSource -> targetRow.maBacSi "maBacSi"; // Target field: MA_BAC_SI - Mã bác sĩ FHIR path: VNCoreServiceRequest.requester.resolve().identifier.value | VNCoreProcedure.performer.actor.resolve().identifier.value | VNCorePractitioner.identifier.value
  sourceBundle.entry as nguoiThucHienSource -> targetRow.nguoiThucHien "nguoiThucHien"; // Target field: NGUOI_THUC_HIEN - Người thực hiện FHIR path: VNCoreProcedure.performer.actor.resolve().identifier.value | VNCorePractitioner.identifier.value
  sourceBundle.entry as maBenhSource -> targetRow.maBenh "maBenh"; // Target field: MA_BENH - Mã bệnh liên quan FHIR path: VNCoreCondition.code | VNCoreClaim.diagnosis.diagnosisCodeableConcept
  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 ngayYlSource -> targetRow.ngayYl "ngayYl"; // Target field: NGAY_YL - Ngày y lệnh FHIR path: VNCoreServiceRequest.authoredOn | VNCoreProcedure.basedOn.resolve().authoredOn
  sourceBundle.entry as ngayThYlSource -> targetRow.ngayThYl "ngayThYl"; // Target field: NGAY_TH_YL - Ngày thực hiện y lệnh FHIR path: VNCoreProcedure.performedDateTime | VNCoreServiceRequest.occurrenceDateTime
  sourceBundle.entry as ngayKqSource -> targetRow.ngayKq "ngayKq"; // Target field: NGAY_KQ - Ngày kết quả FHIR path: VNCoreDiagnosticReport.issued | VNCoreObservationLab.effectiveDateTime Mapping note: Conditionally required except for bed-day MA_NHOM values 14, 15, 16.
  sourceBundle.entry as maPtttSource -> targetRow.maPttt "maPttt"; // Target field: MA_PTTT - Mã phẫu thuật/thủ thuật FHIR path: VNCoreClaim.procedure.procedureCodeableConcept | VNCoreProcedure.code
  sourceBundle.entry as vetThuongTpSource -> targetRow.vetThuongTp "vetThuongTp"; // Target field: VET_THUONG_TP - Vết thương tái phát FHIR path: VNCoreClaim.item[serviceLine].extension[recurrentWoundBenefit].valueBoolean | VNCoreExplanationOfBenefit.item[serviceLine].extension[recurrentWoundBenefit].valueBoolean Mapping note: Exporter emits literal `1` only when the line-level recurrentWoundBenefit flag is true; this is not a diagnosis recurrence code.
  sourceBundle.entry as viTriThDvktSource -> targetRow.viTriThDvkt "viTriThDvkt"; // Target field: VI_TRI_TH_DVKT - Vị trí thực hiện DVKT FHIR path: VNCoreProcedure.bodySite | VNCoreServiceRequest.bodySite
  sourceBundle.entry as maMaySource -> targetRow.maMay "maMay"; // Target field: MA_MAY - Mã máy FHIR path: VNCoreDevice.identifier.value
  sourceBundle.entry as maHieuSpSource -> targetRow.maHieuSp "maHieuSp"; // Target field: MA_HIEU_SP - Mã hiệu sản phẩm FHIR path: VNCoreDevice.deviceName.name | VNCoreDevice.modelNumber
  sourceBundle.entry as taiSuDungSource -> targetRow.taiSuDung "taiSuDung"; // Target field: TAI_SU_DUNG - Tái sử dụng FHIR path: VNCoreDeviceUseStatement.note | future reusable-device extension
}

# title
Bảng 3 DVKT và vật tư 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 3 DVKT và vật tư BHYT — Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML3ServiceLM.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 3 DVKT và vật tư BHYT — Logical Model

# group[].documentation
Full QD 3176 XML3 field catalog. Rows are derived from non-medication service, supply, device, procedure, and bed-day claim items. 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 3 DVKT và vật tư 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ự dòng FHIR path: VNCoreClaim.item.where(category!='8').sequence

# group[].rule[].documentation
Target field: MA_DICH_VU - Mã dịch vụ kỹ thuật FHIR path: VNCoreClaim.item.where(category!='8').productOrService.coding.code | VNCoreServiceRequest.code.coding.code Mapping note: Conditionally required when MA_VAT_TU is absent or MA_NHOM is not 10.

# group[].rule[].documentation
Target field: MA_VAT_TU - Mã vật tư y tế FHIR path: VNCoreDevice.identifier[medicalDeviceItemCode].value | VNCoreClaim.item.where(category!='8').productOrService.coding.code Mapping note: Conditionally required when MA_DICH_VU is absent or MA_NHOM=10; do not collapse medical supplies into service codes when Device is available.

# group[].rule[].documentation
Target field: MA_NHOM - Mã nhóm chi phí theo QĐ 3176 FHIR path: ConceptMap/vn-cm-qd3176-cost-group-to-q697-cost-category -> VNCoreClaim.item.where(category!='8').category.coding.code Mapping note: Source code system is QD 3176 MA_NHOM. Export/import must bridge through the ConceptMap instead of assigning the QD 697 target code directly.

# group[].rule[].documentation
Target field: TEN_VAT_TU - Tên vật tư y tế FHIR path: VNCoreDevice.deviceName.name | VNCoreClaim.item.where(category!='8').productOrService.text | display

# group[].rule[].documentation
Target field: TEN_DICH_VU - Tên dịch vụ kỹ thuật FHIR path: VNCoreClaim.item.where(category!='8').productOrService.text | VNCoreServiceRequest.code.text | display

# group[].rule[].documentation
Target field: DON_VI_TINH - Đơn vị tính FHIR path: VNCoreClaim.item.where(category!='8').quantity.unit

# group[].rule[].documentation
Target field: DON_GIA_BV - Đơn giá bệnh viện FHIR path: VNCoreClaim.item.where(category!='8').unitPrice.value | VNCoreClaim.item.extension[hospitalUnitPrice].valueMoney.value Mapping note: Hospital charge price; keep separate from the BHYT price to avoid financial round-trip loss.

# group[].rule[].documentation
Target field: DON_GIA_BH - Đơn giá BHYT FHIR path: VNCoreClaim.item.where(category!='8').extension[insuranceCostInfo].extension[insuranceUnitPrice].valueMoney.value Mapping note: BHYT-covered unit price; do not collapse into Claim.item.unitPrice when hospital and insurance prices differ.

# group[].rule[].documentation
Target field: THANH_TIEN_BV - Thành tiền bệnh viện FHIR path: VNCoreClaim.item.where(category!='8').net.value | VNCoreClaim.item.extension[hospitalLineAmount].valueMoney.value Mapping note: Hospital line amount; keep separate from BHYT line amount.

# group[].rule[].documentation
Target field: MA_GIUONG - Mã giường FHIR path: VNCoreEncounter.location.location.resolve().identifier.value Mapping note: Conditionally required for bed-day MA_NHOM values 14, 15, 16.

# group[].rule[].documentation
Target field: MA_BENH - Mã bệnh liên quan FHIR path: VNCoreCondition.code | VNCoreClaim.diagnosis.diagnosisCodeableConcept

# group[].rule[].documentation
Target field: NGAY_YL - Ngày y lệnh FHIR path: VNCoreServiceRequest.authoredOn | VNCoreProcedure.basedOn.resolve().authoredOn

# group[].rule[].documentation
Target field: NGAY_TH_YL - Ngày thực hiện y lệnh FHIR path: VNCoreProcedure.performedDateTime | VNCoreServiceRequest.occurrenceDateTime

# group[].rule[].documentation
Target field: NGAY_KQ - Ngày kết quả FHIR path: VNCoreDiagnosticReport.issued | VNCoreObservationLab.effectiveDateTime Mapping note: Conditionally required except for bed-day MA_NHOM values 14, 15, 16.

# group[].rule[].documentation
Target field: MA_PTTT - Mã phẫu thuật/thủ thuật FHIR path: VNCoreClaim.procedure.procedureCodeableConcept | VNCoreProcedure.code

# group[].rule[].documentation
Target field: VET_THUONG_TP - Vết thương tái phát FHIR path: VNCoreClaim.item[serviceLine].extension[recurrentWoundBenefit].valueBoolean | VNCoreExplanationOfBenefit.item[serviceLine].extension[recurrentWoundBenefit].valueBoolean Mapping note: Exporter emits literal `1` only when the line-level recurrentWoundBenefit flag is true; this is not a diagnosis recurrence code.

# group[].rule[].documentation
Target field: VI_TRI_TH_DVKT - Vị trí thực hiện DVKT FHIR path: VNCoreProcedure.bodySite | VNCoreServiceRequest.bodySite

# group[].rule[].documentation
Target field: MA_MAY - Mã máy FHIR path: VNCoreDevice.identifier.value

# group[].rule[].documentation
Target field: MA_HIEU_SP - Mã hiệu sản phẩm FHIR path: VNCoreDevice.deviceName.name | VNCoreDevice.modelNumber

# group[].rule[].documentation
Target field: TAI_SU_DUNG - Tái sử dụng FHIR path: VNCoreDeviceUseStatement.note | future reusable-device extension