<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="RECIPE_BASE" 
Description="Базовый рецепт" 
DNAttributes="{Number};{PostingDate};{AmbulanceEvent/AmbulanceCard/Patient/cFIO}" 
DisplayName="{0} - {1} ({2})" 
Inherits="AKUZ.AMBULANCE_RECORD">
  <Customs>
    <Custom Name="NotDisplayedInFilter" Value="ChangedByPharmacy;RecipeDate" />
    <Custom Name="NotDisplayedColumns" Value="ChangedByPharmacy;RecipeDate" />
    <Custom Name="NotTrackedAttributes" Value="ChangedByPharmacy;RecipeDate" />
    <Custom Name="FilterUICondition"><![CDATA[<lx:Criterion type="=" xmlns:lx="lexem">
    <lx:Path OwnerQueryLevel="0">
        <lx:StepString name="AmbulanceCard" />
        <lx:StepString name="CardLpu" />
    </lx:Path>
    <lx:ParamHolder>
        <lx:StepString name="CURRENT_LPU_MAIN" />
    </lx:ParamHolder>
</lx:Criterion>]]></Custom>
  </Customs>
  <Fields>
    <Attribute Name="Serial" Index="6320006" Type="string" Description="Серия" Required="1" />
    <Attribute Name="Number" Index="6320007" Type="bigint" Description="Номер" Required="1" />
    <Attribute Name="Deleted" Index="6320016" Type="bool" Description="Удален/отбракован" Required="1" />
    <Attribute Name="DeleteReason" Index="6320017" Type="string" Description="Причина удаления" />
    <Attribute Name="CreationDateTime" Index="6320033" Type="datetime" DefaultFormat="{0:dd.MM.yyyy HH:mm}" Description="Дата и время регистрации" />
    <Attribute Name="DeleteDateTime" Index="6320036" Type="datetime" DefaultFormat="{0:dd.MM.yyyy HH:mm}" Description="Дата и время отбраковки" />
    <Attribute Name="IsChronic" Index="6320038" Type="bool" Description="Пациент с хроническим заболеванием" Required="1" />
    <Attribute Name="MKBCode" Index="6370007" Type="string" Description="Код заболевания по классификатору МКБ" CharacterMaximumLength="8" Required="1" />
    <Parent Name="CreatorUser" Index="6320034" Type="AKUZ.USERS" Description="Пользователь" />
    <Parent Name="DeleteUser" Index="6320035" Type="AKUZ.USERS" Description="Пользователь отбраковки" />
    <Child Name="RecipePrintHistory" Index="6320055" Type="AKUZ.RECIPE_PRINT_HISTORY" Description="Журнал распечатки рецепта" ChildAttribute="Recipe" />
    <Choice Name="Period" Index="6320015" Description="Срок действия" Required="1">
      <Item Name="30 дней" Index="0" />
      <Item Name="14 дней" Index="1" />
      <Item Name="90 дней" Index="2" />
      <Item Name="5 дней" Index="3" />
      <Item Name="10 дней" Index="4" />
      <Item Name="15 дней" Index="5" />
      <Item Name="60 дней" Index="6" />
      <Item Name="до года" Index="7" />
    </Choice>
    <Child Name="RecipeSignatures" Type="AKUZ.RECIPE_SIGNATURE" Description="Подпись рецепта" ChildAttribute="RecipeBase" SortingAttr="SignatureDateTime" />
    <Attribute Name="KladrAddress" Type="string" Description="Код адреса по КЛАДР" />
    <Attribute Name="DayDose" Type="float" Description="Суточная доза" NumericPrecision="10" NumericScale="2" />
    <Attribute Name="DayQuantity" Type="int" Description="Количество в сутки" />
    <Attribute Name="IntakeBeginDate" Type="date" Description="Дата начала приема" />
    <Attribute Name="IntakeEndDate" Type="date" Description="Дата окончания приема" />
    <Choice Name="CalcMethod" Description="Метод вычисления" Required="1">
      <Item Name="Единиц на прием" Index="1" />
      <Item Name="Дневная доза" Index="2" />
      <Item Name="Недельная доза" Index="3" />
    </Choice>
    <Choice Name="SyncState" IsFlag="1" Description="Состояние синхронизации" Required="1">
      <Item Name="AKUZ" Index="1" />
      <Item Name="RDS" Index="2" />
      <Item Name="APS" Index="4" />
    </Choice>
    <Choice Name="Status" 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" />
      <Item Name="Реализован" Index="6" />
    </Choice>
    <Attribute Name="ChangedByPharmacy" Type="bool" Description="Статус изменен аптекой" />
    <Attribute Name="Cito" Type="bool" Description="Признак срочного отпуска препарата" Required="1" />
    <Attribute Name="Statim" Type="bool" Description="Признак немедленного отпуска препарата" Required="1" />
    <Attribute Name="Spec" Type="bool" Description="Отметка о специальном назначении ЛП" Required="1" />
    <Attribute Name="RecipeEndDate" Type="date" Description="Дата окончания срока действия рецепта" />
    <Attribute Name="DarsId" Type="guid" Description="Идентификатор в единой системе назначений" />
    <Attribute Name="Diagnosis" Type="string" Description="Описание диагноза" />
    <Attribute Name="VKNumber" Type="string" Description="Номер ВК" CharacterMaximumLength="20" />
    <Attribute Name="VKDate" Type="date" Description="Дата ВК" />
    <Parent Name="VKPost" Type="AKUZ.POST" Description="Председатель ВК" />
    <Attribute Name="VKResult" Type="string" Description="Решение ВК" />
    <Attribute Name="InTheMorning6" Type="float" DefaultFormat="{0:0.#####}" Description="В 6:00" NumericPrecision="6" NumericScale="2" Required="1" />
    <Attribute Name="BeforeBreakfast" Type="float" DefaultFormat="{0:0.#####}" Description="Перед завтраком" NumericPrecision="6" NumericScale="2" Required="1" />
    <Attribute Name="BeforeDinner" Type="float" DefaultFormat="{0:0.#####}" Description="Перед обедом" NumericPrecision="6" NumericScale="2" Required="1" />
    <Attribute Name="BeforeSupper" Type="float" DefaultFormat="{0:0.#####}" Description="Перед ужином" NumericPrecision="6" NumericScale="2" Required="1" />
    <Attribute Name="ForTheNight" Type="float" DefaultFormat="{0:0.#####}" Description="На ночь" NumericPrecision="6" NumericScale="2" Required="1" />
    <Attribute Name="WeekQuantify" Type="int" Description="Сколько раз принимать всего" Required="1" />
    <Attribute Name="Weeks" Type="int" Description="В течение скольки недель" Required="1" />
    <Attribute Name="WeekDose" Type="int" Description="По сколько за раз" Required="1" />
    <Attribute Name="MedicalRecordType" Type="int" Description="Индекс сущности рецепта" />
    <Link Name="CdaRecipe" Type="AKUZ.CDA_RECIPE" Description="Рецепт в формате CDA" LinkAttribute="RecipeBase" />
    <Attribute Name="RecipeDate" Type="date" Description="Дата выписки рецепта" />
    <Attribute Name="Year" Type="int" Description="Год выписки рецепта" />
  </Fields>
  <DbMapping>
    <Table name="T_RECIPE">
      <Map Name="Serial" Column="Serial" />
      <Map Name="Number" Column="Number" />
      <Map Name="Deleted" Column="Deleted" />
      <Map Name="DeleteReason" Column="DeleteReason" />
      <Map Name="CreationDateTime" Column="CreationDateTime" />
      <Map Name="DeleteDateTime" Column="DeleteDateTime" />
      <Map Name="IsChronic" Column="IsChronic" />
      <Map Name="MKBCode" Column="MKBCode" />
      <Map Name="CreatorUser" Column="CreatorUser" />
      <Map Name="DeleteUser" Column="DeleteUser" />
      <Map Name="Period" Column="Period" />
      <Map Name="DayDose" Column="DayDose" />
      <Map Name="DayQuantity" Column="DayQuantity" />
      <Map Name="IntakeBeginDate" Column="IntakeBeginDate" />
      <Map Name="IntakeEndDate" Column="IntakeEndDate" />
      <Map Name="CalcMethod" Column="CalcMethod" />
      <Map Name="SyncState" Column="SyncState" />
      <Map Name="Status" Column="Status" />
      <Map Name="Cito" Column="Cito" />
      <Map Name="Statim" Column="Statim" />
      <Map Name="Spec" Column="Spec" />
      <Map Name="DarsId" Column="DarsId" />
      <Map Name="VKNumber" Column="VKNumber" />
      <Map Name="VKDate" Column="VKDate" />
      <Map Name="VKPost" Column="VKPost" />
      <Map Name="VKResult" Column="VKResult" />
      <Map Name="InTheMorning6" Column="InTheMorning6" />
      <Map Name="BeforeBreakfast" Column="BeforeBreakfast" />
      <Map Name="BeforeDinner" Column="BeforeDinner" />
      <Map Name="BeforeSupper" Column="BeforeSupper" />
      <Map Name="ForTheNight" Column="ForTheNight" />
      <Map Name="WeekQuantify" Column="WeekQuantify" />
      <Map Name="Weeks" Column="Weeks" />
      <Map Name="WeekDose" Column="WeekDose" />
      <Map Name="MedicalRecordType" Column="MedicalRecordType" />
      <Map Name="Year" Column="Year" />
    </Table>
    <Lexem>
      <Map Name="KladrAddress">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criteria type="And">
              <lx:Criterion not="1" type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="AmbulanceEvent" />
                  <lx:StepString name="AmbulanceCard" />
                  <lx:StepString name="Patient" />
                  <lx:StepString name="AddressReal" />
                  <lx:StepString name="Street" />
                  <lx:StepString name="Code" />
                </lx:Path>
                <lx:ConstOperand isNull="1" />
              </lx:Criterion>
              <lx:Not>
                <lx:IsEmptyString>
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="AmbulanceEvent" />
                    <lx:StepString name="AmbulanceCard" />
                    <lx:StepString name="Patient" />
                    <lx:StepString name="AddressReal" />
                    <lx:StepString name="Street" />
                    <lx:StepString name="Code" />
                  </lx:Path>
                </lx:IsEmptyString>
              </lx:Not>
            </lx:Criteria>
          </When>
          <Then>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="AmbulanceEvent" />
              <lx:StepString name="AmbulanceCard" />
              <lx:StepString name="Patient" />
              <lx:StepString name="AddressReal" />
              <lx:StepString name="Street" />
              <lx:StepString name="Code" />
            </lx:Path>
          </Then>
          <When>
            <lx:Criteria type="And">
              <lx:Criterion not="1" type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="AmbulanceEvent" />
                  <lx:StepString name="AmbulanceCard" />
                  <lx:StepString name="Patient" />
                  <lx:StepString name="AddressReal" />
                  <lx:StepString name="District" />
                  <lx:StepString name="Code" />
                </lx:Path>
                <lx:ConstOperand isNull="1" />
              </lx:Criterion>
              <lx:Not>
                <lx:IsEmptyString>
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="AmbulanceEvent" />
                    <lx:StepString name="AmbulanceCard" />
                    <lx:StepString name="Patient" />
                    <lx:StepString name="AddressReal" />
                    <lx:StepString name="District" />
                    <lx:StepString name="Code" />
                  </lx:Path>
                </lx:IsEmptyString>
              </lx:Not>
            </lx:Criteria>
          </When>
          <Then>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="AmbulanceEvent" />
              <lx:StepString name="AmbulanceCard" />
              <lx:StepString name="Patient" />
              <lx:StepString name="AddressReal" />
              <lx:StepString name="District" />
              <lx:StepString name="Code" />
            </lx:Path>
          </Then>
          <When>
            <lx:Criteria type="And">
              <lx:Criterion not="1" type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="AmbulanceEvent" />
                  <lx:StepString name="AmbulanceCard" />
                  <lx:StepString name="Patient" />
                  <lx:StepString name="AddressReal" />
                  <lx:StepString name="City" />
                  <lx:StepString name="Code" />
                </lx:Path>
                <lx:ConstOperand isNull="1" />
              </lx:Criterion>
              <lx:Not>
                <lx:IsEmptyString>
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="AmbulanceEvent" />
                    <lx:StepString name="AmbulanceCard" />
                    <lx:StepString name="Patient" />
                    <lx:StepString name="AddressReal" />
                    <lx:StepString name="City" />
                    <lx:StepString name="Code" />
                  </lx:Path>
                </lx:IsEmptyString>
              </lx:Not>
            </lx:Criteria>
          </When>
          <Then>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="AmbulanceEvent" />
              <lx:StepString name="AmbulanceCard" />
              <lx:StepString name="Patient" />
              <lx:StepString name="AddressReal" />
              <lx:StepString name="City" />
              <lx:StepString name="Code" />
            </lx:Path>
          </Then>
          <Else>
            <lx:ConstOperand isNull="1" />
          </Else>
        </lx:Case>
      </Map>
      <Map Name="RecipeEndDate">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Period" />
              </lx:Path>
              <lx:ChoiceOperand Entity="AKUZ.RECIPE_BASE" AttributeName="Period" type="Int32" PrimaryKey="0" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:DateAdd datepart="Day">
              <lx:ConstOperand type="Int32">29</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Then>
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Period" />
              </lx:Path>
              <lx:ChoiceOperand Entity="AKUZ.RECIPE_BASE" AttributeName="Period" type="Int32" PrimaryKey="1" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:DateAdd datepart="Day">
              <lx:ConstOperand type="Int32">13</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Then>
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Period" />
              </lx:Path>
              <lx:ChoiceOperand Entity="AKUZ.RECIPE_BASE" AttributeName="Period" type="Int32" PrimaryKey="2" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:DateAdd datepart="Day">
              <lx:ConstOperand type="Int32">89</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Then>
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Period" />
              </lx:Path>
              <lx:ChoiceOperand Entity="AKUZ.RECIPE_BASE" AttributeName="Period" type="Int32" PrimaryKey="3" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:DateAdd datepart="Day">
              <lx:ConstOperand type="Int32">4</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Then>
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Period" />
              </lx:Path>
              <lx:ChoiceOperand Entity="AKUZ.RECIPE_BASE" AttributeName="Period" type="Int32" PrimaryKey="4" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:DateAdd datepart="Day">
              <lx:ConstOperand type="Int32">9</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Then>
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Period" />
              </lx:Path>
              <lx:ChoiceOperand Entity="AKUZ.RECIPE_BASE" AttributeName="Period" type="Int32" PrimaryKey="5" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:DateAdd datepart="Day">
              <lx:ConstOperand type="Int32">14</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Then>
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Period" />
              </lx:Path>
              <lx:ChoiceOperand Entity="AKUZ.RECIPE_BASE" AttributeName="Period" type="Int32" PrimaryKey="6" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:DateAdd datepart="Day">
              <lx:ConstOperand type="Int32">59</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Then>
          <Else>
            <lx:DateAdd datepart="Year">
              <lx:ConstOperand type="Int32">1</lx:ConstOperand>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="PostingDate" />
              </lx:Path>
            </lx:DateAdd>
          </Else>
        </lx:Case>
      </Map>
      <Map Name="Diagnosis">
        <lx:QueryValue entity="AKUZ.MKB" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="MCBCode" />
              </lx:Path>
              <lx:Path OwnerQueryLevel="1">
                <lx:StepString name="MKBCode" />
              </lx:Path>
            </lx:Criterion>
          </condition>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="Name" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
    </Lexem>
    <Table name="T_MEDICAL_RECORD">
      <Map Name="RecipeDate" Column="PostingDate" />
    </Table>
  </DbMapping>
  <CalculatingAttributes>
    <Parent Name="LastCardNote" Type="AKUZ.CARD_NOTE" Description="Последний созданный действующий документ" RequiredAttributes="{CardNotes/ As AKUZ.CN_CDA_RECIPE/ CdaDocument};{CardNotes/PostingDate}" PathAttributes="{CardNotes}" />
  </CalculatingAttributes>
</Entity>