<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="REHAB_COURSE" 
Description="Курс реабилитации" 
PrimaryKey="RehabCourseID">
  <Fields>
    <Attribute Name="RehabCourseID" Type="guid" Description="Идентификатор" />
    <Attribute Name="CourseOpeningDate" Type="datetime" Description="Дата открытия курса" Required="1" />
    <Parent Name="Referral" Type="AKUZ.REFERRAL" Description="Направление" Required="1" />
    <Parent Name="RehabRegistry" Type="AKUZ.REHAB_REGISTRY" Description="Регистр Реабилитации" Required="1" />
    <Child Name="RehabFiles" Type="AKUZ.REHAB_FILE" Description="Прикрепленные документы для реабилитации" ChildAttribute="RehabCourse" RemoveAction="0" />
    <Attribute Name="CourseStatus" Type="string" Description="Статус курса" />
    <Parent Name="LpuMain" Type="AKUZ.LPU_MAIN" Description="Направившее МО" />
    <Parent Name="LpuMainTo" Type="AKUZ.LPU_MAIN" Description="Исполняющее МО" />
    <Link Name="EventRehabilitationCard" Type="AKUZ.EVENT_REHABILITATION_CARD" Description="Карта реабилитационных мероприятий" LinkAttribute="RehabCourse" />
    <Choice Name="RehabilitationPhase" Description="Этап реабилитации">
      <Item Name="Первый этап реабилитации" Index="1" />
      <Item Name="Второй этап реабилитации" Index="2" />
      <Item Name="Третий этап реабилитации" Index="3" />
    </Choice>
  </Fields>
  <DbMapping>
    <Table name="T_REHAB_COURSE">
      <Map Name="RehabCourseID" Column="RehabCourseID" />
      <Map Name="CourseOpeningDate" Column="CourseOpeningDate" />
      <Map Name="Referral" Column="Referral" />
      <Map Name="RehabRegistry" Column="RehabRegistry" />
      <Map Name="LpuMain" Column="LpuMain" />
      <Map Name="LpuMainTo" Column="LpuMainTo" />
      <Map Name="RehabilitationPhase" Column="RehabilitationPhase" />
    </Table>
    <Lexem>
      <Map Name="CourseStatus">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Referral" />
              </lx:Path>
              <lx:Null />
            </lx:Criterion>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Нет направления]]></lx:ConstOperand>
          </Then>
          <When>
            <lx:Criterion type="&lt;&gt;">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Referral" />
                <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                <lx:StepString name="CancelHospitalizationReferral" />
              </lx:Path>
              <lx:Null />
            </lx:Criterion>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Направление на госпитализацию отменено]]></lx:ConstOperand>
          </Then>
          <When>
            <lx:Criteria type="And">
              <lx:Criterion type="&lt;&gt;">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="EventRehabilitationCard" />
                </lx:Path>
                <lx:Null />
              </lx:Criterion>
              <lx:Criterion type="&lt;&gt;">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="EventRehabilitationCard" />
                  <lx:StepString name="OutcomeStatus" />
                </lx:Path>
                <lx:Null />
              </lx:Criterion>
            </lx:Criteria>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Завершен курс реабилитации]]></lx:ConstOperand>
          </Then>
          <When>
            <lx:Criteria type="And">
              <lx:Criterion type="&lt;&gt;">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="EventRehabilitationCard" />
                </lx:Path>
                <lx:Null />
              </lx:Criterion>
              <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="EventRehabilitationCard" />
                  <lx:StepString name="EventBase" />
                  <lx:StepString name="CloseDate" />
                </lx:Path>
                <lx:Null />
              </lx:Criterion>
              <lx:Criterion type="&lt;&gt;">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="EventRehabilitationCard" />
                  <lx:StepString name="FirstPhaseRehabilitation" />
                </lx:Path>
                <lx:Null />
              </lx:Criterion>
            </lx:Criteria>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Прохождение курса реабилитации]]></lx:ConstOperand>
          </Then>
          <When>
            <lx:Criterion type="&lt;&gt;">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="Referral" />
                <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                <lx:StepString name="EmergencyEvent" />
              </lx:Path>
              <lx:Null />
            </lx:Criterion>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Госпитализирован]]></lx:ConstOperand>
          </Then>
          <When>
            <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="&lt;&gt;">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="Referral" />
                  <lx:StepString name="ConsiliumDecisionLink" />
                </lx:Path>
                <lx:Null />
              </lx:Criterion>
            </lx:Criteria>
          </When>
          <Then>
            <lx:Case>
              <When>
                <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>
              </When>
              <Then>
                <lx:ConstOperand type="String"><![CDATA[Ожидает рассмотрения]]></lx:ConstOperand>
              </Then>
              <When>
                <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:Criteria>
              </When>
              <Then>
                <lx:ConstOperand type="String"><![CDATA[Ожидает дату госпитализации]]></lx:ConstOperand>
              </Then>
              <When>
                <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:Criteria>
              </When>
              <Then>
                <lx:ConstOperand type="String"><![CDATA[Ожидает госпитализацию]]></lx:ConstOperand>
              </Then>
              <When>
                <lx:Criterion type="&lt;&gt;">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Referral" />
                    <lx:StepAs as="AKUZ.HOSPITALIZATION_REFERRAL" />
                    <lx:StepString name="CancelHospitalizationReferral" />
                  </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>
          <When>
            <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:Path>
                <lx:Null />
              </lx:Criterion>
            </lx:Criteria>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Ожидает рассмотрения]]></lx:ConstOperand>
          </Then>
          <When>
            <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>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Ожидает реабилитацию]]></lx:ConstOperand>
          </Then>
          <When>
            <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>
          </When>
          <Then>
            <lx:Case>
              <When>
                <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>
              </When>
              <Then>
                <lx:ConstOperand type="String"><![CDATA[Подтверждено ВК]]></lx:ConstOperand>
              </Then>
              <When>
                <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:Criteria type="Or">
                        <lx:Criterion type="=">
                          <lx:Path OwnerQueryLevel="0">
                            <lx:StepAs as="AKUZ.REK_EXPERTISE_REHAB" />
                            <lx:StepString name="MCResult" />
                          </lx:Path>
                          <lx:ConstOperand type="Int32">1</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">2</lx:ConstOperand>
                        </lx:Criterion>
                      </lx:Criteria>
                    </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>
              </When>
              <Then>
                <lx:ConstOperand type="String"><![CDATA[Отклонено ВК]]></lx:ConstOperand>
              </Then>
              <When>
                <lx:Criterion type="&lt;&gt;">
                  <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Referral" />
                    <lx:StepAs as="AKUZ.REK_REFFERAL" />
                    <lx:StepString name="RekRefferalCancel" />
                    <lx:StepString name="CancelDate" />
                  </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>
          <When>
            <lx:Criteria type="And">
              <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="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>
          </When>
          <Then>
            <lx:ConstOperand type="String"><![CDATA[Ожидает дату госпитализации]]></lx:ConstOperand>
          </Then>
          <Else>
            <lx:ConstOperand type="String"><![CDATA[Ожидает рассмотрения]]></lx:ConstOperand>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
</Entity>