<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="POLICY" 
Description="Полис медицинского страхования" 
PrimaryKey="PolicyID" 
DNAttributes="{Serial};{Number};{InsuranceCompany/Name}" 
DisplayName="{0} {1} ({2})">
  <Customs>
    <Custom Name="HistoryEntity" Value="AKUZ.POLICY_HISTORY" />
  </Customs>
  <Fields>
    <Attribute Name="PolicyID" Index="5080001" Type="guid" Description="Идентификатор" />
    <Attribute Name="Serial" Index="5080002" Type="string" Description="Серия" CharacterMaximumLength="12" />
    <Attribute Name="Number" Index="5080003" Type="string" Description="Номер" CharacterMaximumLength="32" Required="1" />
    <Attribute Name="ValidThrough" Index="5080006" Type="date" Description="Действителен по" />
    <Attribute Name="IssueDate" Index="5080008" Type="date" Description="Дата выдачи" Required="1" />
    <Attribute Name="LastName" Index="5080009" Type="string" Description="Фамилия" CharacterMaximumLength="40" />
    <Attribute Name="FirstName" Index="5080010" Type="string" Description="Имя" CharacterMaximumLength="40" />
    <Attribute Name="FatherName" Index="5080011" Type="string" Description="Отчество" CharacterMaximumLength="40" />
    <Attribute Name="IsGuardian" Index="5080016" Type="bool" Description="Представитель" Required="1" />
    <Attribute Name="Birthday" Index="5080017" Type="datetime" Description="Дата рождения" Required="1" />
    <Attribute Name="DocSeries" Index="5080018" Type="string" Description="Серия документа" CharacterMaximumLength="16" />
    <Attribute Name="DocNumber" Index="5080019" Type="string" Description="Номер документа" CharacterMaximumLength="16" />
    <Parent Name="Patient" Index="5080004" Type="AKUZ.PATIENT" Description="Пациент" Required="1" />
    <Parent Name="InsuranceCompany" Index="5080005" Type="AKUZ.INSURANCE_COMPANY" Description="Страховая организация" Required="1" />
    <Parent Name="PolicyType" Index="5080007" Type="VCLib.ENUMS" Description="Тип полиса" EnumType="PolicyType" Save="0" />
    <Parent Name="Sex" Index="5080012" Type="VCLib.ENUMS" Description="Пол" EnumType="Sex" Required="1" />
    <Parent Name="DocType" Index="5080020" Type="VCLib.ENUMS" Description="Тип документа удостоверяющего личность" EnumType="DocType" />
    <Choice Name="SpecialCase" Index="5080021" IsFlag="1" Description="Особый случай" Required="1">
      <Item Name="1 - отсутствует отчество" Index="1" />
      <Item Name="2 - неизвестно фамилия" Index="2" />
      <Item Name="3 - неизвестно имя" Index="4" />
      <Item Name="4 - известен только месяц и год даты рождения" Index="8" />
      <Item Name="5 - известен только год даты рождения" Index="16" />
      <Item Name="6 - дата рождения не соответствует календарю" Index="32" />
      <Item Name="7 - не проверять контрольную сумму полиса" Index="64" />
    </Choice>
    <Child Name="PaymentLimits" Index="5080022" Type="AKUZ.PAYMENT_LIMIT" Description="Оплата услуги из средств лимита" ChildAttribute="Policy" />
    <Attribute Name="EnrichmentEnpUri" Type="string" Description="Адрес запросов к сервису обогащения" />
    <Attribute Name="Snils" Type="string" Description="СНИЛС" CharacterMaximumLength="14" />
    <Attribute Name="DocIssueDate" Index="5040021" Type="date" Description="Дата выдачи документа" />
    <Attribute Name="DocIssueOrg" Index="5040022" Type="string" Description="Организация выдавшая документ" CharacterMaximumLength="256" />
    <Attribute Name="SMORegistryNumber" Type="string" Description="Код СМО" />
  </Fields>
  <DbMapping>
    <Table name="T_POLICY">
      <Map Name="PolicyID" Column="PolicyID" />
      <Map Name="Serial" Column="Serial" />
      <Map Name="Number" Column="Number" />
      <Map Name="ValidThrough" Column="ValidThrough" />
      <Map Name="IssueDate" Column="IssueDate" />
      <Map Name="LastName" Column="LastName" />
      <Map Name="FirstName" Column="FirstName" />
      <Map Name="FatherName" Column="FatherName" />
      <Map Name="IsGuardian" Column="IsGuardian" />
      <Map Name="Birthday" Column="Birthday" />
      <Map Name="DocSeries" Column="DocSeries" />
      <Map Name="DocNumber" Column="DocNumber" />
      <Map Name="Patient" Column="Patient" />
      <Map Name="InsuranceCompany" Column="InsuranceCompany" />
      <Map Name="PolicyType" Column="type_" IsStored="0" />
      <Map Name="Sex" Column="Sex" />
      <Map Name="DocType" Column="DocType" />
      <Map Name="SpecialCase" Column="SpecialCase" />
      <Map Name="EnrichmentEnpUri" Column="EnrichmentEnpUri" />
      <Map Name="Snils" Column="Snils" />
      <Map Name="DocIssueDate" Column="DocIssueDate" />
      <Map Name="DocIssueOrg" Column="DocIssueOrg" />
    </Table>
    <Lexem>
      <Map Name="SMORegistryNumber">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion not="1" type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="InsuranceCompany" />
                <lx:StepString name="Insurer" />
                <lx:StepString name="SmoCod" />
              </lx:Path>
              <lx:ConstOperand isNull="1" />
            </lx:Criterion>
          </When>
          <Then>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="InsuranceCompany" />
              <lx:StepString name="Insurer" />
              <lx:StepString name="SmoCod" />
            </lx:Path>
          </Then>
          <Else>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepAs as="AKUZ.OMS_POLICY" />
              <lx:StepString name="Insurer" />
              <lx:StepString name="SmoCod" />
            </lx:Path>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>