# text.div
Generated Narrative: StructureMap vn-sm-bhyt-xml7-discharge-paper

map "http://fhir.hl7.org.vn/core/StructureMap/vn-sm-bhyt-xml7-discharge-paper" = "BHYTXML7DischargePaperLMStructureMap"

// Generated StructureMap scaffold for Bảng 7 giấy ra viện — XML7 Discharge Paper Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML7DischargePaperLM.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/bhytXml7DischargePaperLm" alias BHYTXML7DischargePaperLM as target // Bảng 7 giấy ra viện — XML7 Discharge Paper Logical Model

// Rows are derived from discharge Composition/DocumentReference, the linked Encounter, Condition, Practitioner and guardian/temporary card data. 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 MapBHYTXML7DischargePaperLM(source sourceBundle : BHYTSubmissionBundle, target targetRow : BHYTXML7DischargePaperLM) {
  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 soLuuTruSource -> targetRow.soLuuTru "soLuuTru"; // Target field: SO_LUU_TRU - Số lưu trữ/số hồ sơ bệnh án FHIR path: VNCoreComposition.identifier.value | VNCoreDocumentReference.identifier.value
  sourceBundle.entry as maYteSource -> targetRow.maYte "maYte"; // Target field: MA_YTE - Mã y tế/mã người bệnh FHIR path: VNCorePatient.identifier[MRN].value
  sourceBundle.entry as maKhoaRvSource -> targetRow.maKhoaRv "maKhoaRv"; // Target field: MA_KHOA_RV - Mã khoa ra viện/tổng kết FHIR path: VNCoreEncounter.location.location.resolve().identifier.value | VNCoreOrganizationDepartment.identifier.value
  sourceBundle.entry as ngayVaoSource -> targetRow.ngayVao "ngayVao"; // Target field: NGAY_VAO - Ngày vào viện FHIR path: VNCoreEncounter.period.start
  sourceBundle.entry as ngayRaSource -> targetRow.ngayRa "ngayRa"; // Target field: NGAY_RA - Ngày ra viện FHIR path: VNCoreEncounter.period.end | VNCoreComposition.date
  sourceBundle.entry as chanDoanRvSource -> targetRow.chanDoanRv "chanDoanRv"; // Target field: CHAN_DOAN_RV - Chẩn đoán ra viện FHIR path: VNCoreComposition.section[diagnosis].entry.resolve().code | VNCoreCondition.code | section.text
  sourceBundle.entry as ghiChuSource -> targetRow.ghiChu "ghiChu"; // Target field: GHI_CHU - Ghi chú FHIR path: VNCoreDocumentReference.description | VNCoreComposition.section.text
  sourceBundle.entry as maTtdvSource -> targetRow.maTtdv "maTtdv"; // Target field: MA_TTDV - Mã thủ trưởng đơn vị/người ký FHIR path: VNCoreComposition.attester.party.resolve().identifier.value | VNCoreDocumentReference.authenticator.resolve().identifier.value
  sourceBundle.entry as maBsSource -> targetRow.maBs "maBs"; // Target field: MA_BS - Mã bác sĩ FHIR path: VNCoreComposition.author.resolve().identifier.value | VNCorePractitioner.identifier.value
  sourceBundle.entry as tenBsSource -> targetRow.tenBs "tenBs"; // Target field: TEN_BS - Tên bác sĩ FHIR path: VNCoreComposition.author.display | VNCorePractitioner.name.text
  sourceBundle.entry as ngayCtSource -> targetRow.ngayCt "ngayCt"; // Target field: NGAY_CT - Ngày cấp chứng từ FHIR path: VNCoreDocumentReference.date | VNCoreComposition.date
  sourceBundle.entry as maChaSource -> targetRow.maCha "maCha"; // Target field: MA_CHA - Mã cha FHIR path: VNCoreRelatedPerson.where(relationship.coding.code='FTH').identifier[CCCD].value | VNCorePatient.contact.where(relationship.coding.code='FTH').name
  sourceBundle.entry as maMeSource -> targetRow.maMe "maMe"; // Target field: MA_ME - Mã mẹ FHIR path: VNCoreRelatedPerson.where(relationship.coding.code='MTH').identifier[CCCD].value | VNCorePatient.contact.where(relationship.coding.code='MTH').name
  sourceBundle.entry as maTheTamSource -> targetRow.maTheTam "maTheTam"; // Target field: MA_THE_TAM - Mã thẻ tạm FHIR path: VNCoreCoverage.identifier.value Mapping note: Temporary card identifiers are kept as Coverage.identifier until a dedicated temporary-card slice is profiled.
  sourceBundle.entry as hoTenChaSource -> targetRow.hoTenCha "hoTenCha"; // Target field: HO_TEN_CHA - Họ tên cha FHIR path: VNCoreRelatedPerson.where(relationship.coding.code='FTH').name.text | VNCorePatient.contact.where(relationship.coding.code='FTH').name.text
  sourceBundle.entry as hoTenMeSource -> targetRow.hoTenMe "hoTenMe"; // Target field: HO_TEN_ME - Họ tên mẹ FHIR path: VNCoreRelatedPerson.where(relationship.coding.code='MTH').name.text | VNCorePatient.contact.where(relationship.coding.code='MTH').name.text
  sourceBundle.entry as soNgayNghiSource -> targetRow.soNgayNghi "soNgayNghi"; // Target field: SO_NGAY_NGHI - Số ngày nghỉ FHIR path: Derived from VNCoreDocumentReference.context.period | VNCoreComposition.event.period
  sourceBundle.entry as ngoaiTruTuNgaySource -> targetRow.ngoaiTruTuNgay "ngoaiTruTuNgay"; // Target field: NGOAITRU_TUNGAY - Ngoại trú từ ngày FHIR path: VNCoreDocumentReference.context.period.start | VNCoreComposition.event.period.start
  sourceBundle.entry as ngoaiTruDenNgaySource -> targetRow.ngoaiTruDenNgay "ngoaiTruDenNgay"; // Target field: NGOAITRU_DENNGAY - Ngoại trú đến ngày FHIR path: VNCoreDocumentReference.context.period.end | VNCoreComposition.event.period.end
}

# title
Bảng 7 giấy ra viện — XML7 Discharge Paper 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 7 giấy ra viện — XML7 Discharge Paper Logical Model. Source semantics come from the logical model mapping annotations in `BHYTXML7DischargePaperLM.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 7 giấy ra viện — XML7 Discharge Paper Logical Model

# group[].documentation
Rows are derived from discharge Composition/DocumentReference, the linked Encounter, Condition, Practitioner and guardian/temporary card data. 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 7 giấy ra viện — XML7 Discharge Paper 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: SO_LUU_TRU - Số lưu trữ/số hồ sơ bệnh án FHIR path: VNCoreComposition.identifier.value | VNCoreDocumentReference.identifier.value

# group[].rule[].documentation
Target field: MA_YTE - Mã y tế/mã người bệnh FHIR path: VNCorePatient.identifier[MRN].value

# group[].rule[].documentation
Target field: NGAY_VAO - Ngày vào viện FHIR path: VNCoreEncounter.period.start

# group[].rule[].documentation
Target field: NGAY_RA - Ngày ra viện FHIR path: VNCoreEncounter.period.end | VNCoreComposition.date

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

# group[].rule[].documentation
Target field: GHI_CHU - Ghi chú FHIR path: VNCoreDocumentReference.description | VNCoreComposition.section.text

# group[].rule[].documentation
Target field: MA_BS - Mã bác sĩ FHIR path: VNCoreComposition.author.resolve().identifier.value | VNCorePractitioner.identifier.value

# group[].rule[].documentation
Target field: TEN_BS - Tên bác sĩ FHIR path: VNCoreComposition.author.display | VNCorePractitioner.name.text

# group[].rule[].documentation
Target field: NGAY_CT - Ngày cấp chứng từ FHIR path: VNCoreDocumentReference.date | VNCoreComposition.date

# group[].rule[].documentation
Target field: MA_THE_TAM - Mã thẻ tạm FHIR path: VNCoreCoverage.identifier.value Mapping note: Temporary card identifiers are kept as Coverage.identifier until a dedicated temporary-card slice is profiled.

# group[].rule[].documentation
Target field: SO_NGAY_NGHI - Số ngày nghỉ FHIR path: Derived from VNCoreDocumentReference.context.period | VNCoreComposition.event.period

# group[].rule[].documentation
Target field: NGOAITRU_TUNGAY - Ngoại trú từ ngày FHIR path: VNCoreDocumentReference.context.period.start | VNCoreComposition.event.period.start

# group[].rule[].documentation
Target field: NGOAITRU_DENNGAY - Ngoại trú đến ngày FHIR path: VNCoreDocumentReference.context.period.end | VNCoreComposition.event.period.end