<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="MENTAL_DISPANSERISATION_INIT" 
Description="Наблюдение за пациентом психиатрического профиля" 
Inherits="AKUZ.AMBULANCE_CARD_RECORD">
  <Fields>
    <Parent Name="LpuFrom" Type="AKUZ.LPU_MAIN" Description="Принят из МО" />
    <Attribute Name="Mkb" Type="string" Description="Код МКБ" Required="1" />
    <Attribute Name="Diagnosis" Type="string" Description="Диагноз" />
    <Link Name="MentalDispanserisationEnd" Type="AKUZ.MENTAL_DISPANSERISATION_END" Description="Снятие с диспансерного учета психиатрического профиля" LinkAttribute="MentalDispanserisationInit" />
    <Child Name="MentalDispanserisationConcomitantDiseasess" Type="AKUZ.MENTAL_DISPANSERISATION_CONCOMITANT_DISEASES" Description="Сопутствующие заболевания при наблюдении" ChildAttribute="MentalDispanserisationInit" />
    <Choice Name="Living" Description="Проживание">
      <Item Name="один" Index="0" />
      <Item Name="в семье" Index="1" />
    </Choice>
    <Choice Name="ResidenceState" Description="Условия проживания">
      <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>
    <Choice Name="Efficiency" Description="Дееспособность">
      <Item Name="нет" Index="0" />
      <Item Name="да" Index="1" />
    </Choice>
    <Choice Name="FamilyStatus" Description="Семейное положение">
      <Item Name="никогда не состоял(а) в браке" Index="1" />
      <Item Name="состоит в браке" Index="2" />
      <Item Name="разведен(а)" Index="3" />
      <Item Name="вдов(а)" Index="4" />
      <Item Name="прочее" Index="8" />
    </Choice>
    <Choice Name="Education" Description="Образование">
      <Item Name="незаконченное среднее" Index="0" />
      <Item Name="среднее" Index="1" />
      <Item Name="средне-специальное" Index="2" />
      <Item Name="незаконченное высшее" Index="3" />
      <Item Name="без образования" Index="4" />
      <Item Name="высшее" Index="5" />
    </Choice>
    <Choice Name="Guardianship" Description="Опека">
      <Item Name="нет" Index="0" />
      <Item Name="да" Index="1" />
    </Choice>
    <Child Name="MentalDispanserisationMovenments" Type="AKUZ.MENTAL_DISPANSERISATION_MOVENMENT" Description="Движение по психиатрическому профилю" ChildAttribute="DispanserisationInit" />
    <Attribute Name="CurrentMkb" Type="string" Description="Текущий код МКБ" />
    <Attribute Name="CurrentDiagnosis" Type="string" Description="Текущий диагноз" />
    <Child Name="MentalDispanserisationPresences" Type="AKUZ.MENTAL_DISPANSERISATION_PRESENCE" Description="Контроль посещений при психиатрическом Д-наблюдении" ChildAttribute="MentalDispanserisationInit" />
    <Link Name="CreationRekExpertise" Type="AKUZ.REK_EXPERTISE_MENTAL" Description="Экспертиза обоснованности ДН" LinkAttribute="CreatedDispanserisation" />
    <Link Name="EndingRekExpertise" Type="AKUZ.REK_EXPERTISE_MENTAL" Description="Экспертиза обоснованности ДН" LinkAttribute="DispToEnd" />
  </Fields>
  <DbMapping>
    <Table name="T_MENTAL_DISPANSERISATION_INIT">
      <Map Name="LpuFrom" Column="LpuFrom" />
      <Map Name="Mkb" Column="Mkb" />
      <Map Name="Diagnosis" Column="Diagnosis" />
      <Map Name="Living" Column="Living" />
      <Map Name="ResidenceState" Column="ResidenceState" />
      <Map Name="Efficiency" Column="Efficiency" />
      <Map Name="FamilyStatus" Column="FamilyStatus" />
      <Map Name="Education" Column="Education" />
      <Map Name="Guardianship" Column="Guardianship" />
    </Table>
    <Lexem>
      <Map Name="CurrentMkb">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion type="&gt;">
              <lx:ChildCount>
                <condition>
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="Mkb" />
                    </lx:Path>
                    <lx:ConstOperand isNull="1" />
                  </lx:Criterion>
                </condition>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="MentalDispanserisationMovenments" />
                </lx:Path>
                <lx:Count />
              </lx:ChildCount>
              <lx:ConstOperand type="Int32">0</lx:ConstOperand>
            </lx:Criterion>
          </When>
          <Then>
            <lx:ChildCount>
              <condition>
                <lx:Criteria type="And">
                  <lx:Criterion type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="DispanserisationInit" />
                      <lx:StepString name="MedicalRecordID" />
                    </lx:Path>
                    <lx:Path OwnerQueryLevel="1">
                      <lx:StepString name="MedicalRecordID" />
                    </lx:Path>
                  </lx:Criterion>
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="Mkb" />
                    </lx:Path>
                    <lx:ConstOperand isNull="1" />
                  </lx:Criterion>
                </lx:Criteria>
              </condition>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="MentalDispanserisationMovenments" />
              </lx:Path>
              <lx:First>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Mkb" />
                </lx:Path>
              </lx:First>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="DateEditing" />
              </lx:Path>
              <lx:ConstOperand type="String"><![CDATA[desc]]></lx:ConstOperand>
            </lx:ChildCount>
          </Then>
          <Else>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="Mkb" />
            </lx:Path>
          </Else>
        </lx:Case>
      </Map>
      <Map Name="CurrentDiagnosis">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion type="&gt;">
              <lx:ChildCount>
                <condition>
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="1">
                      <lx:StepString name="Diagnosis" />
                    </lx:Path>
                    <lx:ConstOperand isNull="1" />
                  </lx:Criterion>
                </condition>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="MentalDispanserisationMovenments" />
                </lx:Path>
                <lx:Count />
              </lx:ChildCount>
              <lx:ConstOperand type="Int32">0</lx:ConstOperand>
            </lx:Criterion>
          </When>
          <Then>
            <lx:ChildCount>
              <condition>
                <lx:Criteria type="And">
                  <lx:Criterion type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="DispanserisationInit" />
                      <lx:StepString name="MedicalRecordID" />
                    </lx:Path>
                    <lx:Path OwnerQueryLevel="1">
                      <lx:StepString name="MedicalRecordID" />
                    </lx:Path>
                  </lx:Criterion>
                  <lx:Criterion not="1" type="=">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="Diagnosis" />
                    </lx:Path>
                    <lx:ConstOperand isNull="1" />
                  </lx:Criterion>
                </lx:Criteria>
              </condition>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="MentalDispanserisationMovenments" />
              </lx:Path>
              <lx:First>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Diagnosis" />
                </lx:Path>
              </lx:First>
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="DateEditing" />
              </lx:Path>
              <lx:ConstOperand type="String"><![CDATA[desc]]></lx:ConstOperand>
            </lx:ChildCount>
          </Then>
          <Else>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="Diagnosis" />
            </lx:Path>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Choice Name="Status" Description="Состояние дисп.учета/длительность" RequiredAttributes="{PostingDate};{MentalDispanserisationEnd/PostingDate}">
      <Item Name="Состоит на наблюдении" Index="1" />
      <Item Name="Снят с наблюдения" Index="2" />
    </Choice>
  </CalculatingAttributes>
</Entity>