<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="BSK_REGISTER_RECORDS" 
Description="Запись в БСК регистре" 
PrimaryKey="BskRegisterRecordsID" 
DNAttributes="{Patient/cFIO}" 
DisplayName="Запись в БСК регистре на пациента {0}">
  <Fields>
    <Attribute Name="BskRegisterRecordsID" Type="guid" Description="Идентификатор" />
    <Attribute Name="DateBegin" Type="date" Description="Дата с" Required="1" />
    <Attribute Name="DateEnd" Type="date" Description="Дата по" />
    <Parent Name="Patient" Type="AKUZ.PATIENT" Description="Пациент" Required="1" />
    <Parent Name="MedicalService" Type="AKUZ.MEDICAL_SERVICE" Description="Медицинская услуга" />
    <Attribute Name="Diagnosis" Type="string" Description="Диагноз" CharacterMaximumLength="4096" />
    <Attribute Name="Mkb" Type="string" Description="Код МКБ" CharacterMaximumLength="10" Required="1" />
    <Choice Name="ExclusionReason" Description="Причина исключения" Required="1">
      <Item Name="Окончание срока действия терапии" Index="0" />
      <Item Name="Замена терапии " Index="1" />
      <Item Name="Смерть" Index="2" />
      <Item Name="Переезд в другой регион" Index="3" />
      <Item Name="Техническая ошибка" Index="4" />
    </Choice>
    <Parent Name="LpuMain" Type="AKUZ.LPU_MAIN" Description="МО" Required="1" />
    <Parent Name="LpuMainTo" Type="AKUZ.LPU_MAIN" Description="МО прикрепления" Required="1" />
    <Child Name="BskRegisterLinkMnns" Type="AKUZ.BSK_REGISTER_LINK_MNN" Description="Препараты" ChildAttribute="BskRegisterRecords" />
    <Parent Name="Post" Type="AKUZ.POST" Description="Должность" Required="1" />
    <Attribute Name="EstimatedDDate" Type="date" Description="Предполагаемая дата постановки на Д учет" Required="1" />
    <Attribute Name="DRegistrationDate" Type="date" Description="Дата постановки на Д учет" />
    <Choice Name="Place" Description="Место установки льготы" Required="1">
      <Item Name="Стационар" Index="0" />
      <Item Name="Поликлиника" Index="1" />
    </Choice>
    <Attribute Name="Federal" Type="bool" Description="Федеральный льготник" />
    <Parent Name="BskRegisterRecords" Type="AKUZ.BSK_REGISTER_RECORDS" Description="Запись в БСК регистре" />
    <Parent Name="Benefits" Type="AKUZ.BENEFITS" Description="Льготы" Required="1" />
    <Attribute Name="CloseDate" Type="date" Description="Дата закрытия" />
    <Attribute Name="CreateDate" Type="datetime" DefaultFormat="{0:dd.MM.yyyy HH:mm}" Description="Дата создания" Required="1" />
    <Attribute Name="LastEditDateTime" Type="datetime" DefaultFormat="{0:dd.MM.yyyy HH:mm}" Description="Дата и время последних изменений" Required="1" />
    <Child Name="BskRegisterComplicationLinks" Type="AKUZ.BSK_REGISTER_COMPLICATION_LINK" Description="Осложнения БСК" ChildAttribute="BskRegisterRecords" />
  </Fields>
  <DbMapping>
    <Table name="T_BSK_REGISTER_RECORDS">
      <Map Name="BskRegisterRecordsID" Column="BskRegisterRecordsID" />
      <Map Name="DateBegin" Column="DateBegin" />
      <Map Name="DateEnd" Column="DateEnd" />
      <Map Name="Patient" Column="Patient" />
      <Map Name="MedicalService" Column="MedicalService" />
      <Map Name="Diagnosis" Column="Diagnosis" />
      <Map Name="Mkb" Column="Mkb" />
      <Map Name="ExclusionReason" Column="ExclusionReason" />
      <Map Name="LpuMain" Column="LpuMain" />
      <Map Name="LpuMainTo" Column="LpuMainTo" />
      <Map Name="Post" Column="Post" />
      <Map Name="EstimatedDDate" Column="EstimatedDDate" />
      <Map Name="DRegistrationDate" Column="DRegistrationDate" />
      <Map Name="Place" Column="Place" />
      <Map Name="Benefits" Column="Benefits" />
      <Map Name="CloseDate" Column="CloseDate" />
      <Map Name="CreateDate" Column="CreateDate" />
      <Map Name="LastEditDateTime" Column="LastEditDateTime" />
    </Table>
    <Lexem>
      <Map Name="Federal">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:CriterionChildExists>
              <condition>
                <lx:Criteria type="And">
                  <lx:Criterion type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="Deleted" />
                    </lx:Path>
                    <lx:ConstOperand type="Boolean">False</lx:ConstOperand>
                  </lx:Criterion>
                  <lx:Criterion type="&lt;=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="DateBegin" />
                    </lx:Path>
                    <lx:ParamHolder>
                      <lx:StepString name="CURRENT_DATE" />
                    </lx:ParamHolder>
                  </lx:Criterion>
                  <lx:Criteria type="Or">
                    <lx:Criterion type="=">
                      <lx:Path OwnerQueryLevel="0">
                        <lx:StepString name="DateEnd" />
                      </lx:Path>
                      <lx:ConstOperand isNull="1" />
                    </lx:Criterion>
                    <lx:Criterion type="&gt;=">
                      <lx:Path OwnerQueryLevel="0">
                        <lx:StepString name="DateEnd" />
                      </lx:Path>
                      <lx:ParamHolder>
                        <lx:StepString name="CURRENT_DATE" />
                      </lx:ParamHolder>
                    </lx:Criterion>
                  </lx:Criteria>
                  <lx:CriterionChildExists not="1">
                    <condition>
                      <lx:Criterion type="&gt;">
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepString name="Version" />
                        </lx:Path>
                        <lx:Path OwnerQueryLevel="1">
                          <lx:StepString name="Version" />
                        </lx:Path>
                      </lx:Criterion>
                    </condition>
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="Snils" />
                      <lx:StepString name="FrRecords" />
                    </lx:Path>
                  </lx:CriterionChildExists>
                </lx:Criteria>
              </condition>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Patient" />
                <lx:StepString name="SNILS" />
                <lx:StepString name="FrRecords" />
              </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="BskRegisterRecords" PathAttributes="{Patient/BskRegisterRecordss}">
        <lx:ChildCount xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Place" />
                </lx:Path>
                <lx:ChoiceOperand Entity="AKUZ.BSK_REGISTER_RECORDS" AttributeName="Place" type="Int32" PrimaryKey="0" />
              </lx:Criterion>
              <lx:Criterion type="&lt;">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="CreateDate" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="CreateDate" />
                </lx:Path>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="Patient" />
            <lx:StepString name="BskRegisterRecordss" />
          </lx:Path>
          <lx:First>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepCurrent />
            </lx:Path>
          </lx:First>
          <lx:Path OwnerQueryLevel="0">
            <lx:StepString name="CreateDate" />
          </lx:Path>
          <lx:ConstOperand type="String"><![CDATA[desc]]></lx:ConstOperand>
        </lx:ChildCount>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>