<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="WAITING_LIST" 
Description="Лист ожидания" 
PrimaryKey="WaitingListID">
  <Customs>
    <Custom Name="NotDisplayedInFilter" Value="ActiveEntryAmbulance" />
    <Custom Name="NotDisplayedColumns" Value="ActiveEntryAmbulance" />
    <Custom Name="NotTrackedAttributes" Value="ActiveEntryAmbulance" />
  </Customs>
  <Fields>
    <Attribute Name="WaitingListID" Index="14230001" Type="guid" Description="Идентификатор" />
    <Attribute Name="CreationDateTime" Index="14230002" Type="datetime" DefaultFormat="{0:dd.MM.yyyy HH:mm}" Description="Дата и время регистрации" Required="1" />
    <Attribute Name="DateFrom" Index="14230003" Type="date" DefaultFormat="{0:dd.MM.yyyy}" Description="Дата начала" Required="1" />
    <Attribute Name="DateTo" Index="14230004" Type="date" DefaultFormat="{0:dd.MM.yyyy}" Description="Дата окончания" Required="1" />
    <Attribute Name="TimeFrom" Index="14230005" Type="datetime" DefaultFormat="{0:HH:mm}" Description="Время начала" />
    <Attribute Name="TimeTo" Index="14230006" Type="datetime" DefaultFormat="{0:HH:mm}" Description="Время окончания" />
    <Attribute Name="Email" Index="14230013" Type="string" Description="E-mail" CharacterMaximumLength="128" />
    <Attribute Name="Complaint" Index="14230014" Type="string" Description="Причина обращения" CharacterMaximumLength="5000" />
    <Attribute Name="Phone" Index="14230017" Type="string" Description="Телефон" CharacterMaximumLength="32" Required="1" />
    <Parent Name="CreatorUser" Index="14230007" Type="AKUZ.USERS" Description="Пользователь" />
    <Parent Name="AmbulanceCard" Index="14230009" Type="AKUZ.AMBULANCE_CARD" Description="Амбулаторная карта" />
    <Parent Name="EntryAmbulance" Index="14230010" Type="AKUZ.ENTRY_AMBULANCE" Description="Запись на прием амбулаторно" />
    <Parent Name="Speciality" Index="14230011" Type="AKUZ.SPECIALITY" Description="Специальность" Required="1" />
    <Parent Name="Resource" Index="14230012" Type="AKUZ.RESOURCE" Description="Ресурс" />
    <Parent Name="Branch" Index="14230021" Type="AKUZ.BRANCH" Description="Филиал" Required="1" />
    <Choice Name="EntryPlace" Index="14230008" Description="Место записи" Required="1">
      <Item Name="Не указано" Index="0" />
      <Item Name="Регистратура" Index="1" />
      <Item Name="Веб-портал" Index="2" />
      <Item Name="Удаленная запись" Index="3" />
      <Item Name="Интернет-запись" Index="4" />
      <Item Name="Call-center" Index="5" />
      <Item Name="Госуслуги" Index="6" />
      <Item Name="Доктор" Index="7" />
      <Item Name="Инфомат" Index="8" />
      <Item Name="Робот122" Index="9" />
    </Choice>
    <Choice Name="Status" Index="14230016" Description="Статус" Required="1">
      <Item Name="Создана" Index="0" />
      <Item Name="В работе" Index="1" />
      <Item Name="Обработана" Index="2" />
      <Item Name="Отменена" Index="3" />
      <Item Name="Исключена" Index="4" />
      <Item Name="Ошибка" Index="5" />
    </Choice>
    <Child Name="WaitingListCalls" Index="14230022" Type="AKUZ.WAITING_LIST_CALL" Description="Телефонные звонки" ChildAttribute="WaitingList" />
    <Parent Name="AmbulanceEvent" Index="14230023" Type="AKUZ.AMBULANCE_EVENT" Description="Амбулаторный случай обращения" />
    <Parent Name="LastCall" Index="14230024" Type="AKUZ.WAITING_LIST_CALL" Description="Последний телефонный звонок" />
    <Attribute Name="EnableAutoRec" Type="bool" Description="Автоматическая запись" Required="1" />
    <Parent Name="DispanserisationPresence" Type="AKUZ.DISPANSERISATION_PRESENCE" Description="Контроль посещений по Д-наблюдению" />
    <Choice Name="PreferredWeek" IsFlag="1" Description="Предпочтительный день недели для записи" Required="1">
      <Item Name="Понедельник" Index="1" />
      <Item Name="Вторник" Index="2" />
      <Item Name="Среда" Index="4" />
      <Item Name="Четверг" Index="8" />
      <Item Name="Пятница" Index="16" />
      <Item Name="Суббота" Index="32" />
      <Item Name="Воскресенье" Index="64" />
    </Choice>
    <Attribute Name="Number" Type="int" Description="Номер заявки" Required="1" />
    <Choice Name="NotificationType" IsFlag="1" Description="Тип оповещения" Required="1">
      <Item Name="Портал" Index="1" />
      <Item Name="Оператор (колл центр)" Index="2" />
      <Item Name="смс/e-mail" Index="4" />
    </Choice>
    <Parent Name="ActiveEntryAmbulance" Type="AKUZ.ENTRY_AMBULANCE" Description="Активная запись на прием" />
    <Parent Name="RemoteEntry" Type="AKUZ.REMOTE_ENTRY" Description="Запись на прием" />
    <Attribute Name="RouteRecordID" Type="guid" Description="Идентификатор направления" />
    <Attribute Name="RouteDate" Type="date" DefaultFormat="{0:dd.MM.yyyy}" Description="Дата направления" />
    <Parent Name="MedicalService" Type="AKUZ.MEDICAL_SERVICE" Description="Медицинские услуги" />
    <Attribute Name="ErrorAutoRecord" Type="string" Description="Ошибка автозаписи" CharacterMaximumLength="1024" />
  </Fields>
  <DbMapping>
    <Table name="T_WAITING_LIST">
      <Map Name="WaitingListID" Column="WaitingListID" />
      <Map Name="CreationDateTime" Column="CreationDateTime" />
      <Map Name="DateFrom" Column="DateFrom" />
      <Map Name="DateTo" Column="DateTo" />
      <Map Name="TimeFrom" Column="TimeFrom" />
      <Map Name="TimeTo" Column="TimeTo" />
      <Map Name="Email" Column="Email" />
      <Map Name="Complaint" Column="Complaint" />
      <Map Name="Phone" Column="Phone" />
      <Map Name="CreatorUser" Column="CreatorUser" />
      <Map Name="AmbulanceCard" Column="AmbulanceCard" />
      <Map Name="EntryAmbulance" Column="EntryAmbulance" />
      <Map Name="Speciality" Column="Speciality" />
      <Map Name="Resource" Column="Resource" />
      <Map Name="Branch" Column="Branch" />
      <Map Name="EntryPlace" Column="EntryPlace" />
      <Map Name="Status" Column="Status" />
      <Map Name="AmbulanceEvent" Column="AmbulanceEvent" />
      <Map Name="EnableAutoRec" Column="EnableAutoRec" />
      <Map Name="DispanserisationPresence" Column="DispanserisationPresence" />
      <Map Name="PreferredWeek" Column="PreferredWeek" />
      <Map Name="Number" Column="Number" />
      <Map Name="NotificationType" Column="NotificationType" />
      <Map Name="RemoteEntry" Column="RemoteEntry" />
      <Map Name="RouteRecordID" Column="RouteRecordID" />
      <Map Name="RouteDate" Column="RouteDate" />
      <Map Name="MedicalService" Column="MedicalService" />
      <Map Name="ErrorAutoRecord" Column="ErrorAutoRecord" />
    </Table>
    <Lexem>
      <Map Name="LastCall">
        <lx:QueryValue entity="AKUZ.WAITING_LIST_CALL" top="1" xmlns:lx="lexem">
          <condition>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepInt index="2" />
                <lx:StepInt index="14230001" />
              </lx:Path>
              <lx:Path OwnerQueryLevel="1">
                <lx:StepInt index="14230001" />
              </lx:Path>
            </lx:Criterion>
          </condition>
          <orderBy>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepInt index="8" />
            </lx:Path>
            <desc>True</desc>
          </orderBy>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepInt index="1" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
      <Map Name="ActiveEntryAmbulance">
        <lx:QueryValue entity="AKUZ.ENTRY_AMBULANCE" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Resource" />
                  <lx:StepString name="Speciality" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="Speciality" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="&gt;">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="EntryDate" />
                </lx:Path>
                <lx:DateAdd datepart="Day">
                  <lx:ConstOperand type="Int32">-1</lx:ConstOperand>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="CreationDateTime" />
                  </lx:Path>
                </lx:DateAdd>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="EntryAmbulance" />
                </lx:Path>
                <lx:BaseObjectOperand Entity="AKUZ.ENTRY_AMBULANCE" isNull="1" />
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="AmbulanceEvent" />
                  <lx:StepString name="AmbulanceCard" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="AmbulanceCard" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criteria type="Or">
                <lx:Criteria type="And">
                  <lx:Criterion type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepAs as="AKUZ.ENTRY_TO_MEDSERVICE" />
                      <lx:StepString name="MedicalService" />
                    </lx:Path>
                    <lx:BaseObjectOperand Entity="AKUZ.MEDICAL_SERVICE" isNull="1" />
                  </lx:Criterion>
                  <lx:Criterion type="=">
                    <lx:Path OwnerQueryLevel="1">
                      <lx:StepString name="MedicalService" />
                    </lx:Path>
                    <lx:BaseObjectOperand Entity="AKUZ.MEDICAL_SERVICE" isNull="1" />
                  </lx:Criterion>
                </lx:Criteria>
                <lx:Criteria type="And">
                  <lx:Criterion type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepAs as="AKUZ.ENTRY_TO_MEDSERVICE" />
                      <lx:StepString name="MedicalService" />
                    </lx:Path>
                    <lx:Path OwnerQueryLevel="1">
                      <lx:StepString name="MedicalService" />
                    </lx:Path>
                  </lx:Criterion>
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="1">
                      <lx:StepString name="MedicalService" />
                    </lx:Path>
                    <lx:BaseObjectOperand Entity="AKUZ.MEDICAL_SERVICE" isNull="1" />
                  </lx:Criterion>
                </lx:Criteria>
              </lx:Criteria>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="EntryBaseID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>