<template>
    <v-layout class="mb-2 " column>
      <v-dialog v-model="dialog_list_test" scrollable max-width="420px">
        <v-card>
          <v-card-title class="font-weight-bold">Pemeriksaan Terpilih</v-card-title>
          <v-divider></v-divider>
          <v-card-text style="height: 300px;">
            <v-text-field
              v-for="test in selected_test" :key="test"
              label=""
              :value="test.T_TestName"
              disabled
              hide-details
            ></v-text-field>
          </v-card-text>
          <v-divider></v-divider>
          <v-card-actions>
            <v-spacer></v-spacer>
            <v-btn color="primary darken-1" flat @click="dialog_list_test = false">Tutup</v-btn>
          </v-card-actions>
        </v-card>
      </v-dialog>
      <v-dialog v-model="dialoginfo" persistent  max-width="290">
              <v-card>
                  <v-card-title
                      dark
                      class="headline error pt-2 pb-2"
                      primary-title
                      style="color:white"
                  >
                      <h4 dark>Info</h4>
                  </v-card-title>
                  <v-card-text>
                      {{msginfo}}
                  </v-card-text>
                  <v-card-actions>
                  <v-spacer></v-spacer>
                      <v-btn small color="primary darken-1 text-sm-right" flat @click="dialoginfo = false">Tutup</v-btn>
                  </v-card-actions>
              </v-card>
          </v-dialog>
      
      <v-card    height="650px">
        <v-system-bar color="primary darken-4" dark>
          <v-spacer></v-spacer>
          <v-icon small>mdi-square</v-icon>
          <v-icon class="ml-1" small>mdi-circle</v-icon>
          <v-icon class="ml-1" small>mdi-triangle</v-icon>
        </v-system-bar>
        <v-toolbar color="primary accent-4" cards dark flat>
          <v-toolbar-title class="title font-weight-regular">{{ selected_anamnese_tab.name }}</v-toolbar-title>
          <v-spacer></v-spacer>
          <v-chip @click="getData('TEXT')" v-if="selected_anamnese_tab && selected_anamnese_tab.id !== 'OPERATING' && type_field === 'TEXT'" label color="primary darken-4">Text</v-chip>
          <v-chip @click="getData('FORM')" v-if="selected_anamnese_tab && selected_anamnese_tab.id !== 'OPERATING' && type_field === 'TEXT'" label color="blue darken-5">Form</v-chip>
          <v-chip @click="getData('TEXT')" v-if="selected_anamnese_tab && selected_anamnese_tab.id !== 'OPERATING' && type_field === 'FORM'" label color="blue darken-5">Text</v-chip>
          <v-chip @click="getData('FORM')" v-if="selected_anamnese_tab && selected_anamnese_tab.id !== 'OPERATING' && type_field === 'FORM'" label color="primary darken-4">Form</v-chip>
        </v-toolbar>
        <v-form ref="form" v-model="form" class="pl-3 pr-3 pb-2 pt-2">
  
          <v-textarea v-if="type_field === 'TEXT' && selected_anamnese_tab" :disabled="selected_patient.orderIsCheck === 'D'" v-model="xnote"  box color="deep-purple" label="Keterangan" rows="23"></v-textarea>
         
          
          
          
  
          <template v-if="type_field === 'FORM'">
          <v-card height="477px" style="overflow-y:auto" flat  class="mb-2 pt-3 x_form">
            <div v-for="(riwayat,idx_r) in riwayats">
                <v-card class="mb-2" flat>
                    <v-layout pb-2 row>
                        <v-flex xs12>
                            <div v-if="riwayat.type_form === 'X'">
                                <v-layout v-if="riwayat.subtitle !== ''" class="pl-2 caption pb-2" row>{{riwayat.subtitle}}</v-layout>
                                <v-layout pl-2  pb-1 pt-1 v-for="(r_detail,idx_detail) in generate_rows(riwayat.details)"  wrap>
                                    <v-flex xs6 pa-1>
                                        <v-layout v-if="r_detail[0]" align-center row>
                                            <v-flex xs1>
                                                <v-checkbox row
                                                    class="mt-0 pt-0"
                                                    v-model="r_detail[0].chx"
                                                    :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                    color="red"
                                                    hide-details
                                                    @change="checkAnotherXCbx(r_detail[0].id_code,$event,idx_detail,idx_r)"
                                                ></v-checkbox>
                                            </v-flex>
                                            <v-flex xs11>
                                                <span style="font-size:12px"  :class="{'red--text':r_detail[0].color && r_detail[0].color == 'red'}">{{getnamelabel(r_detail[0].label)}}</span>
                                            </v-flex>
                                        </v-layout>
                                        
                                    </v-flex>
                                    <v-flex xs6 pa-1>
                                        <v-layout  v-if="r_detail[1]" align-center  row>
                                            <v-flex xs1>
                                                <v-checkbox row
                                                    class="mt-0 pt-0"
                                                    v-model="r_detail[1].chx"
                                                    :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                    color="red"
                                                    hide-details
                                                    @change="checkAnotherXCbx(r_detail[1].id_code,$event,idx_detail,idx_r)"
                                                    ></v-checkbox>
                                            </v-flex>
                                            <v-flex xs11>
                                                <span style="font-size:12px" :class="{'red--text':r_detail[1].color && r_detail[1].color == 'red'}">{{getnamelabel(r_detail[1].label)}}</span>
                                            </v-flex>
                                        </v-layout>
                                        
                                    </v-flex>
                                </v-layout>
                            </div>

                            <div v-if="riwayat.type_form === 'XV'">
                                <v-layout v-if="riwayat.subtitle !== ''" class="pl-2 caption pb-2" row>{{riwayat.subtitle}}</v-layout>
                                <v-layout pl-2  pb-1 pt-1 v-for="(r_detail,idx_detail) in generate_rows(riwayat.details)"  wrap>
                                    <v-flex xs6 pa-1>
                                        <v-layout v-if="r_detail[0]" align-center row>
                                            <v-flex xs1>
                                                <v-checkbox row
                                                    class="mt-0 pt-0"
                                                    v-model="r_detail[0].chx"
                                                    :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                    color="red"
                                                    hide-details
                                                ></v-checkbox>
                                            </v-flex>
                                            <v-flex xs7>
                                                <span style="font-size:12px"  :class="{'red--text':r_detail[0].color && r_detail[0].color == 'red'}">{{getnamelabel(r_detail[0].label)}}</span>
                                            </v-flex>
                                            <v-flex xs4 pl-1 pr-2>
                                                <v-text-field
                                                    style="font-size:12px;margin-top:0;padding-top:0;line-height:25px!important"
                                                    outline
                                                    v-model="r_detail[0].value"
                                                    :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                    single-line
                                                    :placeholder="getnamelabel('Keterangan')"
                                                    hide-details
                                                ></v-text-field>
                                            </v-flex>
                                        </v-layout>
                                        
                                    </v-flex>
                                    <v-flex xs6 pa-1>
                                        <v-layout  v-if="r_detail[1]" align-center  row>
                                            <v-flex xs1>
                                                <v-checkbox row
                                                    class="mt-0 pt-0"
                                                    v-model="r_detail[1].chx"
                                                    :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                    color="red"
                                                    hide-details
                                                    ></v-checkbox>
                                            </v-flex>
                                            <v-flex xs7>
                                                <span style="font-size:12px" :class="{'red--text':r_detail[1].color && r_detail[1].color == 'red'}">{{getnamelabel(r_detail[1].label)}}</span>
                                            </v-flex>
                                            <v-flex xs4 pl-1 pr-2>
                                                <v-text-field
                                                    style="font-size:12px;margin-top:0;padding-top:0;line-height:25px!important"
                                                    outline
                                                    v-model="r_detail[1].value"
                                                    :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                    single-line
                                                    :placeholder="getnamelabel('Keterangan')"
                                                    hide-details
                                                ></v-text-field>
                                            </v-flex>
                                        </v-layout>
                                        
                                    </v-flex>
                                </v-layout>
                            </div>
                            
                            <div v-if="riwayat.type_form === 'XVS'">
                                <v-layout pl-2 v-for="(segment,idx_segment) in riwayat.details" :key="idx_segment" wrap>
                                    <v-flex xs12>
                                        <v-layout  row>{{getnamelabel(segment.name)}}</v-layout>
                                        <v-layout v-if="riwayat.show_all === 'Y' && segment.caption && segment.caption !== ''" row><span class="caption red--text">{{segment.caption}}</span></v-layout>
                                        <v-layout pl-2  pb-1 pt-1 v-for="(r_detail,idx_detail) in generate_rows(segment.details)"  wrap>
                                            <v-flex xs6 pa-1>
                                                <v-layout v-if="r_detail[0]" align-center row>
                                                    <v-flex xs1>
                                                        <v-checkbox row
                                                            class="mt-0 pt-0"
                                                            v-model="r_detail[0].chx"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            color="red"
                                                            hide-details
                                                            @change="checkXVSRiwayatCbx(r_detail[0].id_code,$event,idx_segment,idx_r)"
                                                        ></v-checkbox>
                                                    </v-flex>
                                                    <v-flex xs7>
                                                        <span style="font-size:12px"  :class="{'red--text':r_detail[0].color && r_detail[0].color == 'red'}">{{getnamelabel(r_detail[0].label)}}</span>
                                                    </v-flex>
                                                    <v-flex xs4 pl-1 pr-2>
                                                        <v-text-field
                                                            style="font-size:12px;margin-top:0;padding-top:0;line-height:25px!important"
                                                            outline
                                                            v-model="r_detail[0].value"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            single-line
                                                            :placeholder="getnamelabel('Keterangan')"
                                                            hide-details
                                                        ></v-text-field>
                                                    </v-flex>
                                                </v-layout>
                                                
                                            </v-flex>
                                            <v-flex xs6 pa-1>
                                                <v-layout  v-if="r_detail[1]" align-center  row>
                                                    <v-flex xs1>
                                                        <v-checkbox row
                                                            class="mt-0 pt-0"
                                                            v-model="r_detail[1].chx"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            color="red"
                                                            hide-details
                                                            @change="checkXVSRiwayatCbx(r_detail[1].id_code,$event,idx_segment,idx_r)"
                                                            ></v-checkbox>
                                                    </v-flex>
                                                    <v-flex xs7>
                                                        <span style="font-size:12px" :class="{'red--text':r_detail[1].color && r_detail[1].color == 'red'}" >{{getnamelabel(r_detail[1].label)}}</span>
                                                    </v-flex>
                                                    <v-flex xs4 pl-1 pr-2>
                                                        <v-text-field
                                                            style="font-size:12px;margin-top:0;padding-top:0;line-height:25px!important"
                                                            outline
                                                            v-model="r_detail[1].value"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            single-line
                                                            :placeholder="getnamelabel('Keterangan')"
                                                            hide-details
                                                        ></v-text-field>
                                                    </v-flex>
                                                </v-layout>
                                                
                                            </v-flex>
                                        </v-layout>
                                    </v-flex>
                                </v-layout>
                            </div>

                            <div v-if="riwayat.type_form === 'XO'">
                                <v-layout v-if="riwayat.subtitle !== ''" class="pl-2 caption pb-2" row>{{riwayat.subtitle}}</v-layout>
                                <v-layout  class="pl-2 caption pb-2" row>
                                    <v-flex xs12 pa-1>
                                        <v-layout align-center row>
                                            <v-flex xs4></v-flex>
                                            <v-flex class="text-xs-left" xs2>
                                                Ayah
                                            </v-flex>
                                            <v-flex class="text-xs-left" xs2>
                                                Ibu
                                            </v-flex>
                                            <v-flex class="text-xs-left" xs2>
                                                Saudara Kandung
                                            </v-flex>
                                            <v-flex class="text-xs-left" xs2>
                                                Kakek/Nenek
                                            </v-flex>
                                            <v-flex class="text-xs-left" xs2>
                                                Saudara Lainnya
                                            </v-flex>
                                        </v-layout>
                                    </v-flex>
                                </v-layout>
                                <v-layout pl-2  pb-1 pt-1 v-for="(r_detail,idx_detail) in riwayat.details"  wrap>
                                    <v-flex xs12 pa-1>
                                        <v-layout align-center row>
                                            <v-flex xs4>{{getnamelabel(r_detail.label)}}</v-flex>
                                            <v-flex xs2  class="text-xs-left"  v-for="(opsi,idx_opsi) in r_detail.options" >
                                                <v-checkbox row
                                                    class="mt-0 pt-0 text-xs-left"
                                                    v-model="opsi.selected"
                                                    :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                    color="red"
                                                    hide-details
                                                ></v-checkbox>
                                            </v-flex>
                                        </v-layout>
                                    </v-flex>

                                
                                </v-layout>
                            </div>

                            <div v-if="riwayat.type_form === 'XD'">
                                <v-layout pl-2 v-for="(segment,idx_segment) in riwayat.details" :key="idx_segment" mb-2 wrap>
                                    <v-flex xs12>
                                        <v-layout  row>{{getnamelabel(segment.label)}}</v-layout>
                                        <v-layout v-if="riwayat.show_all === 'Y' && segment.caption && segment.caption !== ''" row><span class="caption red--text">{{segment.caption}}</span></v-layout>
                                        <v-layout pl-2  pb-1 pt-1 v-for="(r_detail,idx_detail) in generate_rows(segment.details)" :key="idx_detail"  wrap>
                                            <v-flex xs6 pa-1>
                                                <v-layout v-if="r_detail[0]" align-center row>
                                                    <v-flex xs1>
                                                        <v-checkbox row
                                                            class="mt-0 pt-0"
                                                            v-model="r_detail[0].chx"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            color="red"
                                                            hide-details
                                                            @change="checkAnotherCbx(r_detail[0].id_code,$event,idx_segment,idx_r)"
                                                        ></v-checkbox>
                                                    </v-flex>
                                                    <v-flex xs6>
                                                        <span style="font-size:12px"  :class="{'red--text':r_detail[0].color && r_detail[0].color == 'red'}">{{getnamelabel(r_detail[0].label)}}</span>
                                                    </v-flex>
                                                    <v-flex xs5 v-if="r_detail[0].show_date"  pl-1 pr-2>
                                                        <v-text-field
                                                            style="font-size:12px;margin-top:0;padding-top:0;line-height:25px!important"
                                                            outline
                                                            v-model="r_detail[0].value"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            :readonly="!r_detail[0].chx"
                                                            single-line
                                                            :placeholder="getnamelabel('DD/MM/YYYY')"
                                                            hide-details
                                                            
                                                        ></v-text-field>
                                                    </v-flex>
                                                </v-layout>
                                                
                                            </v-flex>
                                            <v-flex xs6 pa-1>
                                                <v-layout  v-if="r_detail[1]" align-center  row>
                                                    <v-flex xs1>
                                                        <v-checkbox row
                                                            class="mt-0 pt-0"
                                                            v-model="r_detail[1].chx"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            color="red"
                                                            hide-details
                                                            @change="checkAnotherCbx(r_detail[1].id_code,$event,idx_segment,idx_r)"
                                                            ></v-checkbox>
                                                    </v-flex>
                                                    <v-flex xs6>
                                                        <span  style="font-size:12px" :class="{'red--text':r_detail[1].color && r_detail[1].color == 'red'}">{{getnamelabel(r_detail[1].label)}}</span>
                                                    </v-flex>
                                                    <v-flex xs5 v-if="r_detail[1].show_date" pl-1 pr-2>
                                                        <v-text-field
                                                            style="font-size:12px;margin-top:0;padding-top:0;line-height:25px!important"
                                                            outline
                                                            v-model="r_detail[1].value"
                                                            :readonly="!r_detail[1].chx"
                                                            :disabled="riwayat.flag_normal === 'Y' || cantedit"
                                                            single-line
                                                            :placeholder="getnamelabel('DD/MM/YYYY')"
                                                            hide-details
                                                        ></v-text-field>
                                                    </v-flex>
                                                </v-layout>
                                                
                                            </v-flex>
                                        </v-layout>
                                    </v-flex>
                                </v-layout>
                            </div>
                            
                        </v-flex>
                    </v-layout>    
                </v-card>
            </div>    
        </v-card>
        
         
          </template>
        
    </v-form>
        <v-divider class="mb-1"></v-divider>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn v-if="selected_patient.orderIsCheck !== 'D'" :disabled="save_progress" @click="saveText()" class="white--text" color="primary" depressed>Simpan</v-btn>
        </v-card-actions>
  
      </v-card>
      
    </v-layout>
</template>
  
<style scoped>
  .divider.x_step{
          border-color:#fff;
      }
      .x_form .v-text-field--outline>.v-input__control>.v-input__slot {
          align-items: stretch;
          min-height: 20px!important;
          margin-top:0;
          line-height:25px;
      }
  
      .x_form .v-text-field--outline.v-text-field--single-line input {
          margin-top: 0px!important;
          font-size:14px;
      }
  .mini-input .v-input{
      margin-top: 0px; 
  }
  
  .mini-input .v-input, .mini-input .v-input--selection-controls,.mini-input .v-input__slot{
      margin-top: 0px; 
      margin-bottom:0px;
      margin-left:3px;
  }
  .mini-input .v-messages{
      min-height:0px;
  }
  input.fhm-input{
      border: 1px solid black; 
      border-radius: 2px;
      -webkit-box-shadow: 
      inset 0 0 2px  rgba(0,0,0,0.1),
              0 0 4px rgba(0,0,0,0.1); 
      -moz-box-shadow: 
      inset 0 0 2px  rgba(0,0,0,0.1),
              0 0 4px rgba(0,0,0,0.1); 
      box-shadow: 
      inset 0 0 2px  rgba(0,0,0,0.1),
              0 0 4px rgba(0,0,0,0.1); 
      padding: 2px 4px;
      background: rgba(255,255,255,0.5);
      margin: 0 0 1px 0;
      width:30px;
      text-align:center;
  }
  
  .overflowTests {
    width: 100%;
    height: 420px;
    overflow-x: auto;
  }
</style>
  
<script>
  module.exports = {
    data: () => ({
      model_chx_all:false,
      notifications:false,
      show:false,
      switchMe: false,
      form: false,
      dialog_list_test:false,
      search_icd10primer:'',
      search_icd10sekunder:''
    }),
    computed: {
        riwayats:{
        get() {
            return this.$store.state.patient.riwayats
        },
        set(val) {
            this.$store.commit("patient/update_riwayats",val)
        }
      },
      loadingTest(){
        return this.$store.state.patient.loading_test
      },
      isLoading(){
        return this.$store.state.patient.update_autocomplete_status
      },
      selected_icd10_primer:{
        get() {
            return this.$store.state.patient.selected_icd10_primer
        },
        set(val) {
            this.$store.commit("patient/update_selected_icd10_primer",val)
        }
      },
      icd10_primer:{
        get() {
            return this.$store.state.patient.icd10_primer
        },
        set(val) {
            this.$store.commit("patient/update_icd10_primer",val)
        }
      },
      selected_icd10_sekunder:{
        get() {
            return this.$store.state.patient.selected_icd10_sekunder
        },
        set(val) {
            this.$store.commit("patient/update_selected_icd10_sekunder",val)
        }
      },
      icd10_sekunder:{
        get() {
            return this.$store.state.patient.icd10_sekunder
        },
        set(val) {
            this.$store.commit("patient/update_icd10_sekunder",val)
        }
      },
      cantedit:{
              get() {
                  return this.$store.state.patient.cantedit
              },
              set(val) {
                  this.$store.commit("patient/update_cantedit",val)
              }
          },
      fisiks: {
        get() {
          return this.$store.state.patient.fisiks
        },
        set(val) {
          this.$store.commit("patient/update_fisiks", val)
        }
      },
      type_field: {
        get() {
          return this.$store.state.patient.type_field
        },
        set(val) {
          this.$store.commit("patient/update_type_field", val)
        }
      },
      dialoginfo: {
        get() {
          return this.$store.state.patient.dialoginfo
        },
        set(val) {
          this.$store.commit("patient/update_dialoginfo", val)
        }
      },
      msginfo: {
        get() {
          return this.$store.state.patient.msginfo
        },
        set(val) {
          this.$store.commit("patient/update_msginfo", val)
        }
      },
      header_tab: {
        get() {
          return this.$store.state.patient.header_tab
        },
        set(val) {
          this.$store.commit("patient/update_header_tab", val)
        }
      },
      tests: {
        get() {
          return this.$store.state.patient.tests
        },
        set(val) {
          this.$store.commit("patient/update_tests", val)
        }
      },
      selected_test: {
        get() {
          return this.$store.state.patient.selected_test
        },
        set(val) {
          this.$store.commit("patient/update_selected_test", val)
        }
      },
      select_subgroup: {
        get() {
          return this.$store.state.patient.select_subgroup
        },
        set(val) {
          this.$store.commit("patient/update_select_subgroup", val)
        }
      },
      subgroup_tests: {
        get() {
          return this.$store.state.patient.subgroup_tests
        },
        set(val) {
          this.$store.commit("patient/update_subgroup_tests", val)
        }
      },
      search_test: {
        get() {
          return this.$store.state.patient.search_test
        },
        set(val) {
          this.$store.commit("patient/update_search_test", val)
        }
      },
      group_tests: {
        get() {
          return this.$store.state.patient.group_tests
        },
        set(val) {
          this.$store.commit("patient/update_group_tests", val)
        }
      },
      selectAllSubGroup () {
          return this.select_subgroup.length === this.subgroup_tests.length
        },
        selectSomeSubGroup () {
          return this.select_subgroup.length > 0 && !this.selectAllSubGroup
        },
        icon () {
          if (this.selectAllSubGroup) return 'mdi-close-box'
          if (this.selectSomeSubGroup) return 'mdi-minus-box'
          return 'mdi-checkbox-blank-outline'
        },
      pgrs_save() {
  
        return this.$store.state.patient.pgrs_save
      },
      xnote: {
        get() {
          return this.$store.state.patient.xnote
        },
        set(val) {
          this.$store.commit("patient/update_xnote", val)
        }
      },
      in_saving: {
        get() {
          return this.$store.state.patient.in_saving
        },
        set(val) {
          this.$store.commit("patient/update_in_saving", val)
        }
      },
      dialogconfirmationdelete: {
        get() {
          return this.$store.state.patient.dialog_confirmation_delete
        },
        set(val) {
          this.$store.commit("patient/update_dialog_confirmation_delete", val)
        }
      },
      selected_anamnese_tab: {
        get() {
          return this.$store.state.patient.selected_anamnese_tab
        },
        set(val) {
          this.$store.commit("patient/update_selected_anamnese_tab", val)
        }
      },
      active_name: {
        get() {
          return this.$store.state.patient.active_name
        },
        set(val) {
          this.$store.commit("patient/update_active_name", val)
        }
      },
     
     
      save_progress: {
        get() {
          return this.$store.state.patient.save_progress
        },
        set(val) {
          this.$store.commit("patient/update_save_progress", val)
        }
      },
      selected_patient: {
        get() {
          return this.$store.state.patient.selected_patient
        },
        set(val) {
          this.$store.commit("patient/update_selected_patient", val)
        }
      },
      selected_anamnese_tab: {
        get() {
          return this.$store.state.patient.selected_anamnese_tab
        },
        set(val) {
          this.$store.commit("patient/update_selected_anamnese_tab", val)
        }
      },
    },
    methods: {
        changeFlagNormal(idx){
            var riwayats = this.$store.state.patient.riwayats
            var old_val = riwayats[idx].flag_normal
            riwayats[idx].flag_normal = old_val === 'Y'?'N':'Y'
            if(riwayats[idx].flag_normal === 'Y'){
                riwayats[idx].details.forEach((item) => item.chx = false)
                riwayats[idx].details.forEach((item) => item.value = '')
            }
            this.$store.commit("patient/update_riwayats",riwayats)
        },
        toggleDetailRiwayat(idx){
            var riwayats = this.$store.state.patient.riwayats
            var old_val = riwayats[idx].show_all
            riwayats[idx].show_all = old_val === 'Y'?'N':'Y'
            this.$store.commit("patient/update_riwayats",riwayats)
        },
        checkXVSRiwayatCbx(id_code,event,idx_detail,idx_segment){
            var riwayats = this.riwayats
            var data = riwayats[idx_segment].details[idx_detail].details
            if(riwayats[idx_segment].title === 'RIWAYAT KEBIASAAN HIDUP'){
                data.forEach((value,key) => {
                    if(value.id_code !== id_code){
                        data[key].chx = false
                        data[key].value = ''
                    }
                });
                console.log('check')
                console.log(data)
                this.riwayats = riwayats
            }
            
        },
        checkAnotherXCbx(id_code,event,idx_detail,idx_segment){
            var riwayats = this.riwayats
            var data = riwayats[idx_segment].details
            data.forEach((value,key) => {
                if(value.id_code !== id_code){
                    data[key].chx = false
                    data[key].value = ''
                }
            });
            this.riwayats = riwayats
        },
        checkAnotherCbx(id_code,event,idx_detail,idx_segment){
            var riwayats = this.riwayats
            var data = riwayats[idx_segment].details[idx_detail].details
            //console.log(id_code)
            //console.log(event)
            //console.log(details)
            //console.log(data)
            data.forEach((value,key) => {
                if(value.id_code !== id_code){
                    data[key].chx = false
                    data[key].value = ''
                }
            });
            console.log('check')
            console.log(data)
            this.riwayats = riwayats
        },
      generate_rows(details){
              //console.log(details)
              var riwayats = details
              var row_riwayats = []
              var rows = []
              riwayats.forEach(function(item,index){
                  rows.push(item)
                  if(index%2 !== 0 || index === riwayats.length - 1 ){
                      row_riwayats.push(rows)
                      rows = []
                  }
              })
              //console.log(row_riwayats)
              return row_riwayats
          },
      getnamelabel(kata){
        return kata
      },
      
      
      searchTest(){
        var prm = {}
        prm.subgroup = this.select_subgroup
        prm.search = this.search_test
        prm.group_id = this.group_tests[this.header_tab]
        this.$store.dispatch("patient/get_tests", prm)
      },
      clickSelectTest(index,test,value){
        let tests = this.tests
        tests[index].selected = !value
        this.tets = tests
        this.changeSelectTest(test,tests[index].selected )
      },
      changeSelectTest(index,test,value){
        value = !value
        if(value){
          if(this.selectPx(test,index)){
            let tests = this.tests
            tests[index].selected = value
            this.tests = tests
          }
        }else{
          let new_seltest = this.selected_test.filter(function(item) {
            return item.T_TestID !== test.T_TestID
          })  
          this.selected_test = new_seltest
          this.$store.commit('patient/update_nat_test')
          let tests = this.tests
          tests[index].selected = false
          this.tests = tests
        }
        
      },
      selectPx(px,index){
        // IF PROFILE
        //console.log(px.px_type)
        if (px.px_type == "PR" || px.px_type == "PXR")
                 return this.selectProfile(px,index)
  
          // SEARCH NAT TEST
          let nt = this.$store.state.patient.nat_test
          //console.log(px.nat_test)
          let found_nt = false
          for (let i in px.nat_test) {
              console.log(px.nat_test[i])
              if (nt.indexOf(px.nat_test[i]) > -1)
              found_nt = true
          }
  
          console.log(found_nt)
          if (found_nt) {
              this.dialoginfo = true
              this.msginfo = "Pemeriksaan tersebut sudah ada !"
              return false
          }
  
          in_selectPx = true
          let selected_test = this.$store.state.patient.selected_test
          let flag_found = false
          selected_test.forEach( function(t,idx) {
              if (t.T_TestID == px.T_TestID) {
                selected_test[idx] = px 
                flag_found = true
              }
          })
          if (!flag_found) {
              selected_test.push(px)
          }
          this.selected_test = selected_test
          this.$store.commit('patient/update_nat_test')
          return true
      },
      selectProfile(px,index) {
  
        // SEARCH NAT TEST
        let nt = this.$store.state.patient.nat_test
        let found_nt = false
        for (let i in px.nat_test) {
            if (nt.indexOf(px.nat_test[i]) > -1)
              found_nt = true
        }
  
        if (found_nt) {
            this.dialoginfo = true
            this.msginfo = "Pemeriksaan tersebut sudah ada !"
            return false
        }
  
        let selected_test = this.$store.state.patient.selected_test
        selected_test.push(px)
            
        this.selected_test = selected_test
        
        this.$store.commit('patient/update_nat_test')
        return true
  
        },
      savePx(){
        this.save_progress = true;
        var prm = {}
        prm.orderid = this.$store.state.patient.selected_patient.orderID
        prm.doctor = this.$store.state.patient.selected_doctor
        prm.selected_test = this.selected_test
        console.log(prm.selected_test)
        if(prm.selected_test.length > 0)
        this.$store.dispatch("patient/savepx", prm)
        else{
          this.dialoginfo = true
          this.msginfo = "Anda belum memilih pemeriksaan"
        }
  
      },
      changeGroup(value){
        console.log(value)
        var prm = {}
        this.select_subgroup = []
        this.search_test = ""
        prm.subgroup = this.select_subgroup
        prm.search = this.search_test
        //this.header_tab = parseInt(group.id)
        prm.group_id = this.group_tests[this.header_tab]
        this.$store.dispatch("patient/get_tests", prm)
      },
      changeFilterSubgroup(value){
        var prm = {}
        prm.subgroup = value
        prm.search = this.search_test
        prm.group_id = this.group_tests[this.header_tab]
        this.$store.dispatch("patient/get_tests", prm)
      },
      toggle () {
          this.$nextTick(() => {
            if (this.selectAllSubGroup) {
              this.select_subgroup = []
            } else {
              this.select_subgroup = this.subgroup_tests.slice()
            }
          })
        },
      selectAll(value){
        console.log(value)
      },
      clearText(){
        this.xnote = ""
      },
      saveText() {
        this.save_progress = true;
        var prm = {}
        prm.orderid = this.$store.state.patient.selected_patient.orderID
        prm.doctor = this.$store.state.patient.selected_doctor
        prm.note = this.xnote
        prm.json_form = this.riwayats
        prm.selected_anamnese_tab = this.$store.state.patient.selected_anamnese_tab
        prm.type = this.type_field
        prm.new_tab = this.$store.state.patient.selected_anamnese_tab
        prm.end_session = false
        this.$store.dispatch("patient/savetextanamnese", prm)
      },
      
      getData(value){
        this.$store.commit("patient/update_type_field", value)
        this.$store.dispatch("patient/get_data_anamnese")
      },
      thr_search_icd10primer: _.debounce( function () {
          this.$store.dispatch("patient/search_icd10",{type:'primer',search:this.search_icd10primer})
      },2000),
      thr_search_icd10sekunder: _.debounce( function () {
          this.$store.dispatch("patient/search_icd10",{type:'sekunder',search:this.search_icd10sekunder})
      },2000),
    },
    watch: {
        search_icd10primer(val,old) {
          if (val == old ) return
          if (! val) return
          if (val.length < 1 ) return
          if (this.$store.state.patient.update_autocomplete_status == 1 ) return  
          //this.selected_icd10_primer = {}
          this.thr_search_icd10primer()
        },
        search_icd10sekunder(val,old) {
          if (val == old ) return
          if (! val) return
          if (val.length < 1 ) return
          if (this.$store.state.patient.update_autocomplete_status == 1 ) return  
          //this.selected_icd10_sekunder = {}
          this.thr_search_icd10sekunder()
        }
     }
  }
  </script>