<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="HOSPITALIZATION_REFERRAL" 
Description="Направление на госпитализацию" 
Inherits="AKUZ.REFERRAL">
  <Customs>
    <Custom Name="NotDisplayedInFilter" Value="RdsHospitalizationReferral" />
    <Custom Name="NotDisplayedColumns" Value="RdsHospitalizationReferral" />
    <Custom Name="NotTrackedAttributes" Value="RdsHospitalizationReferral" />
  </Customs>
  <Fields>
    <Attribute Name="MedicalCertificateObtain" Index="5680002" Type="bool" Description="Наличие листа нетрудоспособности" Required="1" />
    <Attribute Name="HtmlDocument" Index="5680005" Type="text" Description="Документ Html" />
    <Attribute Name="HospitalisationDate" Index="5680006" Type="datetime" Description="Дата планируемой госпитализации" />
    <Attribute Name="DocDocument" Index="5680008" Type="binary" Description="Документ MS WORD" />
    <Attribute Name="Email" Index="5680009" Type="string" Description="E-mail" CharacterMaximumLength="64" />
    <Attribute Name="Phone" Index="5680010" Type="string" Description="Телефон" CharacterMaximumLength="128" />
    <Attribute Name="PreHospitalDate" Index="5680013" Type="datetime" Description="Дата ожидаемой госпитализации" />
    <Attribute Name="ReferralNumber" Index="5680014" Type="string" Description="Номер направления" CharacterMaximumLength="21" Required="1" />
    <Attribute Name="NeedOperation" Index="5680015" Type="bool" Description="Необходимость операционного вмешательства" Required="1" />
    <Attribute Name="ErrorReserv" Index="5680018" Type="string" Description="Ошибка резервирование" CharacterMaximumLength="8000" />
    <Attribute Name="RegRefNumber" Index="5680022" Type="string" Description="Региональный номер направления" CharacterMaximumLength="21" />
    <Attribute Name="AnotherRegion" Index="5680023" Type="bool" Description="Направление в другой регион" Required="1" />
    <Parent Name="HospitalizationType" Index="5680001" Type="VCLib.ENUMS" Description="Вид госпитализации" EnumType="HospitalizationType" Required="1" />
    <Parent Name="HospitalType" Index="5680003" Type="VCLib.ENUMS" Description="Вид стационара" EnumType="HospitalType" />
    <Parent Name="ChannelsHospitalisation" Index="5680004" Type="AKUZ.CHANNELS_HOSPITALISATION" Description="Каналы госпитализации" />
    <Parent Name="Branch" Index="5680007" Type="AKUZ.BRANCH" Description="Филиал" />
    <Parent Name="StructureBed" Index="5680011" Type="AKUZ.STRUCTURE_BED" Description="Профили коек" />
    <Parent Name="EmergencyEvent" Index="5680021" Type="AKUZ.EMERGENCY_EVENT" Description="Случай госпитализации" />
    <Child Name="DirectionMedicalDocumentations" Index="5680019" Type="AKUZ.DIRECTION_MEDICAL_DOCUMENTATION" Description="Медицинская документация для направления" ChildAttribute="HospitalizationReferral" />
    <Choice Name="Status" Index="5680017" Description="Статус" Required="1">
      <Item Name="Новое" Index="0" />
      <Item Name="Отправлено" Index="1" />
      <Item Name="Ошибка" Index="2" />
      <Item Name="Зарезервировано" Index="3" />
      <Item Name="Отменено" Index="4" />
    </Choice>
    <Link Name="CancelHospitalizationReferral" Index="5680012" Type="AKUZ.CANCEL_HOSPITALIZATION_REFERRAL" Description="Отмена направления на госпитализацию" LinkAttribute="HospitalizationReferral" />
    <Attribute Name="ContactsConfirmDate" Index="5680024" Type="datetime" Description="Дата подтверждения контактов" />
    <Choice Name="CancelFlag" Index="5680025" Description="Признак отмены" Required="1">
      <Item Name="Активно" Index="0" />
      <Item Name="Откменено пользоветелем" Index="1" />
      <Item Name="Отклонено медицинским учреждением" Index="2" />
    </Choice>
    <Child Name="HospitalisationRefferalLinkResearchs" Type="AKUZ.HOSPITALISATION_REFFERAL_LINK_RESEARCH" Description="Уточненная цель госпитализации" ChildAttribute="HospitalizationReferral" />
    <Parent Name="RdsHospitalizationReferral" Type="AKUZ.RDS_HOSPITALIZATION_REFERRAL" Description="Направление на госпитализацию(rds)" />
    <Link Name="CdaRefHospReahabExamCons" Type="AKUZ.CDA_REF_HOSP_REAHAB_EXAM_CONS" Description="Направление на госпитализацию, восстановительное лечение, обследование, консультацию в формате CDA" LinkAttribute="HospitalizationReferral" />
    <Attribute Name="AnotherDivisionOid" Type="string" Description="Oid удаленного отделения" />
    <Attribute Name="AnotherDivisionName" Type="string" Description="Имя удаленного отделения" />
    <Attribute Name="AnotherLpu" Type="string" Description="Наименование удаленного МО" />
    <Attribute Name="AnotherLpuAdress" Type="string" Description="Адрес удаленного МО" />
    <Attribute Name="AnotherProfileName" Type="string" Description="Наименование удаленного профиля койки" />
    <Link Name="ConfirmHospitalizationRefferal" Type="AKUZ.CONFIRM_HOSPITALIZATION_REFFERAL" Description="Сведения о полученном лечении" LinkAttribute="HospitalizationReferral" />
    <Attribute Name="ApprovedHospitalDate" Type="datetime" Description="Дата утвержденной госпитализации" />
    <Attribute Name="NeedConsiliumSign" Type="bool" Description="Требуется решение консилиума" Required="1" />
    <Child Name="RefferalCallInfos" Type="AKUZ.REFFERAL_CALL_INFO" Description="Информация об информировании пациента о госпитализации" ChildAttribute="HospitalizationReferral" />
    <Attribute Name="ProtokolKek" Index="12290007" Type="bool" Description="Наличие протокола ВК" Required="1" />
    <Attribute Name="VKNumber" Type="string" Description="Номер ВК" CharacterMaximumLength="20" />
    <Attribute Name="VKDate" Type="datetime" Description="Дата и время ВК" />
  </Fields>
  <DbMapping>
    <Table name="T_HOSPITALIZATION_REFERRAL">
      <Map Name="MedicalCertificateObtain" Column="MedicalCertificateObtain" />
      <Map Name="HtmlDocument" Column="HtmlDocument" />
      <Map Name="HospitalisationDate" Column="HospitalisationDate" />
      <Map Name="DocDocument" Column="DocDocument" />
      <Map Name="Email" Column="Email" />
      <Map Name="Phone" Column="Phone" />
      <Map Name="PreHospitalDate" Column="PreHospitalDate" />
      <Map Name="ReferralNumber" Column="ReferralNumber" />
      <Map Name="NeedOperation" Column="NeedOperation" />
      <Map Name="ErrorReserv" Column="ErrorReserv" />
      <Map Name="AnotherRegion" Column="AnotherRegion" />
      <Map Name="HospitalizationType" Column="HospitalizationType" />
      <Map Name="HospitalType" Column="HospitalType" />
      <Map Name="ChannelsHospitalisation" Column="ChannelsHospitalisation" />
      <Map Name="Branch" Column="Branch" />
      <Map Name="StructureBed" Column="StructureBed" />
      <Map Name="Status" Column="Status" />
      <Map Name="ContactsConfirmDate" Column="ContactsConfirmDate" />
      <Map Name="CancelFlag" Column="CancelFlag" />
      <Map Name="AnotherDivisionOid" Column="AnotherDivisionOid" />
      <Map Name="AnotherDivisionName" Column="AnotherDivisionName" />
      <Map Name="AnotherLpu" Column="AnotherLpu" />
      <Map Name="AnotherLpuAdress" Column="AnotherLpuAdress" />
      <Map Name="AnotherProfileName" Column="AnotherProfileName" />
      <Map Name="ApprovedHospitalDate" Column="ApprovedHospitalDate" />
      <Map Name="NeedConsiliumSign" Column="NeedConsiliumSign" />
      <Map Name="ProtokolKek" Column="ProtokolKek" />
      <Map Name="VKNumber" Column="VKNumber" />
      <Map Name="VKDate" Column="VKDate" />
    </Table>
    <Lexem>
      <Map Name="RegRefNumber">
        <lx:MathOperator sign="+" xmlns:lx="lexem">
          <lx:MathOperator sign="+">
            <lx:Path OwnerQueryLevel="0">
              <lx:StepInt index="5460002" />
              <lx:StepInt index="5620006" />
              <lx:StepInt index="5060004" />
              <lx:StepInt index="5170001" />
              <lx:StepInt index="5470017" />
            </lx:Path>
            <lx:Cast type="String">
              <lx:DatePart datepart="Year">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepInt index="5560006" />
                </lx:Path>
              </lx:DatePart>
            </lx:Cast>
          </lx:MathOperator>
          <lx:Cast type="String">
            <lx:PadLeft>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepInt index="5680014" />
              </lx:Path>
              <lx:ConstOperand type="String"><![CDATA[0]]></lx:ConstOperand>
              <lx:ConstOperand type="Int32">11</lx:ConstOperand>
            </lx:PadLeft>
          </lx:Cast>
        </lx:MathOperator>
      </Map>
      <Map Name="EmergencyEvent">
        <lx:QueryValue entity="AKUZ.EMERGENCY_EVENT" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Direction" />
                  <lx:StepString name="DirectionDate" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="ReferralDate" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Direction" />
                  <lx:StepString name="Lpu" />
                  <lx:StepString name="LpuCode" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Lpu" />
                  <lx:StepString name="LpuCode" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Direction" />
                  <lx:StepString name="DirectionNumber" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="ReferralNumber" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Direction" />
                  <lx:StepString name="DirectorLpu" />
                  <lx:StepString name="LpuCode" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Post" />
                  <lx:StepString name="Division" />
                  <lx:StepString name="Branch" />
                  <lx:StepString name="LpuMain" />
                  <lx:StepString name="LpuCode" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="EventID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="RdsHospitalizationReferral">
        <lx:QueryValue entity="AKUZ.RDS_HOSPITALIZATION_REFERRAL" top="1" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="DivisionTo" />
                  <lx:StepString name="DivisionID" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Division" />
                  <lx:StepString name="DivisionID" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="ReferralDate" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="ReferralDate" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="BranchFrom" />
                  <lx:StepString name="LpuID" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Post" />
                  <lx:StepString name="Division" />
                  <lx:StepString name="Branch" />
                  <lx:StepString name="LpuID" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="ReferralNumber" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="ReferralNumber" />
                </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="TFomsCode" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Lpu" />
                  <lx:StepString name="TFomsCode" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="RdsHospitalizationReferralID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Attribute Name="FilesXml" Index="5680020" Type="string" Description="FilesXml" RequiredAttributes="{DirectionMedicalDocumentations / Name}" />
  </CalculatingAttributes>
</Entity>