<?xml version="1.0" encoding="utf-8"?>
<Entity 
Schema="AKUZ" 
Name="CARD_NOTE" 
Description="Медицинская документация" 
DNAttributes="{RecordDate};{DocumentNumber}" 
DisplayName="Медицинская документация от {0} №{1}" 
Inherits="AKUZ.AMBULANCE_CARD_RECORD">
  <Fields>
    <Attribute Name="Receiver" Index="5890004" Type="string" Description="Получатель" CharacterMaximumLength="32" Required="1" />
    <Attribute Name="IssuedReason" Index="5890005" Type="string" Description="Причина выдачи" CharacterMaximumLength="32" />
    <Attribute Name="DocumentNumber" Index="5890006" Type="string" Description="Номер документа" CharacterMaximumLength="16" />
    <Attribute Name="Name" Index="5890010" Type="string" Description="Наименование документа" CharacterMaximumLength="128" Required="1" />
    <Attribute Name="Descr" Index="5890012" Type="string" Description="Описание документа" CharacterMaximumLength="256" />
    <Attribute Name="Deleted" Index="5890015" Type="bool" Description="Удален" Required="1" />
    <Attribute Name="Series" Index="5890016" Type="string" Description="Серия" CharacterMaximumLength="128" />
    <Parent Name="HeadOfficePost" Index="5890007" Type="AKUZ.POST" Description="Заведующий отделением" />
    <Parent Name="Division" Index="5890011" Type="AKUZ.DIVISION" Description="Выдавшее документ отделение " />
    <Parent Name="AmbulanceCardRecord" Type="AKUZ.AMBULANCE_CARD_RECORD" Description="Медицинская запись амбулаторной карты" />
    <Child Name="CardNoteCopyss" Index="5890008" Type="AKUZ.CARD_NOTE_COPYS" Description="Копии выданных документов" ChildAttribute="CardNote" />
    <Choice Name="DocumentType" Index="5890013" Description="Тип документа" Required="1">
      <Item Name="Справка" Index="0" />
      <Item Name="Медицинская документация" Index="1" />
      <Item Name="Другие документы" Index="2" />
      <Item Name="Сканы документов" Index="3" />
    </Choice>
    <Link Name="CardNoteFile" Index="5890003" Type="AKUZ.CARD_NOTE_FILE" Description="Файл документа" LinkAttribute="CardNote" />
    <Child Name="CardNoteSignatures" Type="AKUZ.CARD_NOTE_SIGNATURE" Description="Подписи медицинской документации" ChildAttribute="CardNote" />
    <Parent Name="RequestRunType" Type="AKUZ.REQUEST_RUN_TYPE" Description="Процесс выполнения заявки" />
    <Parent Name="EmdrTemplate" Type="AKUZ.EMDR_TEMPLATE" Description="Шаблон документа АЭМД" />
    <Child Name="EmdrMessages" Type="AKUZ.EMDR_MESSAGE" Description="Результаты регистрации ЭМД" ChildAttribute="CardNote" SortingAttr="CreatedDate" />
    <Child Name="CardNoteServices" Type="AKUZ.CARD_NOTE_SERVICE" Description="Оказанные услуги медицинской документации" ChildAttribute="CardNote" />
    <Attribute Name="DocumentKind" Type="string" Description="Вид документа" CharacterMaximumLength="128" />
    <Attribute Name="PluggableAttributes" Type="text" Description="Дополнительные атрибуты" />
    <Child Name="CardNoteAssociations" Type="AKUZ.CARD_NOTE_ASSOCIATION" Description="Связи документов" ChildAttribute="CardNote" />
    <Link Name="OldCardNoteReplace" Type="AKUZ.CARD_NOTE_REPLACE" Description="Связка со старой медицинской документацией" LinkAttribute="NewCardNote" />
    <Parent Name="CardNoteRecipient" Type="AKUZ.CARD_NOTE_RECIPIENT" Description="Получатель документа" />
    <Link Name="ReplacedCardNote" Type="AKUZ.CARD_NOTE_REPLACE" Description="Связка с новой медицинской документацией" LinkAttribute="CardNote" />
    <Parent Name="EmdrDocType" Type="AKUZ.EMDR_DOC_TYPE" Description="Тип документов АЭМД" />
    <Attribute Name="EmdrBaseObjectName" Type="string" Description="Наименование объекта ЭМД" CharacterMaximumLength="64" />
    <Link Name="CardNoteDeleted" Type="AKUZ.CARD_NOTE_DELETED" Description="Факт удаления медицинской документации" LinkAttribute="CardNote" />
    <Attribute Name="EmdrBaseObjectVersion" Type="int" Description="Версия объекта ЭМД" />
    <Parent Name="LastEmdrMessage" Type="AKUZ.EMDR_MESSAGE" Description="Последний результат регистрации сведений об электронном медицинском документе" />
    <Parent Name="CdaDocument" Type="AKUZ.CDA_DOCUMENT" Description="Документ в формате CDA" />
    <Attribute Name="EmdrBaseObjectID" Type="string" Description="Идентификатор объекта ЭМД" CharacterMaximumLength="36" />
    <Attribute Name="ReadyToBeSent" Type="bool" Description="Готова к отправке" />
    <Attribute Name="IsDelayed" Type="bool" Description="Отложена" Required="1" />
    <Choice Name="WhereToSend" IsFlag="1" Description="Адресат отправки" Required="1">
      <Item Name="РЭМД" Index="1" />
      <Item Name="ВИМИС ССЗ" Index="2" />
      <Item Name="ИЭМК" Index="4" />
      <Item Name="ВИМИС АКИНЕО" Index="8" />
      <Item Name="ВИМИС ОНКО" Index="16" />
      <Item Name="ВИМИС Профилактика" Index="32" />
    </Choice>
    <Parent Name="EhrRusBm5l74bot3" Type="EHR.EHR_RUS_BM5L74BOT3" Description="ВИМИС. Триггерные точки для передачи данных" />
    <Attribute Name="ErrorDocMessage" Type="text" Description="Ошибка формирования документа" />
    <Attribute Name="NeedMoSign" Type="bool" Description="Требуется подпись МО" />
    <Attribute Name="Registered" Type="bool" Description="Зарегистрирована" />
  </Fields>
  <DbMapping>
    <Table name="T_CARD_NOTE">
      <Map Name="Receiver" Column="Receiver" />
      <Map Name="IssuedReason" Column="IssuedReason" />
      <Map Name="DocumentNumber" Column="DocumentNumber" />
      <Map Name="Name" Column="Name" />
      <Map Name="Descr" Column="Descr" />
      <Map Name="Deleted" Column="Deleted" />
      <Map Name="Series" Column="Series" />
      <Map Name="HeadOfficePost" Column="HeadOfficePost" />
      <Map Name="Division" Column="Division" />
      <Map Name="AmbulanceCardRecord" Column="AmbulanceCardRecord" />
      <Map Name="DocumentType" Column="DocumentType" />
      <Map Name="RequestRunType" Column="RequestRunType" />
      <Map Name="EmdrTemplate" Column="EmdrTemplate" />
      <Map Name="DocumentKind" Column="DocumentKind" />
      <Map Name="PluggableAttributes" Column="PluggableAttributes" />
      <Map Name="CardNoteRecipient" Column="CardNoteRecipient" />
      <Map Name="EmdrDocType" Column="EmdrDocType" />
      <Map Name="EmdrBaseObjectName" Column="EmdrBaseObjectName" />
      <Map Name="EmdrBaseObjectVersion" Column="EmdrBaseObjectVersion" />
      <Map Name="CdaDocument" Column="CdaDocument" />
      <Map Name="EmdrBaseObjectID" Column="EmdrBaseObjectID" />
      <Map Name="ReadyToBeSent" Column="ReadyToBeSent" />
      <Map Name="IsDelayed" Column="IsDelayed" />
      <Map Name="WhereToSend" Column="WhereToSend" />
      <Map Name="EhrRusBm5l74bot3" Column="EhrRusBm5l74bot3" />
      <Map Name="ErrorDocMessage" Column="ErrorDocMessage" />
      <Map Name="NeedMoSign" Column="NeedMoSign" />
      <Map Name="Registered" Column="Registered" />
    </Table>
    <Lexem>
      <Map Name="LastEmdrMessage">
        <lx:QueryValue entity="AKUZ.EMDR_MESSAGE" top="1" offset="0" xmlns:lx="lexem">
          <condition>
            <lx:Criterion type="=">
              <lx:Path OwnerQueryLevel="0">
                <lx:StepString name="CardNote" />
                <lx:StepString name="MedicalRecordID" />
              </lx:Path>
              <lx:Path OwnerQueryLevel="1">
                <lx:StepString name="MedicalRecordID" />
              </lx:Path>
            </lx:Criterion>
          </condition>
          <orderBy>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="CreatedDate" />
            </lx:Path>
            <desc>True</desc>
          </orderBy>
          <value>
            <lx:Path OwnerQueryLevel="0">
              <lx:StepString name="EmdrMessageID" />
            </lx:Path>
          </value>
        </lx:QueryValue>
      </Map>
    </Lexem>
  </DbMapping>
  <CalculatingAttributes>
    <Attribute Name="CopyPresent" Index="5890009" Type="bool" Description="Наличие выданных копий" RequiredAttributes="{CardNoteCopyss}" />
    <Parent Name="EmdrMessageCalculated" Type="AKUZ.EMDR_MESSAGE" Description="Результат регистрации сведений об электронном медицинском документе" RequiredAttributes="{MedicalRecordID}" />
    <Attribute Name="IsValidForCda" Type="bool" Description="Валидность для cda-документа" />
    <Attribute Name="MoSigned" Type="bool" Description="Подпись от имени организации" RequiredAttributes="{CardNoteSignatures/Signed};{CardNoteSignatures/SignType}" />
    <Attribute Name="PersonalSigned" Type="string" Description="Персональная подпись" RequiredAttributes="{CardNoteSignatures/Signed};{CardNoteSignatures/SignType}" />
    <Attribute Name="Signed" Type="bool" Description="Подписана" RequiredAttributes="{CardNoteSignatures/Signed}" />
  </CalculatingAttributes>
</Entity>