<commit_before><template>
  <modal ref="modal" @close="hide_modal" show-footer="true" white-bg="true" min-width="85%" margin-top
         :no-close="selected_direction !== -1">
    <span slot="header">Направления из РМИС. Пациент: {{card.family}} {{card.name}} {{card.twoname}},
      {{card.birthday}} ({{card.age}})</span>
    <div slot="body" style="min-height: 200px" class="directions-manage" v-if="loaded">
      <div class="directions-sidebar">
        <div @click="select_direction(d.pk)" class="direction" :class="{active: d.pk === selected_direction}"
             v-for="d in rows">
          <div>РМИС-направление №{{d.pk}} от {{d.referralDate}}</div>
          <div>Направляющая организация: {{d.referralOrganization}}</div>
          <hr/>
          <ol>
            <li v-for="s in d.services"><span class="s-code" v-if="s.code">{{s.code}}</span>
              {{s.title}}
            </li>
          </ol>
        </div>
        <div v-if="rows.length === 0" class="text-center" style="padding: 10px">
          Направлений из РМИС, не зарегистрированных в L2, не найдено
        </div>
      </div>
      <div class="directions-content" v-if="selected_direction !== -1">
        <div class="direction-data">
          <h4>РМИС-направление №{{direction_data.pk}} от {{direction_data.referralDate}}</h4>
          Организация: {{direction_data.referralOrganization}}<br/>
          <div v-if="direction_data.diagnosis">Диагноз: {{direction_data.diagnosis}}
            ({{direction_data.diagnosisName}})
          </div>
          <hr/>
          <div class="direction-service">
            <div class="service-rmis">
              <div class="s-title"><strong>Исследование в РМИС</strong></div>
            </div>
            <div class="service-l2"><strong>Исследование в L2</strong></div>
          </div>
          <div class="direction-service"
               :class="{wrn: s.selected_local_service === -1 && !s.exclude_direction, cancel: s.exclude_direction}"
               v-for="s in direction_data.services">
            <div class="service-rmis">
              <div class="s-code">{{s.code}}</div>
              <div class="s-title">{{s.title}}</div>
            </div>
            <div class="service-l2" v-if="s.local_services.length === 1 && s.selected_local_service !== -1">
              <div class="service-department">
                {{departments[research_data(s.selected_local_service).department_pk].title}}
              </div>
              {{research_data(s.selected_local_service).title}}
              <div class="no-attach">
                <label><input type="checkbox" v-model="s.exclude_direction"> не назначать</label>
              </div>
            </div>
            <div class="service-l2" v-else-if="s.local_services.length > 1">
              <div class="l2-notice">Найдено несколько исследований с таким кодом</div>
              <ul>
                <li v-for="rs in s.local_services">
                  <label class="fwn">
                    <input type="radio" :value="rs" v-model="s.selected_local_service">
                    <span class="service-department">
                      {{departments[research_data(rs).department_pk].title}}
                    </span>
                    {{research_data(rs).title}}
                  </label>
                </li>
              </ul>
              <div class="no-attach">
                <label><input type="checkbox" v-model="s.exclude_direction"> не назначать</label>
              </div>
            </div>
            <div class="service-l2" v-else>
              <div class="l2-notice">Исследований с таким кодом не найдено</div>
              <div v-if="s.selected_local_service !== -1">
                Будет произведена замена на:
                <div class="service-department">
                  {{departments[research_data(s.selected_local_service).department_pk].title}}
                </div>
                {{research_data(s.selected_local_service).title}}
              </div>
              <div :id="'template-' + s.pk">
                <div style="width: 666px;height: 280px;text-align: left;">
                  <researches-picker v-model="s.selected_local_service" autoselect="none" :hidetemplates="true"
                                     :oneselect="true"/>
                </div>
              </div>
              <button class="btn btn-primary-nb btn-blue-nb btn-sm" style="margin-top: 3px"
                      v-tippy="{ html: '#template-' + s.pk, reactive : true, interactive : true, theme : 'light', animateFill : false, trigger: 'click' }">
                Заменить исследование
              </button>
              <div class="no-attach">
                <label><input type="checkbox" v-model="s.exclude_direction"> не назначать</label>
              </div>
            </div>
          </div>
        </div>
        <div class="direction-control">
          <button class="btn btn-primary-nb btn-blue-nb" @click="cancel">Отмена</button>
          <button class="btn btn-primary-nb btn-blue-nb" :disabled="!valid" @click="generateDirections">Создать
            направления в L2
          </button>
        </div>
      </div>
      <div class="directions-content" style="line-height: 200px;text-align: center;color:grey" v-else>
        Направление не выбрано
      </div>
    </div>
    <div slot="body" style="line-height: 200px;text-align: center" v-else>
      Загрузка данных...
    </div>
    <div slot="footer">
      <div class="row">
        <div class="col-xs-4">
          <button type="button" @click="load_data" class="btn btn-primary-nb btn-blue-nb"
                  :disabled="selected_direction !== -1">Перезагрузить
          </button>
        </div>
        <div class="col-xs-4">
        </div>
        <div class="col-xs-4">
          <button type="button" @click="hide_modal" class="btn btn-primary-nb btn-blue-nb"
                  :disabled="selected_direction !== -1">Закрыть
          </button>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
  import Modal from '../ui-cards/Modal'
  import directions_point from '../api/directions-point'
  import * as action_types from '../store/action-types'
  import ResearchesPicker from '../ui-cards/ResearchesPicker'

  export default {
    name: 'rmis-directions-viewer',
    components: {Modal, ResearchesPicker},
    props: {
      card: {
        type: Object,
        required: true
      }
    },
    data() {
      return {
        rows: [],
        loaded: false,
        direction_data: {},
        selected_direction: -1,
        post: false
      }
    },
    created() {
      this.load_data()
    },
    computed: {
      departments() {
        let deps = {}
        for (let dep of this.$store.getters.allDepartments) {
          deps[dep.pk] = dep
        }
        return deps
      },
      valid() {
        if (this.selected_direction === -1 || Object.keys(this.direction_data).length === 0)
          return false
        let has_n_ex = false
        for (let r of this.direction_data.services) {
          if (r.selected_local_service === -1 && !r.exclude_direction) {
            return false
          }
          if (!r.exclude_direction)
            has_n_ex = true
        }
        return has_n_ex
      },
      has_excluded() {
        if (!this.valid())<commit_msg>computed fix<commit_after><template>
  <modal ref="modal" @close="hide_modal" show-footer="true" white-bg="true" min-width="85%" margin-top
         :no-close="selected_direction !== -1">
    <span slot="header">Направления из РМИС. Пациент: {{card.family}} {{card.name}} {{card.twoname}},
      {{card.birthday}} ({{card.age}})</span>
    <div slot="body" style="min-height: 200px" class="directions-manage" v-if="loaded">
      <div class="directions-sidebar">
        <div @click="select_direction(d.pk)" class="direction" :class="{active: d.pk === selected_direction}"
             v-for="d in rows">
          <div>РМИС-направление №{{d.pk}} от {{d.referralDate}}</div>
          <div>Направляющая организация: {{d.referralOrganization}}</div>
          <hr/>
          <ol>
            <li v-for="s in d.services"><span class="s-code" v-if="s.code">{{s.code}}</span>
              {{s.title}}
            </li>
          </ol>
        </div>
        <div v-if="rows.length === 0" class="text-center" style="padding: 10px">
          Направлений из РМИС, не зарегистрированных в L2, не найдено
        </div>
      </div>
      <div class="directions-content" v-if="selected_direction !== -1">
        <div class="direction-data">
          <h4>РМИС-направление №{{direction_data.pk}} от {{direction_data.referralDate}}</h4>
          Организация: {{direction_data.referralOrganization}}<br/>
          <div v-if="direction_data.diagnosis">Диагноз: {{direction_data.diagnosis}}
            ({{direction_data.diagnosisName}})
          </div>
          <hr/>
          <div class="direction-service">
            <div class="service-rmis">
              <div class="s-title"><strong>Исследование в РМИС</strong></div>
            </div>
            <div class="service-l2"><strong>Исследование в L2</strong></div>
          </div>
          <div class="direction-service"
               :class="{wrn: s.selected_local_service === -1 && !s.exclude_direction, cancel: s.exclude_direction}"
               v-for="s in direction_data.services">
            <div class="service-rmis">
              <div class="s-code">{{s.code}}</div>
              <div class="s-title">{{s.title}}</div>
            </div>
            <div class="service-l2" v-if="s.local_services.length === 1 && s.selected_local_service !== -1">
              <div class="service-department">
                {{departments[research_data(s.selected_local_service).department_pk].title}}
              </div>
              {{research_data(s.selected_local_service).title}}
              <div class="no-attach">
                <label><input type="checkbox" v-model="s.exclude_direction"> не назначать</label>
              </div>
            </div>
            <div class="service-l2" v-else-if="s.local_services.length > 1">
              <div class="l2-notice">Найдено несколько исследований с таким кодом</div>
              <ul>
                <li v-for="rs in s.local_services">
                  <label class="fwn">
                    <input type="radio" :value="rs" v-model="s.selected_local_service">
                    <span class="service-department">
                      {{departments[research_data(rs).department_pk].title}}
                    </span>
                    {{research_data(rs).title}}
                  </label>
                </li>
              </ul>
              <div class="no-attach">
                <label><input type="checkbox" v-model="s.exclude_direction"> не назначать</label>
              </div>
            </div>
            <div class="service-l2" v-else>
              <div class="l2-notice">Исследований с таким кодом не найдено</div>
              <div v-if="s.selected_local_service !== -1">
                Будет произведена замена на:
                <div class="service-department">
                  {{departments[research_data(s.selected_local_service).department_pk].title}}
                </div>
                {{research_data(s.selected_local_service).title}}
              </div>
              <div :id="'template-' + s.pk">
                <div style="width: 666px;height: 280px;text-align: left;">
                  <researches-picker v-model="s.selected_local_service" autoselect="none" :hidetemplates="true"
                                     :oneselect="true"/>
                </div>
              </div>
              <button class="btn btn-primary-nb btn-blue-nb btn-sm" style="margin-top: 3px"
                      v-tippy="{ html: '#template-' + s.pk, reactive : true, interactive : true, theme : 'light', animateFill : false, trigger: 'click' }">
                Заменить исследование
              </button>
              <div class="no-attach">
                <label><input type="checkbox" v-model="s.exclude_direction"> не назначать</label>
              </div>
            </div>
          </div>
        </div>
        <div class="direction-control">
          <button class="btn btn-primary-nb btn-blue-nb" @click="cancel">Отмена</button>
          <button class="btn btn-primary-nb btn-blue-nb" :disabled="!valid" @click="generateDirections">Создать
            направления в L2
          </button>
        </div>
      </div>
      <div class="directions-content" style="line-height: 200px;text-align: center;color:grey" v-else>
        Направление не выбрано
      </div>
    </div>
    <div slot="body" style="line-height: 200px;text-align: center" v-else>
      Загрузка данных...
    </div>
    <div slot="footer">
      <div class="row">
        <div class="col-xs-4">
          <button type="button" @click="load_data" class="btn btn-primary-nb btn-blue-nb"
                  :disabled="selected_direction !== -1">Перезагрузить
          </button>
        </div>
        <div class="col-xs-4">
        </div>
        <div class="col-xs-4">
          <button type="button" @click="hide_modal" class="btn btn-primary-nb btn-blue-nb"
                  :disabled="selected_direction !== -1">Закрыть
          </button>
        </div>
      </div>
    </div>
  </modal>
</template>

<script>
  import Modal from '../ui-cards/Modal'
  import directions_point from '../api/directions-point'
  import * as action_types from '../store/action-types'
  import ResearchesPicker from '../ui-cards/ResearchesPicker'

  export default {
    name: 'rmis-directions-viewer',
    components: {Modal, ResearchesPicker},
    props: {
      card: {
        type: Object,
        required: true
      }
    },
    data() {
      return {
        rows: [],
        loaded: false,
        direction_data: {},
        selected_direction: -1,
        post: false
      }
    },
    created() {
      this.load_data()
    },
    computed: {
      departments() {
        let deps = {}
        for (let dep of this.$store.getters.allDepartments) {
          deps[dep.pk] = dep
        }
        return deps
      },
      valid() {
        if (this.selected_direction === -1 || Object.keys(this.direction_data).length === 0)
          return false
        let has_n_ex = false
        for (let r of this.direction_data.services) {
          if (r.selected_local_service === -1 && !r.exclude_direction) {
            return false
          }
          if (!r.exclude_direction)
            has_n_ex = true
        }
        return has_n_ex
      },
      has_excluded() {
        if (!this.valid)
{'fraction_non_alphanumeric': 0.15590261201664052, 'fraction_numerical': 0.006547091318284117, 'mean_word_length': 1.9164677804295942, 'pattern_counts': {'":': 0, '<': 257, '<?xml version=': 0, '>': 259, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2004763', 'n_tokens_mistral': 4617, 'n_tokens_neox': 4538, 'n_words': 832}