<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="EMERGENCY_EVENT" 
Description="Случай госпитализации" 
DNAttributes="{EventDate}" 
DisplayName="Случай госпитализации ({0})" 
Inherits="AKUZ.AMBULANCE_EVENT">
  <Customs>
    <Custom Name="NotDisplayedInFilter" Value="CalcNumberIB;EpicrisCollections;DivisionEpicriss;HospitalSummaryEpicris;IsDrugAllergyPresent;IsFoodAllergyPresent;LastMovementDivisionCard" />
    <Custom Name="NotDisplayedColumns" Value="CalcNumberIB;EpicrisCollections;DivisionEpicriss;HospitalSummaryEpicris;IsDrugAllergyPresent;IsFoodAllergyPresent;LastMovementDivisionCard" />
    <Custom Name="NotTrackedAttributes" Value="CalcNumberIB;EpicrisCollections;DivisionEpicriss;HospitalSummaryEpicris;IsDrugAllergyPresent;IsFoodAllergyPresent;LastMovementDivisionCard" />
  </Customs>
  <Fields>
    <Attribute Name="DeliveryDate" Index="5840028" Type="datetime" DefaultFormat="{0:HH:mm}" Description="Время поступления" Required="1" />
    <Attribute Name="OutcomeTime" Index="5840038" Type="datetime" DefaultFormat="{0:HH:mm}" Description="Время выписки" />
    <Parent Name="MedicalcardRegistration" Index="5840027" Type="AKUZ.MEDICALCARD_REGISTRATION" Description="Данные по госпитализации" />
    <Parent Name="Post" Index="5840037" Type="AKUZ.POST" Description="Ответственный врач" />
    <Child Name="MedicalcardRegistrations" Index="5840041" Type="AKUZ.MEDICALCARD_REGISTRATION" Description="Данные по госпитализации" ChildAttribute="EmergencyEvent" />
    <Choice Name="VidHospitalisation" Index="5840033" Description="Вид госпитализации">
      <Item Name="Госпитализация без направления" Index="1" />
      <Item Name="Госпитализация с осмотром врача" Index="2" />
      <Item Name="Госпитализация по договору" Index="3" />
      <Item Name="Госпитализация без осмотра врача" Index="4" />
      <Item Name="Отказ от госпитализации" Index="5" />
      <Item Name="Госпитализация с направлением" Index="6" />
      <Item Name="Не определен" Index="0" />
    </Choice>
    <Choice Name="CommonStatus" Description="Состояние при обращении за мед.помощью">
      <Item Name="Удовлетворительное" Index="0" />
      <Item Name="Средне-тяжелое" Index="1" />
      <Item Name="Тяжелое" Index="2" />
      <Item Name="Терминальное" Index="3" />
    </Choice>
    <Attribute Name="IncomingComplaints" Type="string" Description="Жалобы при обращении" />
    <Parent Name="HospitalizationType" Index="10190011" Type="VCLib.ENUMS" Description="Тип госпитализации" EnumType="HospitalizationType" />
    <Link Name="PrepareDataHospitalisation" Index="5840022" Type="AKUZ.PREPARE_DATA_HOSPITALISATION" Description="Предгоспитализационный осмотр" LinkAttribute="EmergencyEvent" />
    <Link Name="Inspectiontosiffilis" Index="5840025" Type="AKUZ.INSPECTIONTOSIFFILIS" Description="Обследование на сифилис" LinkAttribute="EmergencyEvent" />
    <Link Name="TakeOverHospitalisation" Index="5840029" Type="AKUZ.TAKE_OVER_HOSPITALISATION" Description="Отказ от госпитализации" LinkAttribute="EmergencyEvent" />
    <Link Name="ReceptionDiagnosis" Index="5840039" Type="AKUZ.RECEPTION_DIAGNOSIS" Description="Диагноз при поступлении" LinkAttribute="EmergencyEvent" />
    <Link Name="ObstetricsServices" Index="5840042" Type="AKUZ.OBSTETRICS_SERVICES" Description="Служба родовспоможения" LinkAttribute="EmergencyEvent" />
    <Link Name="CdaHospitalEpicris" Type="AKUZ.CDA_HOSPITAL_EPICRIS" Description="Выписка из случая стационарного лечения в формате CDA" LinkAttribute="EmergencyEvent" />
    <Parent Name="RdsHospitalizationReferral" Type="AKUZ.RDS_HOSPITALIZATION_REFERRAL" Description="Направление на госпитализацию(rds)" />
    <Link Name="NotificationAboutHospital" Type="AKUZ.NOTIFICATION_ABOUT_HOSPITAL" Description="Уведомление в стационар о предстоящей госпитализации пациента" LinkAttribute="EmergencyEvent" RemoveAction="0" />
    <Child Name="RouteToOperations" Type="AKUZ.ROUTE_TO_OPERATION" Description="Назначение на операцию" ChildAttribute="AmbulanceEvent" />
    <Link Name="VimisHospitalEpicrisis" Type="AKUZ.VIMIS_HOSPITAL_EPICRISIS" Description="Эпикриз стационара в формате ВИМИС" LinkAttribute="EmergencyEvent" />
    <Parent Name="Room" Type="AKUZ.ROOM" Description="Кабинет первичного приема" />
    <Attribute Name="IsDrugAllergyPresent" Type="bool" Description="Наличие лекарственной аллергии" />
    <Attribute Name="IsFoodAllergyPresent" Type="bool" Description="Наличие пищевой аллегрии" />
    <Parent Name="AdmissionDivision" Type="AKUZ.DIVISION" Description="Приемное отделение" />
    <Parent Name="LastMovementDivisionCard" Type="AKUZ.MOVEMENTS_DIVISION_CARD" Description="Последнее отделение" />
    <Attribute Name="IsSendToTyre" Type="bool" Description="Признак отправки в шину" />
    <Parent Name="ChannelsHospitalisation" Type="AKUZ.CHANNELS_HOSPITALISATION" Description="Каналы госпитализации" />
    <Child Name="EpicrissCollection" Type="AKUZ.HOSPITAL_SUMMARY_EPICRIS" Description="Эпикриз из случая стационарного лечения" ChildAttribute="AmbulanceEvent" />
    <Attribute Name="PatientIdentify" Type="bool" Description="Иденфикация пациента со слов" Required="1" />
    <Child Name="Partograms" Type="AKUZ.PARTOGRAM" Description="Партограмма" ChildAttribute="AmbulanceEvent" />
    <Attribute Name="NumberIB" Type="int" Description="Номер госпитализации по порядку" />
    <Attribute Name="CalcNumberIB" Type="string" Description="Вычислимый номер истории болезни" />
    <Link Name="ObstetricHospitalStage" Type="AKUZ.OBSTETRIC_HOSPITAL_STAGE" Description="Сведения акушерского стационара о родильнице" LinkAttribute="EmergencyEvent" />
  </Fields>
  <DbMapping>
    <Table name="T_EMERGENCY_EVENT">
      <Map Name="DeliveryDate" Column="DeliveryDate" />
      <Map Name="OutcomeTime" Column="OutcomeTime" />
      <Map Name="MedicalcardRegistration" Column="mcr" IsStored="0" />
      <Map Name="Post" Column="Post" />
      <Map Name="VidHospitalisation" Column="VidHospitalisation" />
      <Map Name="CommonStatus" Column="CommonStatus" />
      <Map Name="IncomingComplaints" Column="IncomingComplaints" />
      <Map Name="HospitalizationType" Column="HospitalizationType" />
      <Map Name="Room" Column="Room" />
      <Map Name="AdmissionDivision" Column="AdmissionDivision" />
      <Map Name="IsSendToTyre" Column="IsSendToTyre" />
      <Map Name="ChannelsHospitalisation" Column="ChannelsHospitalisation" />
      <Map Name="PatientIdentify" Column="PatientIdentify" />
      <Map Name="NumberIB" Column="NumberIB" />
    </Table>
    <Lexem>
      <Map Name="RdsHospitalizationReferral">
        <lx:QueryValue entity="AKUZ.RDS_HOSPITALIZATION_REFERRAL" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="ReferralDate" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Direction" />
                  <lx:StepString name="DirectionDate" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="DivisionTo" />
                  <lx:StepString name="Branch" />
                  <lx:StepString name="LpuMain" />
                  <lx:StepString name="LpuCode" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Direction" />
                  <lx:StepString name="Lpu" />
                  <lx:StepString name="LpuCode" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="ReferralNumber" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Direction" />
                  <lx:StepString name="DirectionNumber" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criteria type="Or">
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="BranchFrom" />
                    <lx:StepString name="LpuMain" />
                    <lx:StepString name="LpuCode" />
                  </lx:Path>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="Direction" />
                    <lx:StepString name="DirectorLpu" />
                    <lx:StepString name="LpuCode" />
                  </lx:Path>
                </lx:Criterion>
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="LpuMainFrom" />
                    <lx:StepString name="LpuCode" />
                  </lx:Path>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="Direction" />
                    <lx:StepString name="DirectorLpu" />
                    <lx:StepString name="LpuCode" />
                  </lx:Path>
                </lx:Criterion>
              </lx:Criteria>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="RdsHospitalizationReferralID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="IsDrugAllergyPresent">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:CriterionChildExists>
              <condition>
                <lx:Criteria type="And">
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepAs as="AKUZ.MEDICAL_EXAMINATION" />
                      <lx:StepString name="DrugAllergy" />
                    </lx:Path>
                    <lx:ConstOperand isNull="1" />
                  </lx:Criterion>
                </lx:Criteria>
              </condition>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="AmbulanceRecords" />
              </lx:Path>
            </lx:CriterionChildExists>
          </When>
          <Then>
            <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
          </Then>
          <Else>
            <lx:ConstOperand type="Boolean">False</lx:ConstOperand>
          </Else>
        </lx:Case>
      </Map>
      <Map Name="IsFoodAllergyPresent">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:CriterionChildExists>
              <condition>
                <lx:Criterion not="1" type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepAs as="AKUZ.MEDICAL_EXAMINATION" />
                    <lx:StepString name="FoodAllergy" />
                  </lx:Path>
                  <lx:ConstOperand isNull="1" />
                </lx:Criterion>
              </condition>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="AmbulanceRecords" />
              </lx:Path>
            </lx:CriterionChildExists>
          </When>
          <Then>
            <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
          </Then>
          <Else>
            <lx:ConstOperand type="Boolean">False</lx:ConstOperand>
          </Else>
        </lx:Case>
      </Map>
      <Map Name="LastMovementDivisionCard">
        <lx:QueryValue entity="AKUZ.MOVEMENTS_DIVISION_CARD" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Movement" />
                <lx:StepString name="EmergencyEvent" />
                <lx:StepString name="EventID" />
              </lx:Path>
              <lx:Path OwnerQueryLevel="1">
                <lx:StepString name="EventID" />
              </lx:Path>
            </lx:Criterion>
          </condition>
          <orderBy>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="DateIn" />
            </lx:Path>
            <desc>True</desc>
          </orderBy>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="MedicalEpisodeID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="CalcNumberIB">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="MedicalcardRegistration" />
                <lx:StepString name="FullMedCardNum" />
              </lx:Path>
              <lx:ConstOperand isNull="1" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:Case>
              <When>
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="MedicalcardRegistration" />
                    <lx:StepString name="MedCardNumber" />
                  </lx:Path>
                  <lx:ConstOperand isNull="1" />
                </lx:Criterion>
              </When>
              <Then>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="NumberIB" />
                </lx:Path>
              </Then>
              <Else>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="MedicalcardRegistration" />
                  <lx:StepString name="MedCardNumber" />
                </lx:Path>
              </Else>
            </lx:Case>
          </Then>
          <Else>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="MedicalcardRegistration" />
              <lx:StepString name="FullMedCardNum" />
            </lx:Path>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Parent Name="DoctorWardExamination" Index="5840030" Type="AKUZ.DOCTOR_WARD_EXAMINATION" Description="Первичный осмотр врача в приемном покое" RequiredAttributes="{Post};{AmbulanceRecords / Post}" PathAttributes="{AmbulanceRecords/as AKUZ.DOCTOR_WARD_EXAMINATION}" />
    <Child Name="DivisionEpicriss" Type="AKUZ.HOSPITAL_SUMMARY_EPICRIS" Description="Выписные эпикризы отделений" RequiredAttributes="{MedicalcardRegistrations/HospitalSummaryEpicriss/Type};{MedicalcardRegistrations/HospitalSummaryEpicriss/DateEnd};{MedicalcardRegistrations/HospitalSummaryEpicriss/Division};{MedicalcardRegistrations/HospitalSummaryEpicriss/CreateDate};{MedicalcardRegistrations/HospitalSummaryEpicriss/EpicrisText}" />
    <Parent Name="HospitalSummaryEpicris" Type="AKUZ.HOSPITAL_SUMMARY_EPICRIS" Description="Итоговый эпикриз" RequiredAttributes="{MedicalcardRegistrations/HospitalSummaryEpicriss/Type};{MedicalcardRegistrations/HospitalSummaryEpicriss/DateEnd};{MedicalcardRegistrations/HospitalSummaryEpicriss/Division}" />
    <Attribute Name="FullBarcode" Type="string" Description="Штрих код" RequiredAttributes="{Number};{EventDate};{AmbulanceCard/CardLpu/Code}" />
  </CalculatingAttributes>
</Entity>