<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="MEDICAL_EXAMINATION_DATA" 
Description="Данные о случае обращения" 
PrimaryKey="MedicalExaminationDataID">
  <Fields>
    <Attribute Name="MedicalExaminationDataID" Type="guid" Description="Идентификатор" />
    <Parent Name="MedicalExaminationMain" Type="AKUZ.MEDICAL_EXAMINATION_MAIN" Description="Первичный медицинский осмотр" />
    <Attribute Name="TNMS" Type="string" Description="Онкологический диагноз" />
    <Parent Name="SicknessMode" Type="VCLib.ENUMS" Description="Характер заболевания" EnumType="SicknessMode" />
    <Attribute Name="SetDTClinicalDiagnosis" Type="datetime" Description="Дата и время установки клинического диагноза" />
    <Attribute Name="ExternalCause" Type="string" Description="Внешняя причина" />
    <Choice Name="TraumaType" Description="Тип травмы">
      <Item Name="Производственная" Index="1" />
      <Item Name="Непроизводственная" Index="2" />
    </Choice>
    <Parent Name="VisitPurpose" Type="AKUZ.VISIT_PURPOSE" Description="Цель обращения" Required="1" />
    <Parent Name="ClinicalDiagnosis" Type="AKUZ.DIAGNOSIS" Description="Основное заболевание" Required="1" />
    <Child Name="AssociatedAndComplicationDiseases" Type="AKUZ.ASSOCIATED_AND_COMPLICATION_DISEASE" Description="Сопутствующие диагнозы и осложнения в случаe обращения" ChildAttribute="MedicalExaminationData" />
    <Choice Name="SicknessStage" Description="Стадия заболевания">
      <Item Name="ранняя" Index="1" />
      <Item Name="поздняя" Index="2" />
      <Item Name="0" Index="10" />
      <Item Name="1" Index="11" />
      <Item Name="2" Index="12" />
      <Item Name="3" Index="13" />
      <Item Name="4" Index="14" />
    </Choice>
    <Parent Name="Trauma" Type="AKUZ.TRAUMA" Description="Травма" />
    <Link Name="OutcomeOfInspection" Type="AKUZ.OUTCOME_OF_INSPECTION" Description="Исход осмотра врача" LinkAttribute="MedicalExaminationData" />
    <Parent Name="CheckUpStatus" Type="VCLib.ENUMS" Description="Признак ДН по диагнозу" EnumType="CheckUpStatus" />
    <Parent Name="CheckUpGroup" Type="VCLib.ENUMS" Description="Группа Д-наблюдения" EnumType="CheckUpGroup" />
    <Attribute Name="CheckUpDateIn" Type="datetime" Description="Дата взятия на ДН" />
    <Attribute Name="CheckUpDateOut" Type="datetime" Description="Дата снятия с ДН" />
    <Attribute Name="ActiveFindDiagnos" Type="bool" Description="Признак активного выявления диагноза" Required="1" />
    <Parent Name="AmbulanceEvent" Type="AKUZ.AMBULANCE_EVENT" Description="Амбулаторный случай обращения" />
    <Parent Name="LastMedicalExamination" Type="AKUZ.MEDICAL_EXAMINATION" Description="Последний проведенный медицинский осмотр" />
    <Child Name="ChangeDiagnosisInPolyclinicEvents" Type="AKUZ.CHANGE_DIAGNOSIS_IN_POLYCLINIC_EVENT" Description="Изменение клинического диагноза в поликлинике" ChildAttribute="MedicalExaminationData" />
    <Link Name="DispanserisationInit" Type="AKUZ.DISPANSERISATION_INIT" Description="Диспансерное наблюдение" LinkAttribute="MedicalExaminationData" />
    <Parent Name="cLastMedicalExamination" Type="AKUZ.MEDICAL_EXAMINATION" Description="Медицинский осмотр" />
  </Fields>
  <DbMapping>
    <Table name="T_MEDICAL_EXAMINATION_DATA">
      <Map Name="MedicalExaminationDataID" Column="MedicalExaminationDataID" />
      <Map Name="MedicalExaminationMain" Column="MedicalExaminationMain" />
      <Map Name="TNMS" Column="TNMS" />
      <Map Name="SicknessMode" Column="SicknessMode" />
      <Map Name="SetDTClinicalDiagnosis" Column="SetDTClinicalDiagnosis" />
      <Map Name="ExternalCause" Column="ExternalCause" />
      <Map Name="TraumaType" Column="TraumaType" />
      <Map Name="VisitPurpose" Column="VisitPurpose" />
      <Map Name="ClinicalDiagnosis" Column="ClinicalDiagnosis" />
      <Map Name="SicknessStage" Column="SicknessStage" />
      <Map Name="Trauma" Column="Trauma" />
      <Map Name="CheckUpStatus" Column="CheckUpStatus" />
      <Map Name="CheckUpGroup" Column="CheckUpGroup" />
      <Map Name="CheckUpDateIn" Column="CheckUpDateIn" />
      <Map Name="CheckUpDateOut" Column="CheckUpDateOut" />
      <Map Name="ActiveFindDiagnos" Column="ActiveFindDiagnos" />
      <Map Name="AmbulanceEvent" Column="AmbulanceEvent" />
      <Map Name="LastMedicalExamination" Column="LastMedicalExamination" />
    </Table>
    <Lexem>
      <Map Name="cLastMedicalExamination">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion type="&gt;">
              <lx:ChildCount>
                <condition />
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="MedicalExaminationMain" />
                  <lx:StepString name="MedicalExaminationRes" />
                </lx:Path>
                <lx:Count />
              </lx:ChildCount>
              <lx:ConstOperand type="Int32">0</lx:ConstOperand>
            </lx:Criterion>
          </When>
          <Then>
            <lx:ChildCount>
              <condition />
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="MedicalExaminationMain" />
                <lx:StepString name="MedicalExaminationRes" />
              </lx:Path>
              <lx:First>
                <lx:ConstOperand isNull="1" />
              </lx:First>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="ExaminationDate" />
              </lx:Path>
              <lx:ConstOperand type="String"><![CDATA[asc]]></lx:ConstOperand>
            </lx:ChildCount>
          </Then>
          <Else>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="MedicalExaminationMain" />
            </lx:Path>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Attribute Name="NextEntryDate" Type="datetime" Description="Дата следующей явки" RequiredAttributes="{LastMedicalExamination/ExaminationDate};{MedicalExaminationMain/ExaminationDate};{MedicalExaminationMain/RepeatedToRouteDoctorInspections/RouteDate};{MedicalExaminationMain/cMedicalExaminationRess/ExaminationDate};{MedicalExaminationMain/cMedicalExaminationRess/ExaminationTime};{MedicalExaminationMain/Post};{MedicalExaminationMain/AmbulanceEvent/AmbulanceRecords/Post};{MedicalExaminationMain/ExaminationDate};{MedicalExaminationMain/AmbulanceEvent/AmbulanceRecords/as AKUZ.PRESCRIPTION_RECORD/RouteDate}" />
  </CalculatingAttributes>
</Entity>