<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="IES" 
Name="MEDICAL_EXPERTISE" 
Description="Отбор на медицинскую эксперизу" 
PrimaryKey="MedicalExpertiseID" 
DNAttributes="{MedicalExpertiseFolder/Caption};{Number};{ExpertiseDate}" 
DisplayName="{0} №{1} от {2}">
  <Fields>
    <Attribute Name="MedicalExpertiseID" Index="6010001" Type="guid" Description="Идентификатор" />
    <Attribute Name="Number" Index="6010002" Type="int" Description="Номер отбора" Required="1" />
    <Attribute Name="Descr" Index="6010006" Type="string" Description="Описание отбора" />
    <Attribute Name="ExpertiseDate" Index="6010009" Type="date" Description="Дата создания отбора" Required="1" />
    <Attribute Name="LastExpertiseStart" Index="6010010" Type="datetime" Description="Дата и время последнего отбора" />
    <Attribute Name="IsArchive" Index="6010013" Type="bool" Description="В архиве" DefaultValue="0" Required="1" />
    <Parent Name="F006ControlType" Type="IES.F006_CONTROL_TYPE" Description="Вид экспертизы" />
    <Parent Name="Worker" Index="6010005" Type="IES.WORKER" Description="Сотрудник" Required="1" />
    <Parent Name="Users" Index="6010008" Type="IES.USERS" Description="Пользователь системы" Required="1" />
    <Parent Name="MedicalExpertiseFolder" Index="6010014" Type="IES.MEDICAL_EXPERTISE_FOLDER" Description="Подраздел мед. экспертизы" Required="1" />
    <Child Name="MedicalExpertiseSchets" Index="6010007" Type="IES.MEDICAL_EXPERTISE_SCHET" Description="Счета, вошедшие в отбор" ChildAttribute="MedicalExpertise" />
    <Child Name="MedicalRequests" Index="6010012" Type="IES.MEDICAL_REQUEST" Description="Медицинские заявки" ChildAttribute="MedicalExpertise" />
    <Attribute Name="IsManualTaked" Type="bool" Description="IsManualTaked" />
    <Parent Name="ExpertiseTypePodvid" Type="IES.EXPERTISE_TYPE_PODVID" Description="Подвид экспертизы" />
    <Child Name="MedicalExpertiseCriterias" Type="IES.MEDICAL_EXPERTISE_CRITERIA" Description="Критерии медецинского отбора" ChildAttribute="MedicalExpertise" />
    <Choice Name="Status" Description="Cостояние отбора">
      <Item Name="Отбор счетов" Index="0" />
      <Item Name="Отбор случаев" Index="1" />
      <Item Name="Созданы заявки" Index="2" />
      <Item Name="Закрыт" Index="3" />
    </Choice>
    <Choice Name="GeneratedBy" Description="Сгенерирован">
      <Item Name="Экспертизой МЭЭ, ЭКМП на МТР от МО" Index="0" />
    </Choice>
    <Child Name="SmoActs" Type="IES.SMO_ACT" Description="Акты экспертизы СМО" ChildAttribute="MedicalExpertise" />
    <Attribute Name="SchetsCount" Type="int" Description="Количество счетов в отборе" />
    <Attribute Name="IsReexpertise" Type="bool" Description="Реэкспертиза" DefaultValue="0" Required="1" />
    <Attribute Name="IsMultiEkmp" Type="bool" Description="Признак мультидисциплинарной ЭКМП" DefaultValue="0" Required="1" />
    <Child Name="MedicalExpertiseItems" Type="IES.MEDICAL_EXPERTISE_ITEM" Description="Случай, вошедший в отбор" ChildAttribute="MedicalExpertise" />
  </Fields>
  <DbMapping>
    <Table name="T_MEDICAL_EXPERTISE">
      <Map Name="MedicalExpertiseID" Column="MedicalExpertiseID" />
      <Map Name="Number" Column="Number" />
      <Map Name="Descr" Column="Descr" />
      <Map Name="ExpertiseDate" Column="ExpertiseDate" />
      <Map Name="LastExpertiseStart" Column="LastExpertiseStart" />
      <Map Name="IsArchive" Column="IsArchive" />
      <Map Name="F006ControlType" Column="F006ControlType" />
      <Map Name="Worker" Column="Worker" />
      <Map Name="Users" Column="Users" />
      <Map Name="MedicalExpertiseFolder" Column="MedicalExpertiseFolder" />
      <Map Name="IsManualTaked" Column="IsManualTaked" />
      <Map Name="ExpertiseTypePodvid" Column="ExpertiseTypePodvid" />
      <Map Name="Status" Column="Status" />
      <Map Name="GeneratedBy" Column="GeneratedBy" />
      <Map Name="IsReexpertise" Column="IsReexpertise" />
      <Map Name="IsMultiEkmp" Column="IsMultiEkmp" />
    </Table>
    <Lexem>
      <Map Name="SchetsCount">
        <lx:QueryValue entity="IES.MEDICAL_EXPERTISE_SCHET" top="-1" offset="0" hints="" xmlns:lx="lexem">
          <condition>
            <lx:Criteria type="And">
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="MedicalExpertise" />
                  <lx:StepString name="MedicalExpertiseID" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepString name="MedicalExpertiseID" />
                </lx:Path>
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Schet" />
                  <lx:StepString name="IsDelete" />
                </lx:Path>
                <lx:ConstOperand type="Boolean">False</lx:ConstOperand>
              </lx:Criterion>
            </lx:Criteria>
          </condition>
          <value>
            <lx:Count />
          </value>
        </lx:QueryValue>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Attribute Name="IncludedMo" Index="6010011" Type="text" Description="МО, вошедшие в отбор" RequiredAttributes="{MedicalExpertiseSchets/Schet/as IES.OMS_SCHET/CODE_MO/NAM_MOK}" />
  </CalculatingAttributes>
</Entity>