<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="REHAB_REGISTRY" 
Description="Регистр реабилитации" 
PrimaryKey="RehabRegistryID">
  <Fields>
    <Attribute Name="RehabRegistryID" Type="guid" Description="Идентификатор" />
    <Parent Name="Patient" Type="AKUZ.PATIENT" Description="Пациент" Required="1" />
    <Attribute Name="DeregisterDate" Type="datetime" Description="Дата исключения из регистра" />
    <Attribute Name="TakeReason" Type="string" Description="Причина включения в регистр" CharacterMaximumLength="1024" />
    <Parent Name="RegisterPost" Type="AKUZ.POST" Description="Пользователь включивший в регистр" Required="1" />
    <Attribute Name="RegisterDate" Type="datetime" Description="Дата включения в регистр" Required="1" />
    <Parent Name="DeregisterPost" Type="AKUZ.POST" Description="Пользователь исключивший из регистра" />
    <Attribute Name="DeregisterReason" Type="string" Description="Причина исключения из регистра" CharacterMaximumLength="1024" />
    <Child Name="RehabCourses" Type="AKUZ.REHAB_COURSE" Description="Курсы реабилитации" ChildAttribute="RehabRegistry" />
    <Child Name="RehabFiles" Type="AKUZ.REHAB_FILE" Description="Прикрепленные документы для реабилитации" ChildAttribute="RehabRegistry" />
    <Attribute Name="Status" Type="string" Description="Статус" />
  </Fields>
  <DbMapping>
    <Table name="T_REHAB_REGISTRY">
      <Map Name="RehabRegistryID" Column="RehabRegistryID" />
      <Map Name="Patient" Column="Patient" />
      <Map Name="DeregisterDate" Column="DeregisterDate" />
      <Map Name="TakeReason" Column="TakeReason" />
      <Map Name="RegisterPost" Column="RegisterPost" />
      <Map Name="RegisterDate" Column="RegisterDate" />
      <Map Name="DeregisterPost" Column="DeregisterPost" />
      <Map Name="DeregisterReason" Column="DeregisterReason" />
    </Table>
    <Lexem>
      <Map Name="Status">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:CriterionChildExists not="1">
              <condition />
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="RehabCourses" />
              </lx:Path>
            </lx:CriterionChildExists>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Нет курсов реабилитации]]></lx:ConstOperand>
          </Then>
          <Else>
            <lx:QueryValue entity="AKUZ.REHAB_COURSE" top="1" offset="0">
              <condition>
                <lx:Criterion type="=">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="RehabRegistry" />
                    <lx:StepString name="RehabRegistryID" />
                  </lx:Path>
                  <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="RehabRegistryID" />
                  </lx:Path>
                </lx:Criterion>
              </condition>
              <orderBy>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="CourseOpeningDate" />
                </lx:Path>
                <desc>True</desc>
              </orderBy>
              <value>
                <lx:LexemList>
                  <lx:Case>
                    <When>
                      <lx:Criterion type="&lt;&gt;">
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepString name="EventRehabilitationCard" />
                        </lx:Path>
                        <lx:Null />
                      </lx:Criterion>
                    </When>
                    <Then>
                      <lx:Case>
                        <When>
                          <lx:Criterion type="&lt;&gt;">
                            <lx:Path OwnerQueryLevel="0">
                              <lx:StepString name="EventRehabilitationCard" />
                              <lx:StepString name="EventBase" />
                              <lx:StepString name="CloseDate" />
                            </lx:Path>
                            <lx:Null />
                          </lx:Criterion>
                        </When>
                        <Then>
                          <lx:ConstOperand type="String"><![CDATA[Завершил курс реабилитации]]></lx:ConstOperand>
                        </Then>
                        <Else>
                          <lx:ConstOperand type="String"><![CDATA[Проходит курс реабилитации]]></lx:ConstOperand>
                        </Else>
                      </lx:Case>
                    </Then>
                    <Else>
                      <lx:Case>
                        <When>
                          <lx:Criteria type="Or">
                            <lx:Criteria type="And">
                              <lx:Criterion type="=">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="Referral" />
                                  <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                  <lx:StepString name="NeedConsiliumSign" />
                                </lx:Path>
                                <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
                              </lx:Criterion>
                              <lx:Criterion type="=">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="Referral" />
                                  <lx:StepString name="ConsiliumDecisionLink" />
                                  <lx:StepAs as="AKUZ.REHABILITATION_CONSILIUM_DECISION" />
                                </lx:Path>
                                <lx:Null />
                              </lx:Criterion>
                              <lx:Criterion type="=">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="Referral" />
                                  <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                  <lx:StepString name="CancelHospitalizationReferral" />
                                </lx:Path>
                                <lx:Null />
                              </lx:Criterion>
                              <lx:Criterion type="IS">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="Referral" />
                                  <lx:StepString name="ObjectProperties" />
                                  <lx:StepString name="ObjectTypeID" />
                                </lx:Path>
                                <lx:ConstOperand type="String"><![CDATA[AKUZ.HOSPITALIZATION_REFERRAL]]></lx:ConstOperand>
                              </lx:Criterion>
                            </lx:Criteria>
                            <lx:Criteria type="And">
                              <lx:CriterionChildExists not="1">
                                <condition>
                                  <lx:Criterion type="IS">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="ObjectProperties" />
                                      <lx:StepString name="ObjectTypeID" />
                                    </lx:Path>
                                    <lx:ConstOperand type="String"><![CDATA[AKUZ.REK_EXPERTISE_REHAB]]></lx:ConstOperand>
                                  </lx:Criterion>
                                </condition>
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="Referral" />
                                  <lx:StepAs as="AKUZ.REK_REFFERAL" />
                                  <lx:StepString name="RekEvent" />
                                  <lx:StepString name="RekExpertises" />
                                </lx:Path>
                              </lx:CriterionChildExists>
                              <lx:Criterion type="IS">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="Referral" />
                                  <lx:StepString name="ObjectProperties" />
                                  <lx:StepString name="ObjectTypeID" />
                                </lx:Path>
                                <lx:ConstOperand type="String"><![CDATA[AKUZ.REK_REFFERAL]]></lx:ConstOperand>
                              </lx:Criterion>
                            </lx:Criteria>
                          </lx:Criteria>
                        </When>
                        <Then>
                          <lx:ConstOperand type="String"><![CDATA[Ожидает рассмотрения]]></lx:ConstOperand>
                        </Then>
                        <Else>
                          <lx:Case>
                            <When>
                              <lx:Criteria type="Or">
                                <lx:Criteria type="And">
                                  <lx:Criterion type="IS">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="EventRehabilitationCard" />
                                      <lx:StepString name="EventBase" />
                                      <lx:StepString name="ObjectProperties" />
                                      <lx:StepString name="ObjectTypeID" />
                                    </lx:Path>
                                    <lx:ConstOperand type="String"><![CDATA[AKUZ.EXAMINATION_BASE]]></lx:ConstOperand>
                                  </lx:Criterion>
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="EventRehabilitationCard" />
                                      <lx:StepString name="FirstPhaseRehabilitation" />
                                    </lx:Path>
                                    <lx:Null />
                                  </lx:Criterion>
                                </lx:Criteria>
                                <lx:Criteria type="And">
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepString name="ConsiliumDecisionLink" />
                                      <lx:StepAs as="AKUZ.REHABILITATION_CONSILIUM_DECISION" />
                                      <lx:StepString name="ConsiliumDecision" />
                                    </lx:Path>
                                    <lx:ConstOperand type="Int32">0</lx:ConstOperand>
                                  </lx:Criterion>
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                      <lx:StepString name="ApprovedHospitalDate" />
                                    </lx:Path>
                                    <lx:Null />
                                  </lx:Criterion>
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                      <lx:StepString name="CancelHospitalizationReferral" />
                                    </lx:Path>
                                    <lx:Null />
                                  </lx:Criterion>
                                </lx:Criteria>
                                <lx:Criteria type="And">
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepString name="ConsiliumDecisionLink" />
                                      <lx:StepAs as="AKUZ.REHABILITATION_CONSILIUM_DECISION" />
                                      <lx:StepString name="ConsiliumDecision" />
                                    </lx:Path>
                                    <lx:ConstOperand type="Int32">0</lx:ConstOperand>
                                  </lx:Criterion>
                                  <lx:Criterion type="&lt;&gt;">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                      <lx:StepString name="ApprovedHospitalDate" />
                                    </lx:Path>
                                    <lx:Null />
                                  </lx:Criterion>
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                      <lx:StepString name="CancelHospitalizationReferral" />
                                    </lx:Path>
                                    <lx:Null />
                                  </lx:Criterion>
                                </lx:Criteria>
                                <lx:Criteria type="And">
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                      <lx:StepString name="NeedConsiliumSign" />
                                    </lx:Path>
                                    <lx:ConstOperand type="Boolean">False</lx:ConstOperand>
                                  </lx:Criterion>
                                  <lx:Criterion type="=">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                                      <lx:StepString name="CancelHospitalizationReferral" />
                                    </lx:Path>
                                    <lx:Null />
                                  </lx:Criterion>
                                </lx:Criteria>
                                <lx:Criteria type="And">
                                  <lx:Criterion type="IS">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepString name="ObjectProperties" />
                                      <lx:StepString name="ObjectTypeID" />
                                    </lx:Path>
                                    <lx:ConstOperand type="String"><![CDATA[AKUZ.REK_REFFERAL]]></lx:ConstOperand>
                                  </lx:Criterion>
                                  <lx:CriterionChildExists>
                                    <condition>
                                      <lx:Criteria type="And">
                                        <lx:Criterion type="IS">
                                          <lx:Path OwnerQueryLevel="0">
                                            <lx:StepString name="ObjectProperties" />
                                            <lx:StepString name="ObjectTypeID" />
                                          </lx:Path>
                                          <lx:ConstOperand type="String"><![CDATA[AKUZ.REK_EXPERTISE_REHAB]]></lx:ConstOperand>
                                        </lx:Criterion>
                                        <lx:Criterion type="=">
                                          <lx:Path OwnerQueryLevel="0">
                                            <lx:StepAs as="AKUZ.REK_EXPERTISE_REHAB" />
                                            <lx:StepString name="MCResult" />
                                          </lx:Path>
                                          <lx:ConstOperand type="Int32">0</lx:ConstOperand>
                                        </lx:Criterion>
                                      </lx:Criteria>
                                    </condition>
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="Referral" />
                                      <lx:StepAs as="AKUZ.REK_REFFERAL" />
                                      <lx:StepString name="RekEvent" />
                                      <lx:StepString name="RekExpertises" />
                                    </lx:Path>
                                  </lx:CriterionChildExists>
                                </lx:Criteria>
                              </lx:Criteria>
                            </When>
                            <Then>
                              <lx:ConstOperand type="String"><![CDATA[Ожидает реабилитации]]></lx:ConstOperand>
                            </Then>
                            <Else>
                              <lx:ConstOperand type="String"><![CDATA[Не нуждается в реабилитации]]></lx:ConstOperand>
                            </Else>
                          </lx:Case>
                        </Else>
                      </lx:Case>
                    </Else>
                  </lx:Case>
                </lx:LexemList>
              </value>
            </lx:QueryValue>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>