<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="DRUG_DEMAND" 
Description="Потребность в препарате по заявке" 
PrimaryKey="DrugDemandID" 
DNAttributes="{cDisplayName}" 
DisplayName="{0}">
  <Customs>
    <Custom Name="NotDisplayedInFilter" Value="BaseDrugRequestItem" />
    <Custom Name="NotDisplayedColumns" Value="BaseDrugRequestItem" />
    <Custom Name="NotTrackedAttributes" Value="BaseDrugRequestItem" />
  </Customs>
  <Fields>
    <Attribute Name="DrugDemandID" Index="7260001" Type="guid" Description="Идентификатор" />
    <Attribute Name="DemandOnPeriod" Index="7260006" Type="float" Description="Потребность на период" NumericPrecision="12" NumericScale="2" Required="1" />
    <Attribute Name="RequestQuantity" Index="7260007" Type="float" Description="Заявленное количество" NumericPrecision="12" NumericScale="2" Required="1" />
    <Attribute Name="RequestCode" Index="7260010" Type="int" Description="Код в заявочном списке" Required="1" />
    <Attribute Name="LSFO" Index="7260017" Type="int" Description="Код ЛС поставщика" />
    <Attribute Name="Comment" Index="7260025" Type="string" Description="Комментарий" CharacterMaximumLength="8000" />
    <Attribute Name="Sum" Index="7260026" Type="float" Description="Сумма" NumericPrecision="12" NumericScale="2" />
    <Parent Name="DrugRequest" Index="7260002" Type="AKUZ.DRUG_REQUEST" Description="Заявка на лекарственное обеспечение" Required="1" />
    <Parent Name="BaseDrugRequestItem" Index="7260009" Type="AKUZ.BASE_DRUG_REQUEST_ITEM" Description="Базовый элемент заявочного списка" />
    <Child Name="PharmacyDrugDemands" Index="7260008" Type="AKUZ.PHARMACY_DRUG_DEMAND" Description="Потребность препарата по аптеке" ChildAttribute="DrugDemand" />
    <Child Name="DrugRequestCommentss" Index="7260027" Type="AKUZ.DRUG_REQUEST_COMMENTS" Description="Комментарии к заявке" ChildAttribute="DrugDemand" />
    <Attribute Name="SectionCode" Type="string" Description="Код подраздела" />
    <Attribute Name="PersRequest" Type="bool" Description="Персонифицированная заявка" Required="1" />
    <Attribute Name="ExistsComment" Type="bool" Description="Наличие комментария" />
    <Parent Name="RequestCatalog" Type="AKUZ.REQUEST_CATALOG" Description="Заявочный каталог" />
    <Attribute Name="cDisplayName" Type="string" Description="Наименование препарата" />
    <Attribute Name="TRN" Type="string" Description="ТРН" />
    <Attribute Name="Price" Type="float" Description="Цена" />
  </Fields>
  <DbMapping>
    <Table name="T_DRUG_DEMAND">
      <Map Name="DrugDemandID" Column="DrugDemandID" />
      <Map Name="DemandOnPeriod" Column="DemandOnPeriod" />
      <Map Name="RequestQuantity" Column="RequestQuantity" />
      <Map Name="RequestCode" Column="RequestCode" />
      <Map Name="LSFO" Column="LSFO" />
      <Map Name="Comment" Column="Comment" />
      <Map Name="DrugRequest" Column="DrugRequest" />
      <Map Name="BaseDrugRequestItem" Function="dbo.fn_GetDemandDrugRequestList" />
      <Map Name="SectionCode" Column="SectionCode" />
      <Map Name="PersRequest" Column="PersRequest" />
      <Map Name="RequestCatalog" Column="RequestCatalog" />
    </Table>
    <Lexem>
      <Map Name="Sum">
        <lx:MathOperator sign="*" xmlns:lx="lexem">
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="Price" />
          </lx:Path>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="RequestQuantity" />
          </lx:Path>
        </lx:MathOperator>
      </Map>
      <Map Name="ExistsComment">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:CriterionExists entity="AKUZ.PATIENT_DRUG_DEMAND" top="-1" offset="0">
              <condition>
                <lx:Criteria type="And">
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="Comment" />
                    </lx:Path>
                    <lx:ConstOperand isNull="1" />
                  </lx:Criterion>
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="Comment" />
                    </lx:Path>
                    <lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand>
                  </lx:Criterion>
                  <lx:Criterion type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="PharmacyDrugDemand" />
                      <lx:StepString name="DrugDemand" />
                      <lx:StepString name="DrugDemandID" />
                    </lx:Path>
                    <lx:Path OwnerQueryLevel="1">
                      <lx:StepString name="DrugDemandID" />
                    </lx:Path>
                  </lx:Criterion>
                </lx:Criteria>
              </condition>
            </lx:CriterionExists>
          </When>
          <Then>
            <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
          </Then>
          <Else>
            <lx:ConstOperand type="Boolean">False</lx:ConstOperand>
          </Else>
        </lx:Case>
      </Map>
      <Map Name="cDisplayName">
        <lx:Path OwnerQueryLevel="0" xmlns:lx="lexem">
          <lx:StepString name="RequestCatalog" />
          <lx:StepString name="Preparation" />
        </lx:Path>
      </Map>
      <Map Name="TRN">
        <lx:Path OwnerQueryLevel="0" xmlns:lx="lexem">
          <lx:StepString name="RequestCatalog" />
          <lx:StepString name="CTrn" />
          <lx:StepString name="NameRus" />
        </lx:Path>
      </Map>
      <Map Name="Price">
        <lx:Path OwnerQueryLevel="0" xmlns:lx="lexem">
          <lx:StepString name="RequestCatalog" />
          <lx:StepString name="Price" />
        </lx:Path>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Attribute Name="Mont1" Index="7260011" Type="float" Description="1 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont1}" />
    <Attribute Name="Mont2" Index="7260012" Type="float" Description="2 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont2}" />
    <Attribute Name="Mont3" Index="7260013" Type="float" Description="3 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont3}" />
    <Attribute Name="Mont4" Index="7260014" Type="float" Description="4 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont4}" />
    <Attribute Name="Mont5" Index="7260015" Type="float" Description="5 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont5}" />
    <Attribute Name="Mont6" Index="7260016" Type="float" Description="6 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont6}" />
    <Attribute Name="Mont8" Index="7260018" Type="float" Description="8 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont8}" />
    <Attribute Name="Mont9" Index="7260019" Type="float" Description="9 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont9}" />
    <Attribute Name="Mont10" Index="7260020" Type="float" Description="10 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont10}" />
    <Attribute Name="Mont11" Index="7260021" Type="float" Description="11 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont11}" />
    <Attribute Name="Mont12" Index="7260022" Type="float" Description="12 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont12}" />
    <Attribute Name="Mont7" Index="7260023" Type="float" Description="7 месяц" NumericPrecision="12" NumericScale="2" RequiredAttributes="{PharmacyDrugDemands/Mont7}" />
  </CalculatingAttributes>
</Entity>