<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="AMBULANCE_EVENT" 
Description="Амбулаторный случай обращения" 
DNAttributes="{EventDate};{CloseDate}" 
DisplayName="Обращение {0} - {1}" 
Inherits="AKUZ.EVENT_BASE">
  <Customs>
    <Custom Name="NotDisplayedInFilter" Value="AllergiInfo" />
    <Custom Name="NotDisplayedColumns" Value="AllergiInfo" />
    <Custom Name="NotTrackedAttributes" Value="AllergiInfo" />
  </Customs>
  <Fields>
    <Attribute Name="PatientAge" Index="5440017" Type="string" Description="Возраст пациента на дату обращения" />
    <Child Name="EntryToDoctorInspections" Index="5440001" Type="AKUZ.ENTRY_TO_DOCTOR_INSPECTION" Description="Записи на прием к врачу" ChildAttribute="AmbulanceEvent" />
    <Child Name="AmbulanceRecords" Index="5440003" Type="AKUZ.AMBULANCE_CARD_RECORD" Description="Медицинские записи врачей" ChildAttribute="AmbulanceEvent" />
    <Child Name="DoctorInspections" Index="5440004" Type="AKUZ.DOCTOR_INSPECTION" Description="Первичные осмотры врачей" ChildAttribute="AmbulanceEvent" />
    <Child Name="Recipes" Index="5440005" Type="AKUZ.RECIPE" Description="Рецепты" ChildAttribute="AmbulanceEvent" />
    <Child Name="HospitalizationReferrals" Index="5440007" Type="AKUZ.HOSPITALIZATION_REFERRAL" Description="Направление на госпитализацию" ChildAttribute="AmbulanceEvent" />
    <Child Name="MedicalCertificates" Index="5440009" Type="AKUZ.MEDICAL_CERTIFICATE" Description="Листы нетрудоспособности" ChildAttribute="AmbulanceEvent" />
    <Child Name="EntryAmbulances" Index="5440010" Type="AKUZ.ENTRY_AMBULANCE" Description="Запись на прием амбулаторно" ChildAttribute="AmbulanceEvent" />
    <Child Name="EventServices" Index="5440011" Type="AKUZ.EVENT_SERVICE" Description="Услуги по случаю обращения" ChildAttribute="AmbulanceEvent" />
    <Child Name="FarmacyDocuments" Index="5440012" Type="AKUZ.FARMACY_DOCUMENT" Description="Документы аптеки" ChildAttribute="AmbulanceEvent" />
    <Child Name="DoctorVisits" Index="5440014" Type="AKUZ.DOCTOR_VISIT" Description="Посещение врача" ChildAttribute="AmbulanceEvent" />
    <Child Name="PhysicalContracts" Index="5440019" Type="AKUZ.PHYSICAL_CONTRACT" Description="Договора на оказание физических услуг" ChildAttribute="AmbulanceEvent" />
    <Link Name="ListOfDestination" Index="5440013" Type="AKUZ.LIST_OF_DESTINATION" Description="Лист назначений" LinkAttribute="AmbulanceEvent" />
    <Child Name="HospitalisationActiveCalls" Index="5440022" Type="AKUZ.HOSPITALISATION_ACTIVE_CALL" Description="Активный вызов стационара" ChildAttribute="AmbulanceEvent" />
    <Child Name="RecipeForms" Type="AKUZ.RECIPE_FORM" Description="Бланк рецепта" ChildAttribute="AmbulanceEvent" />
    <Child Name="Referrals" Type="AKUZ.REFERRAL" Description="Направление" ChildAttribute="AmbulanceEvent" />
    <Child Name="AmbulanceEventMovementCardLinks" Type="AKUZ.AMBULANCE_EVENT_MOVEMENT_CARD_LINK" Description="Связка между маршрутной картой и случаем" ChildAttribute="AmbulanceEvent" />
    <Child Name="WriteOffOnPatients" Type="AKUZ.WRITE_OFF_ON_PATIENT" Description="Списание товаров на складе на пациента" ChildAttribute="AmbulanceEvent" />
    <Child Name="PatientMonitoringPrograms" Type="AKUZ.PATIENT_MONITORING_PROGRAM" Description="Программа мониторинга пациента" ChildAttribute="AmbulanceEvent" />
    <Child Name="MedicalExaminations" Type="AKUZ.MEDICAL_EXAMINATION" Description="Медицинский осмотр" ChildAttribute="AmbulanceEvent" />
    <Child Name="Consiliums" Type="AKUZ.CONSILIUM" Description="Консилиумы врачей" ChildAttribute="AmbulanceEvent" />
    <Child Name="RouteToDiagnosticss" Type="AKUZ.ROUTE_TO_DIAGNOSTICS" Description="Направление на диагностику" ChildAttribute="AmbulanceEvent" />
    <Child Name="RouteToDoctorInspections" Type="AKUZ.ROUTE_TO_DOCTOR_INSPECTION" Description="Направление на консультации" ChildAttribute="AmbulanceEvent" />
    <Child Name="DiagnosticsResultss" Type="AKUZ.DIAGNOSTICS_RESULTS" Description="Результаты исследования" ChildAttribute="AmbulanceEvent" />
    <Child Name="StateOfTooths" Type="AKUZ.STATE_OF_TOOTH" Description="Состояние зуба" ChildAttribute="AmbulanceEvent" />
    <Child Name="RehabRegistryReferrals" Type="AKUZ.REHAB_REGISTRY_REFERRAL" Description="Направление на реабилитацию" ChildAttribute="AmbulanceEvent" />
    <Child Name="TemperatureListNews" Type="AKUZ.TEMPERATURE_LIST_NEW" Description="Новый температурный лист" ChildAttribute="AmbulanceEvent" />
    <Child Name="CardNotes" Type="AKUZ.CARD_NOTE" Description="Медицинская документация" ChildAttribute="AmbulanceEvent" />
    <Child Name="MedicalExaminationDatas" Type="AKUZ.MEDICAL_EXAMINATION_DATA" Description="Данные о случае обращения" ChildAttribute="AmbulanceEvent" />
    <Child Name="BurnCards" Type="AKUZ.BURN_CARD" Description="Карта ожогов" ChildAttribute="AmbulanceEvent" />
    <Child Name="NurseMedicalExaminations" Type="AKUZ.NURSE_MEDICAL_EXAMINATION" Description="Осмотр медицинской сестрой" ChildAttribute="AmbulanceEvent" />
    <Child Name="BloodGroupRecords" Type="AKUZ.BLOOD_GROUP_RECORD" Description="Определение группы крови" ChildAttribute="AmbulanceEvent" />
    <Child Name="PhysicalTherapyReferrals" Type="AKUZ.PHYSICAL_THERAPY_REFERRAL" Description="Направления на физиотерапию" ChildAttribute="AmbulanceEvent" />
    <Child Name="DistanceMonitoringPrograms" Type="AKUZ.DISTANCE_MONITORING_PROGRAM" Description="Программа дистанционного мониторинга" ChildAttribute="AmbulanceEvent" />
    <Child Name="EpicrissCollection" Type="AKUZ.HOSPITAL_SUMMARY_EPICRIS" Description="Эпикриз из случая лечения" ChildAttribute="AmbulanceEvent" />
  </Fields>
  <DbMapping>
    <Lexem>
      <Map Name="PatientAge">
        <lx:Case xmlns:lx="lexem">
          <When>
            <lx:Criterion type="&gt;">
              <lx:DateDiff datepart="Year">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="AmbulanceCard" />
                  <lx:StepString name="Patient" />
                  <lx:StepString name="Birthday" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepString name="EventDate" />
                </lx:Path>
              </lx:DateDiff>
              <lx:ConstOperand type="Decimal">0</lx:ConstOperand>
            </lx:Criterion>
          </When>
          <Then>
            <lx:MathOperator sign="+">
              <lx:MathOperator sign="+">
                <lx:MathOperator sign="+">
                  <lx:MathOperator sign="+">
                    <lx:MathOperator sign="+">
                      <lx:MathOperator sign="+">
                        <lx:MathOperator sign="+">
                          <lx:MathOperator sign="+">
                            <lx:MathOperator sign="+">
                              <lx:MathOperator sign="+">
                                <lx:Cast type="String">
                                  <lx:DateDiff datepart="Year">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="AmbulanceCard" />
                                      <lx:StepString name="Patient" />
                                      <lx:StepString name="Birthday" />
                                    </lx:Path>
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="EventDate" />
                                    </lx:Path>
                                  </lx:DateDiff>
                                </lx:Cast>
                                <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                              </lx:MathOperator>
                              <lx:Cast type="String">
                                <lx:NumberWord>
                                  <lx:DateDiff datepart="Year">
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="AmbulanceCard" />
                                      <lx:StepString name="Patient" />
                                      <lx:StepString name="Birthday" />
                                    </lx:Path>
                                    <lx:Path OwnerQueryLevel="0">
                                      <lx:StepString name="EventDate" />
                                    </lx:Path>
                                  </lx:DateDiff>
                                  <lx:ConstOperand type="String"><![CDATA[год]]></lx:ConstOperand>
                                  <lx:ConstOperand type="String"><![CDATA[года]]></lx:ConstOperand>
                                  <lx:ConstOperand type="String"><![CDATA[лет]]></lx:ConstOperand>
                                </lx:NumberWord>
                              </lx:Cast>
                            </lx:MathOperator>
                            <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                          </lx:MathOperator>
                          <lx:Cast type="String">
                            <lx:DateDiff datepart="Month">
                              <lx:DateAdd datepart="Year">
                                <lx:DateDiff datepart="Year">
                                  <lx:Path OwnerQueryLevel="0">
                                    <lx:StepInt index="5240005" />
                                    <lx:StepInt index="5220002" />
                                    <lx:StepInt index="5040015" />
                                  </lx:Path>
                                  <lx:Path OwnerQueryLevel="0">
                                    <lx:StepInt index="5240002" />
                                  </lx:Path>
                                </lx:DateDiff>
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepInt index="5240005" />
                                  <lx:StepInt index="5220002" />
                                  <lx:StepInt index="5040015" />
                                </lx:Path>
                              </lx:DateAdd>
                              <lx:Path OwnerQueryLevel="0">
                                <lx:StepInt index="5240002" />
                              </lx:Path>
                            </lx:DateDiff>
                          </lx:Cast>
                        </lx:MathOperator>
                        <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                      </lx:MathOperator>
                      <lx:Cast type="String">
                        <lx:NumberWord>
                          <lx:DateDiff datepart="Month">
                            <lx:DateAdd datepart="Year">
                              <lx:DateDiff datepart="Year">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepInt index="5240005" />
                                  <lx:StepInt index="5220002" />
                                  <lx:StepInt index="5040015" />
                                </lx:Path>
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepInt index="5240002" />
                                </lx:Path>
                              </lx:DateDiff>
                              <lx:Path OwnerQueryLevel="0">
                                <lx:StepInt index="5240005" />
                                <lx:StepInt index="5220002" />
                                <lx:StepInt index="5040015" />
                              </lx:Path>
                            </lx:DateAdd>
                            <lx:Path OwnerQueryLevel="0">
                              <lx:StepInt index="5240002" />
                            </lx:Path>
                          </lx:DateDiff>
                          <lx:ConstOperand type="String"><![CDATA[месяц]]></lx:ConstOperand>
                          <lx:ConstOperand type="String"><![CDATA[месяца]]></lx:ConstOperand>
                          <lx:ConstOperand type="String"><![CDATA[месяцев]]></lx:ConstOperand>
                        </lx:NumberWord>
                      </lx:Cast>
                    </lx:MathOperator>
                    <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                  </lx:MathOperator>
                  <lx:Cast type="String">
                    <lx:DateDiff datepart="Day">
                      <lx:DateAdd datepart="Month">
                        <lx:DateDiff datepart="Month">
                          <lx:Path OwnerQueryLevel="0">
                            <lx:StepInt index="5240005" />
                            <lx:StepInt index="5220002" />
                            <lx:StepInt index="5040015" />
                          </lx:Path>
                          <lx:Path OwnerQueryLevel="0">
                            <lx:StepInt index="5240002" />
                          </lx:Path>
                        </lx:DateDiff>
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepInt index="5240005" />
                          <lx:StepInt index="5220002" />
                          <lx:StepInt index="5040015" />
                        </lx:Path>
                      </lx:DateAdd>
                      <lx:Path OwnerQueryLevel="0">
                        <lx:StepInt index="5240002" />
                      </lx:Path>
                    </lx:DateDiff>
                  </lx:Cast>
                </lx:MathOperator>
                <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
              </lx:MathOperator>
              <lx:Cast type="String">
                <lx:NumberWord>
                  <lx:DateDiff datepart="Day">
                    <lx:DateAdd datepart="Month">
                      <lx:DateDiff datepart="Month">
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepInt index="5240005" />
                          <lx:StepInt index="5220002" />
                          <lx:StepInt index="5040015" />
                        </lx:Path>
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepInt index="5240002" />
                        </lx:Path>
                      </lx:DateDiff>
                      <lx:Path OwnerQueryLevel="0">
                        <lx:StepInt index="5240005" />
                        <lx:StepInt index="5220002" />
                        <lx:StepInt index="5040015" />
                      </lx:Path>
                    </lx:DateAdd>
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepInt index="5240002" />
                    </lx:Path>
                  </lx:DateDiff>
                  <lx:ConstOperand type="String"><![CDATA[день]]></lx:ConstOperand>
                  <lx:ConstOperand type="String"><![CDATA[дня]]></lx:ConstOperand>
                  <lx:ConstOperand type="String"><![CDATA[дней]]></lx:ConstOperand>
                </lx:NumberWord>
              </lx:Cast>
            </lx:MathOperator>
          </Then>
          <Else>
            <lx:Case>
              <When>
                <lx:Criterion type="&gt;">
                  <lx:DateDiff datepart="Month">
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="AmbulanceCard" />
                      <lx:StepString name="Patient" />
                      <lx:StepString name="Birthday" />
                    </lx:Path>
                    <lx:Path OwnerQueryLevel="0">
                      <lx:StepString name="EventDate" />
                    </lx:Path>
                  </lx:DateDiff>
                  <lx:ConstOperand type="Decimal">0</lx:ConstOperand>
                </lx:Criterion>
              </When>
              <Then>
                <lx:MathOperator sign="+">
                  <lx:MathOperator sign="+">
                    <lx:MathOperator sign="+">
                      <lx:MathOperator sign="+">
                        <lx:MathOperator sign="+">
                          <lx:MathOperator sign="+">
                            <lx:Cast type="String">
                              <lx:DateDiff datepart="Month">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="AmbulanceCard" />
                                  <lx:StepString name="Patient" />
                                  <lx:StepString name="Birthday" />
                                </lx:Path>
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="EventDate" />
                                </lx:Path>
                              </lx:DateDiff>
                            </lx:Cast>
                            <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                          </lx:MathOperator>
                          <lx:Cast type="String">
                            <lx:NumberWord>
                              <lx:DateDiff datepart="Month">
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="AmbulanceCard" />
                                  <lx:StepString name="Patient" />
                                  <lx:StepString name="Birthday" />
                                </lx:Path>
                                <lx:Path OwnerQueryLevel="0">
                                  <lx:StepString name="EventDate" />
                                </lx:Path>
                              </lx:DateDiff>
                              <lx:ConstOperand type="String"><![CDATA[месяц]]></lx:ConstOperand>
                              <lx:ConstOperand type="String"><![CDATA[месяца]]></lx:ConstOperand>
                              <lx:ConstOperand type="String"><![CDATA[месяцев]]></lx:ConstOperand>
                            </lx:NumberWord>
                          </lx:Cast>
                        </lx:MathOperator>
                        <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                      </lx:MathOperator>
                      <lx:Cast type="String">
                        <lx:DateDiff datepart="Day">
                          <lx:DateAdd datepart="Month">
                            <lx:DateDiff datepart="Month">
                              <lx:Path OwnerQueryLevel="0">
                                <lx:StepString name="AmbulanceCard" />
                                <lx:StepString name="Patient" />
                                <lx:StepString name="Birthday" />
                              </lx:Path>
                              <lx:Path OwnerQueryLevel="0">
                                <lx:StepString name="EventDate" />
                              </lx:Path>
                            </lx:DateDiff>
                            <lx:Path OwnerQueryLevel="0">
                              <lx:StepInt index="5240005" />
                              <lx:StepInt index="5220002" />
                              <lx:StepInt index="5040015" />
                            </lx:Path>
                          </lx:DateAdd>
                          <lx:Path OwnerQueryLevel="0">
                            <lx:StepInt index="5240002" />
                          </lx:Path>
                        </lx:DateDiff>
                      </lx:Cast>
                    </lx:MathOperator>
                    <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                  </lx:MathOperator>
                  <lx:Cast type="String">
                    <lx:NumberWord>
                      <lx:DateDiff datepart="Day">
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepString name="AmbulanceCard" />
                          <lx:StepString name="Patient" />
                          <lx:StepString name="Birthday" />
                        </lx:Path>
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepString name="EventDate" />
                        </lx:Path>
                      </lx:DateDiff>
                      <lx:ConstOperand type="String"><![CDATA[день]]></lx:ConstOperand>
                      <lx:ConstOperand type="String"><![CDATA[дня]]></lx:ConstOperand>
                      <lx:ConstOperand type="String"><![CDATA[дней]]></lx:ConstOperand>
                    </lx:NumberWord>
                  </lx:Cast>
                </lx:MathOperator>
              </Then>
              <Else>
                <lx:Case>
                  <When>
                    <lx:Criterion type="&gt;">
                      <lx:DateDiff datepart="Day">
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepString name="AmbulanceCard" />
                          <lx:StepString name="Patient" />
                          <lx:StepString name="Birthday" />
                        </lx:Path>
                        <lx:Path OwnerQueryLevel="0">
                          <lx:StepString name="EventDate" />
                        </lx:Path>
                      </lx:DateDiff>
                      <lx:ConstOperand type="Decimal">0</lx:ConstOperand>
                    </lx:Criterion>
                  </When>
                  <Then>
                    <lx:MathOperator sign="+">
                      <lx:MathOperator sign="+">
                        <lx:Cast type="String">
                          <lx:DateDiff datepart="Day">
                            <lx:Path OwnerQueryLevel="0">
                              <lx:StepString name="AmbulanceCard" />
                              <lx:StepString name="Patient" />
                              <lx:StepString name="Birthday" />
                            </lx:Path>
                            <lx:Path OwnerQueryLevel="0">
                              <lx:StepString name="EventDate" />
                            </lx:Path>
                          </lx:DateDiff>
                        </lx:Cast>
                        <lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand>
                      </lx:MathOperator>
                      <lx:Cast type="String">
                        <lx:NumberWord>
                          <lx:DateDiff datepart="Day">
                            <lx:Path OwnerQueryLevel="0">
                              <lx:StepString name="AmbulanceCard" />
                              <lx:StepString name="Patient" />
                              <lx:StepString name="Birthday" />
                            </lx:Path>
                            <lx:Path OwnerQueryLevel="0">
                              <lx:StepString name="EventDate" />
                            </lx:Path>
                          </lx:DateDiff>
                          <lx:ConstOperand type="String"><![CDATA[день]]></lx:ConstOperand>
                          <lx:ConstOperand type="String"><![CDATA[дня]]></lx:ConstOperand>
                          <lx:ConstOperand type="String"><![CDATA[дней]]></lx:ConstOperand>
                        </lx:NumberWord>
                      </lx:Cast>
                    </lx:MathOperator>
                  </Then>
                  <Else>
                    <lx:ConstOperand type="String"><![CDATA[новорожденный]]></lx:ConstOperand>
                  </Else>
                </lx:Case>
              </Else>
            </lx:Case>
          </Else>
        </lx:Case>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Child Name="AmbulanceCardRecords" Type="AKUZ.AMBULANCE_CARD_RECORD" Description="Медицинская запись амбулаторной карты" RequiredAttributes="{AmbulanceRecords}" />
    <Attribute Name="cPatientAge" Index="5440006" Type="int" Description="Возраст пациента" RequiredAttributes="{EventDate};{AmbulanceCard/Patient/Birthday}" />
    <Attribute Name="ContractCost" Index="5440020" Type="float" DefaultFormat="{0:N}" Description="Стоимость услуг по договору" NumericPrecision="15" NumericScale="2" RequiredAttributes="{EventServices/ServiceTotalCost};{EventServices/IncludedEventServices};{EventServices/IncludedEventServices/Cost};{EventServices/IncludedEventServices/Coefficient};{EventServices/IncludedEventServices/ServiceCount};{EventServices/BaseEventService}" />
    <Attribute Name="DiscountSize" Index="5440021" Type="float" DefaultFormat="{0:N}" Description="Размер скидки" NumericPrecision="15" NumericScale="2" RequiredAttributes="{EventServices/Coefficient};{EventServices/Cost}" />
    <Child Name="cDoctorInspections" Index="5440015" Type="AKUZ.DOCTOR_INSPECTION" Description="Первичные осмотры врачей" RequiredAttributes="{EventDate}" PathAttributes="{DoctorVisits}" />
    <Child Name="cMedicalExaminationMains" Index="5440016" Type="AKUZ.MEDICAL_EXAMINATION_MAIN" Description="Первичные медицинские осмотры" RequiredAttributes="{AmbulanceRecords/as AKUZ.MEDICAL_EXAMINATION_MAIN}" PathAttributes="{AmbulanceRecords/as AKUZ.MEDICAL_EXAMINATION_MAIN}" />
    <Child Name="cMedicamentsOfEvents" Type="AKUZ.DESTINATION_COMPONENTS" Description="Медикаменты по случаю обращения" RequiredAttributes="{ListOfDestination/Destinations/DestinationComponentss};{ListOfDestination/Destinations/DestinationComponentss/CMnn};{ListOfDestination/Destinations/DestinationComponentss/CTrn};{ListOfDestination/Destinations/DestinationComponentss/Dosa};{ListOfDestination/Destinations/DestinationComponentss/MedicationForms}" PathAttributes="{ListOfDestination/Destinations/DestinationComponentss}" />
    <Attribute Name="AllergiInfo" Type="string" Description="Сведения о Аллергии" CharacterMaximumLength="1024" RequiredAttributes="{AmbulanceRecords/as AKUZ.MEDICAL_EXAMINATION/DrugAllergy};{AmbulanceRecords/as AKUZ.MEDICAL_EXAMINATION/FoodAllergy}" />
  </CalculatingAttributes>
</Entity>