<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="MEDICAL_EPISODE" 
Description="Медицинский эпизод" 
PrimaryKey="MedicalEpisodeID">
  <Customs>
    <Custom Name="NotDisplayedInFilter" Value="TransportationRequests;TransportationRequest" />
    <Custom Name="NotDisplayedColumns" Value="TransportationRequests;TransportationRequest" />
    <Custom Name="NotTrackedAttributes" Value="TransportationRequests;TransportationRequest" />
  </Customs>
  <Fields>
    <Attribute Name="MedicalEpisodeID" Type="guid" Description="Идентификатор" />
    <Attribute Name="TNMS" Type="string" Description="Онкологический диагноз" />
    <Parent Name="RecordType" Type="VCLib.ENTITIES" Description="Тип записи" Save="0" />
    <Attribute Name="SetDTClinicalDiagnosis" Type="datetime" DefaultFormat="{0:dd.MM.yyyy}" Description="Дата и время установки окончательного диагноза" />
    <Parent Name="OutcomeRecord" Type="AKUZ.OUTCOME_OF_INSPECTION" Description="Исход случая обращения" />
    <Parent Name="AmbulanceEvent" Type="AKUZ.AMBULANCE_EVENT" Description="Амбулаторный случай обращения" Required="1" />
    <Parent Name="PaymentType" Type="VCLib.ENUMS" Description="Вид оплаты" EnumType="PaymentType" />
    <Child Name="DivisionSignificantEventss" Type="AKUZ.DIVISION_SIGNIFICANT_EVENTS" Description="Значимые события в отделении" ChildAttribute="MedicalEpisode" />
    <Child Name="NurseMedicalExaminations" Type="AKUZ.NURSE_MEDICAL_EXAMINATION" Description="Осмотры медицинской сестрой" ChildAttribute="MedicalEpisode" />
    <Attribute Name="Mkb" Type="string" Description="Код МКБ" />
    <Attribute Name="Diagnosis" Type="string" Description="Расшифровка диагноза" CharacterMaximumLength="4096" />
    <Attribute Name="Descr" Type="string" Description="Дополнительное описание диагноза" CharacterMaximumLength="2000" />
    <Child Name="AssociatedAndComplicationDiseases" Type="AKUZ.ASSOCIATED_AND_COMPLICATION_DISEASE" Description="Сопутствующие диагнозы и осложнения в случаe обращения" ChildAttribute="MedicalEpisode" />
    <Child Name="PostTreats" Type="AKUZ.POST_TREAT" Description="Лечащие врачи" ChildAttribute="MedicalEpisode" />
    <Parent Name="Post" Type="AKUZ.POST" Description="Должность" />
    <Attribute Name="DateIn" Type="date" Description="Дата начала лечения" Required="1" />
    <Attribute Name="DateOut" Type="date" Description="Дата окончания лечения/Дата последнего осмотра" />
    <Attribute Name="IExistMovementResult" Type="bool" Description="Эпизод имеет исход обращения" Required="1" />
    <Parent Name="CdaEpicris" Type="AKUZ.CDA_HOSPITAL_EPICRIS" Description="Выписка из случая лечения в формате CDA" />
    <Parent Name="VimisEpicrisis" Type="AKUZ.VIMIS_HOSPITAL_EPICRISIS" Description="Эпикриз в формате ВИМИС" />
    <Link Name="OnkTreatmentCase" Index="6670021" Type="AKUZ.ONK_TREATMENT_CASE" Description="Сведения о случае лечения онкологического заболевания" LinkAttribute="MedicalEpisode" />
    <Link Name="MovementResultLekPrepLink" Type="AKUZ.MOVEMENT_RESULT_LEK_PREP_LINK" Description="Связка между выпиской из отделения и сведениями о введенном лекарственном препарате" LinkAttribute="MedicalEpisode" />
    <Parent Name="Mes" Type="AKUZ.MES" Description="КСГ" />
    <Parent Name="Mes2" Type="AKUZ.MES" Description="Дополнительный КСГ" />
    <Attribute Name="Mes_Rec_Id" Type="int" Description="Rec_Id" />
    <Attribute Name="OnkoSuspicion" Type="bool" Description="Подозрение на онко" Required="1" />
    <Parent Name="AmbulanceCard" Type="AKUZ.AMBULANCE_CARD" Description="Амбулаторная карта" Required="1" />
    <Child Name="CardEpicrisiss" Type="AKUZ.CARD_EPICRISIS" Description="Выписки" ChildAttribute="MedicalEpisode" />
    <Child Name="MedicalRecomendations" Type="AKUZ.MEDICAL_RECOMENDATION" Description="Базовая сущность медицинских рекомендаций" ChildAttribute="MedicalEpisode" />
    <Child Name="TransportationRequests" Type="AKUZ.TRANSPORTATION_REQUEST" Description="Заявка на транспортировку" ChildAttribute="MedicalEpisode" />
    <Parent Name="TransportationRequest" Type="AKUZ.TRANSPORTATION_REQUEST" Description="Активная заявка на транспортировку" />
    <Parent Name="Result" Type="AKUZ.V009_RESULT" Description="Классификатор результатов обращения за медицинской помощью" />
    <Parent Name="Outcome" Type="AKUZ.V012_OUTCOME" Description="Классификатор исходов заболевания" />
    <Child Name="MedicalRecords" Type="AKUZ.MEDICAL_RECORD" Description="Медицинская запись" ChildAttribute="MedicalEpisode" />
  </Fields>
  <DbMapping>
    <Table name="T_MEDICAL_EPISODE">
      <Map Name="MedicalEpisodeID" Column="MedicalEpisodeID" />
      <Map Name="TNMS" Column="TNMS" />
      <Map Name="RecordType" Column="type_" IsStored="0" />
      <Map Name="SetDTClinicalDiagnosis" Column="SetDTClinicalDiagnosis" />
      <Map Name="OutcomeRecord" Column="OutcomeRecord" />
      <Map Name="AmbulanceEvent" Column="AmbulanceEvent" />
      <Map Name="PaymentType" Column="PaymentType" />
      <Map Name="Mkb" Column="Mkb" />
      <Map Name="Diagnosis" Column="Diagnosis" />
      <Map Name="Descr" Column="Descr" />
      <Map Name="DateIn" Column="DateIn" />
      <Map Name="DateOut" Column="DateOut" />
      <Map Name="CdaEpicris" Column="CdaEpicris" />
      <Map Name="VimisEpicrisis" Column="VimisEpicrisis" />
      <Map Name="Mes" Column="Mes" />
      <Map Name="Mes2" Column="Mes2" />
      <Map Name="Mes_Rec_Id" Column="Mes_Rec_Id" />
      <Map Name="OnkoSuspicion" Column="OnkoSuspicion" />
      <Map Name="AmbulanceCard" Column="AmbulanceCard" />
      <Map Name="Result" Column="Result" />
      <Map Name="Outcome" Column="Outcome" />
    </Table>
    <Lexem>
      <Map Name="Post" PathAttributes="{PostTreats/Post}">
        <lx:ChildCount xmlns:lx="lexem">
          <condition>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="EndCareDate" />
              </lx:Path>
              <lx:ConstOperand isNull="1" />
            </lx:Criterion>
          </condition>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="PostTreats" />
          </lx:Path>
          <lx:First>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="Post" />
            </lx:Path>
          </lx:First>
        </lx:ChildCount>
      </Map>
      <Map Name="IExistMovementResult">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion not="1" type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="OutcomeRecord" />
              </lx:Path>
              <lx:BaseObjectOperand Entity="AKUZ.OUTCOME_OF_INSPECTION" isNull="1" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
          </Then>
          <Else>
            <lx:ConstOperand type="Boolean">False</lx:ConstOperand>
          </Else>
        </lx:Case>
      </Map>
      <Map Name="TransportationRequest" PathAttributes="{TransportationRequests}">
        <lx:ChildCount xmlns:lx="lexem">
          <condition />
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="TransportationRequests" />
          </lx:Path>
          <lx:First>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepCurrent />
            </lx:Path>
          </lx:First>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="RequestDate" />
          </lx:Path>
          <lx:ConstOperand type="String"><![CDATA[desc]]></lx:ConstOperand>
        </lx:ChildCount>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>