# text.div
Generated Narrative: StructureMap vn-sm-bhyt-xml2-medication

map "http://fhir.hl7.org.vn/core/StructureMap/vn-sm-bhyt-xml2-medication" = "BHYTXML2MedicationLMStructureMap"

// Generated StructureMap scaffold for Bảng 2 thuốc BHYT — Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML2MedicationLM.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/bhytXml2MedicationLm" alias BHYTXML2MedicationLM as target // Bảng 2 thuốc BHYT — Logical Model

// Full QD 3176 XML2 field catalog. MA_NHOM uses the QD 3176 source code system and must be mapped to QD 697/VNCostCategoryCS with a ConceptMap. 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 MapBHYTXML2MedicationLM(source sourceBundle : BHYTSubmissionBundle, target targetRow : BHYTXML2MedicationLM) {
  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[medicationLine].sequence
  sourceBundle.entry as maThuocSource -> targetRow.maThuoc "maThuoc"; // Target field: MA_THUOC - Mã thuốc FHIR path: VNCoreMedication.code.coding.code | VNCoreClaim.item[medicationLine].productOrService.coding.code
  sourceBundle.entry as maPpChebienSource -> targetRow.maPpChebien "maPpChebien"; // Target field: MA_PP_CHEBIEN - Mã phương pháp chế biến FHIR path: VNCoreClaim.item[medicationLine].extension[processingMethod].valueString | VNCoreExplanationOfBenefit.item[medicationLine].extension[processingMethod].valueString | VNCoreMedication.extension[processingMethod].valueString | VNCoreMedicationRequest.extension[processingMethod].valueString | VNCoreMedicationDispense.extension[processingMethod].valueString
  sourceBundle.entry as maCskcbThuocSource -> targetRow.maCskcbThuoc "maCskcbThuoc"; // Target field: MA_CSKCB_THUOC - Mã cơ sở KCB cấp thuốc FHIR path: VNCoreMedicationDispense.performer.actor.resolve().identifier[CSKCB].value | VNCoreMedicationDispense.location.resolve().identifier[CSKCB].value
  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[medicationLine].category.coding.code Mapping note: QD 3176 uses MA_NHOM=4 for medication; StructureMap must first apply the ConceptMap, then populate VNCostCategoryCS#8. Do not assign the QD 3176 code directly to VNCostCategoryCS.
  sourceBundle.entry as tenThuocSource -> targetRow.tenThuoc "tenThuoc"; // Target field: TEN_THUOC - Tên thuốc FHIR path: VNCoreMedication.code.text | VNCoreClaim.item[medicationLine].productOrService.text | display
  sourceBundle.entry as donViTinhSource -> targetRow.donViTinh "donViTinh"; // Target field: DON_VI_TINH - Đơn vị tính FHIR path: VNCoreClaim.item[medicationLine].quantity.unit
  sourceBundle.entry as hamLuongSource -> targetRow.hamLuong "hamLuong"; // Target field: HAM_LUONG - Hàm lượng FHIR path: VNCoreMedication.ingredient.strength | Medication.code.text
  sourceBundle.entry as duongDungSource -> targetRow.duongDung "duongDung"; // Target field: DUONG_DUNG - Đường dùng FHIR path: VNCoreMedicationRequest.dosageInstruction.route
  sourceBundle.entry as dangBaoCheSource -> targetRow.dangBaoChe "dangBaoChe"; // Target field: DANG_BAO_CHE - Dạng bào chế FHIR path: VNCoreMedication.form.coding.code | VNCoreMedication.form.text
  sourceBundle.entry as lieuDungSource -> targetRow.lieuDung "lieuDung"; // Target field: LIEU_DUNG - Liều dùng FHIR path: VNCoreMedicationRequest.dosageInstruction.doseAndRate
  sourceBundle.entry as cachDungSource -> targetRow.cachDung "cachDung"; // Target field: CACH_DUNG - Cách dùng FHIR path: VNCoreMedicationRequest.dosageInstruction.text
  sourceBundle.entry as soDangKySource -> targetRow.soDangKy "soDangKy"; // Target field: SO_DANG_KY - Số đăng ký thuốc FHIR path: VNCoreMedication.extension[registrationNumber].valueString | VNCoreMedicationRequest.extension[registrationNumber].valueString | VNCoreMedicationDispense.extension[registrationNumber].valueString
  sourceBundle.entry as ttThauSource -> targetRow.ttThau "ttThau"; // Target field: TT_THAU - Thông tin thầu FHIR path: VNCoreClaim.item[medicationLine].extension[tenderInfo].valueString | VNCoreExplanationOfBenefit.item[medicationLine].extension[tenderInfo].valueString | VNCoreMedication.extension[tenderInfo].valueString | VNCoreMedicationRequest.extension[tenderInfo].valueString | VNCoreMedicationDispense.extension[tenderInfo].valueString
  sourceBundle.entry as phamViSource -> targetRow.phamVi "phamVi"; // Target field: PHAM_VI - Phạm vi thanh toán FHIR path: VNCoreClaim.item[medicationLine].extension[insuranceCostInfo].extension[scope].valueCodeableConcept
  sourceBundle.entry as tyleTtBhSource -> targetRow.tyleTtBh "tyleTtBh"; // Target field: TYLE_TT_BH - Tỷ lệ thanh toán BHYT FHIR path: VNCoreClaim.item[medicationLine].extension[insuranceCostInfo].extension[paymentRatio].valueDecimal
  sourceBundle.entry as soLuongSource -> targetRow.soLuong "soLuong"; // Target field: SO_LUONG - Số lượng FHIR path: VNCoreClaim.item[medicationLine].quantity.value | VNCoreMedicationDispense.quantity.value
  sourceBundle.entry as donGiaSource -> targetRow.donGia "donGia"; // Target field: DON_GIA - Đơn giá FHIR path: VNCoreClaim.item[medicationLine].unitPrice.value
  sourceBundle.entry as thanhTienBvSource -> targetRow.thanhTienBv "thanhTienBv"; // Target field: THANH_TIEN_BV - Thành tiền bệnh viện FHIR path: VNCoreClaim.item[medicationLine].net.value | VNCoreClaim.item[medicationLine].extension[hospitalLineAmount].valueMoney.value
  sourceBundle.entry as thanhTienBhSource -> targetRow.thanhTienBh "thanhTienBh"; // Target field: THANH_TIEN_BH - Thành tiền BHYT FHIR path: VNCoreClaim.item[medicationLine].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[medicationLine].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[medicationLine].adjudication.where(category='submitted').amount - .where(category='eligible').amount | Derived from VNCoreExplanationOfBenefit.item[medicationLine].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[medicationLine].adjudication.where(category='copay').amount.value | VNCoreExplanationOfBenefit.item[medicationLine].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[medicationLine].adjudication.where(category='benefit').amount.value | VNCoreExplanationOfBenefit.item[medicationLine].adjudication.where(category='benefit').amount.value
  sourceBundle.entry as maKhoaSource -> targetRow.maKhoa "maKhoa"; // Target field: MA_KHOA - Mã khoa FHIR path: VNCoreClaim.item[medicationLine].extension[department].valueCodeableConcept.coding.code
  sourceBundle.entry as maBacSiSource -> targetRow.maBacSi "maBacSi"; // Target field: MA_BAC_SI - Mã bác sĩ FHIR path: VNCoreMedicationRequest.requester.resolve().identifier.value | VNCorePractitioner.identifier.value
  sourceBundle.entry as maDichVuSource -> targetRow.maDichVu "maDichVu"; // Target field: MA_DICH_VU - Mã dịch vụ liên quan FHIR path: VNCoreClaim.item[medicationLine].detail.productOrService.coding.code | VNCoreServiceRequest.code
  sourceBundle.entry as ngayYlSource -> targetRow.ngayYl "ngayYl"; // Target field: NGAY_YL - Ngày y lệnh FHIR path: VNCoreMedicationRequest.authoredOn
  sourceBundle.entry as ngayThYlSource -> targetRow.ngayThYl "ngayThYl"; // Target field: NGAY_TH_YL - Ngày thực hiện y lệnh FHIR path: VNCoreMedicationDispense.whenHandedOver | VNCoreMedicationDispense.whenPrepared
  sourceBundle.entry as maPtttSource -> targetRow.maPttt "maPttt"; // Target field: MA_PTTT - Mã phẫu thuật/thủ thuật liên quan FHIR path: VNCoreClaim.procedure.procedureCodeableConcept | VNCoreProcedure.code Mapping note: Procedure context for medication lines when QD 3176 requires linking the drug to a related surgery/procedure; do not infer this from MA_NHOM.
  sourceBundle.entry as nguonCtraSource -> targetRow.nguonCtra "nguonCtra"; // Target field: NGUON_CTRA - Nguồn chi trả FHIR path: VNCoreClaim.item[medicationLine].extension[paymentSource].valueCodeableConcept.coding.code | VNCoreExplanationOfBenefit.item[medicationLine].extension[paymentSource].valueCodeableConcept.coding.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[medicationLine].extension[recurrentWoundBenefit].valueBoolean | VNCoreExplanationOfBenefit.item[medicationLine].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.
}

# title
Bảng 2 thuốc 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 2 thuốc BHYT — Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML2MedicationLM.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.

# group[].documentation
Full QD 3176 XML2 field catalog. MA_NHOM uses the QD 3176 source code system and must be mapped to QD 697/VNCostCategoryCS with a ConceptMap. 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[].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[medicationLine].sequence

# 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[medicationLine].category.coding.code Mapping note: QD 3176 uses MA_NHOM=4 for medication; StructureMap must first apply the ConceptMap, then populate VNCostCategoryCS#8. Do not assign the QD 3176 code directly to VNCostCategoryCS.

# group[].rule[].documentation
Target field: TEN_THUOC - Tên thuốc FHIR path: VNCoreMedication.code.text | VNCoreClaim.item[medicationLine].productOrService.text | display

# group[].rule[].documentation
Target field: DON_VI_TINH - Đơn vị tính FHIR path: VNCoreClaim.item[medicationLine].quantity.unit

# group[].rule[].documentation
Target field: HAM_LUONG - Hàm lượng FHIR path: VNCoreMedication.ingredient.strength | Medication.code.text

# group[].rule[].documentation
Target field: DUONG_DUNG - Đường dùng FHIR path: VNCoreMedicationRequest.dosageInstruction.route

# group[].rule[].documentation
Target field: DANG_BAO_CHE - Dạng bào chế FHIR path: VNCoreMedication.form.coding.code | VNCoreMedication.form.text

# group[].rule[].documentation
Target field: CACH_DUNG - Cách dùng FHIR path: VNCoreMedicationRequest.dosageInstruction.text

# group[].rule[].documentation
Target field: DON_GIA - Đơn giá FHIR path: VNCoreClaim.item[medicationLine].unitPrice.value

# group[].rule[].documentation
Target field: MA_DICH_VU - Mã dịch vụ liên quan FHIR path: VNCoreClaim.item[medicationLine].detail.productOrService.coding.code | VNCoreServiceRequest.code

# group[].rule[].documentation
Target field: NGAY_YL - Ngày y lệnh FHIR path: VNCoreMedicationRequest.authoredOn

# group[].rule[].documentation
Target field: NGAY_TH_YL - Ngày thực hiện y lệnh FHIR path: VNCoreMedicationDispense.whenHandedOver | VNCoreMedicationDispense.whenPrepared

# group[].rule[].documentation
Target field: MA_PTTT - Mã phẫu thuật/thủ thuật liên quan FHIR path: VNCoreClaim.procedure.procedureCodeableConcept | VNCoreProcedure.code Mapping note: Procedure context for medication lines when QD 3176 requires linking the drug to a related surgery/procedure; do not infer this from MA_NHOM.

# group[].rule[].documentation
Target field: VET_THUONG_TP - Vết thương tái phát FHIR path: VNCoreClaim.item[medicationLine].extension[recurrentWoundBenefit].valueBoolean | VNCoreExplanationOfBenefit.item[medicationLine].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.