<template>
    <div>
        <v-snackbar
            v-model="snackbar"
            color="success"
            :auto-height="true"
            :timeout="5000"
            :right="true"
            :multi-line="false"
            :vertical="false"
            :bottom="true">
            {{msgsnackbar}}
            <v-btn flat="flat" @click="updateAlert_success(false)">
                Tutup
            </v-btn>
        </v-snackbar>
        <v-dialog v-model="dialog_form" max-width="510px">
            <v-card>
                <v-card-title>
                    <h4 class="font-weight-bold">FORM</h5>

                </v-card-title>
                <v-card-text>
                    <v-layout row="row">
                        <v-flex xs12="xs12">
                            <v-layout class="mb-2" row="row">
                                <v-flex xs12="xs12">
                                    <v-text-field
                                        label="Nomor Surat"
                                        v-model="data_surat.xnumber"
                                        hide-details="hide-details"></v-text-field>
                                </v-flex>
                            </v-layout>
                            <v-layout class="mb-2" row="row">
                                <v-flex xs12="xs12">
                                    <v-text-field
                                        label="Pekerjaan"
                                        v-model="data_surat.pekerjaan"
                                        hide-details="hide-details"></v-text-field>
                                </v-flex>
                            </v-layout>
                            <v-layout  class="mb-3" row>
                                <v-flex xs12>
                                    <v-autocomplete
                                        label="Pilih Dokter"
                                        v-model="selected_doctor"
                                        :items="doctors"
                                        :search-input.sync="search_doctor"
                                        auto-select-first="auto-select-first"
                                        hide-details="hide-details"
                                        no-filter="no-filter"
                                        item-text="name"
                                        return-object="return-object"
                                        :loading="isLoading"
                                        no-data-text="Semua">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.name"></v-list-tile-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                    </v-layout>
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn
                        small="small"
                        dark="dark"
                        flat="flat"
                        color="blue"
                        @click="saveFormLetter()">Simpan</v-btn>

                    <v-btn
                        small="small"
                        dark="dark"
                        flat="flat"
                        color="grey"
                        @click="dialog_form = false">Tutup</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-dialog v-model="dialogbarcode" persistent="persistent" max-width="490">
            <v-card>
                <v-card-title style="color:#fff" class="headline grey darken-1">Cetak Barcode</v-card-title>
                <v-card-text>
                    <v-layout pa-2="pa-2" class="grey lighten-2" row="row">
                        <v-flex xs1="xs1">
                            <v-checkbox
                                style="padding-top:0;margin-top:0"
                                hide-details="hide-details"
                                color="grey darken-1"
                                :indeterminate="indeterminatex"
                                @change="changeCbxAll(bar_chx_all)"
                                v-model="bar_chx_all"></v-checkbox>
                        </v-flex>
                        <v-flex xs5="xs5">
                            SPECIMEN
                        </v-flex>
                        <v-flex xs4="xs4">
                            BARCODE
                        </v-flex>
                        <v-flex xs2="xs2">
                            CETAK
                        </v-flex>
                    </v-layout>
                    <v-layout
                        align-center="align-center"
                        pa-2="pa-2"
                        v-for="(vs,idx) in barcodes"
                        :key="vs.id"
                        class="grey lighten-4"
                        row="row">

                        <v-flex xs1="xs1">
                            <v-checkbox
                                v-if="vs.type === 'barcode' || vs.type === 'formulir'"
                                style="padding-top:0;margin-top:0"
                                color="grey darken-1"
                                hide-details="hide-details"
                                v-model="vs.chex"
                                @change="checkTop()"></v-checkbox>
                        </v-flex>
                        <v-flex xs5="xs5">
                            {{vs.T_SampleTypeName}}
                        </v-flex>
                        <v-flex xs4="xs4">
                            {{vs.T_BarcodeLabBarcode}}
                        </v-flex>
                        <v-flex xs2="xs2">
                            <span
                                @click="printSingleBarcode(vs)"
                                class="icon-medium-fill-base-small xs1 white--text grey darken-1  ml-1 icon-print"></span>
                        </v-flex>
                    </v-layout>
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="grey darken-1" flat="flat" @click="dialogbarcode = false">Tutup</v-btn>
                    <v-btn dark="dark" color="grey darken-3" @click="printRobo">Cetak Robo
                    </v-btn>
                    <v-btn dark="dark" color="grey darken-1" @click="printMultipleBarcode">Cetak terpilih [
                        {{selected_barcode.length}}
                        ]</v-btn>

                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-layout row>
           <v-flex xs5>
        <v-layout class="fill-height" column="column">
            <v-card class="mb-2 pa-2 searchbox">
                <v-layout align-center="align-center" row="row">
                    <v-flex xs3="xs3">
                        <v-menu
                            v-model="menufilterdatestart"
                            :close-on-content-click="false"
                            :nudge-right="40"
                            lazy="lazy"
                            transition="scale-transition"
                            offset-y="offset-y"
                            full-width="full-width"
                            max-width="290px"
                            min-width="290px">
                            <template v-slot:activator="{ on }">
                                <v-text-field
                                    class="mr-2"
                                    v-model="filterComputedDateFormattedStart"
                                    label="Tanggal Awal"
                                    outline="outline"
                                    hide-details="hide-details"
                                    readonly="readonly"
                                    v-on="on"
                                    @blur="date = deFormatedDate(filterComputedDateFormattedStart)"></v-text-field>
                            </template>
                            <v-date-picker
                                v-model="xdatestart"
                                no-title="no-title"
                                @input="menufilterdatestart = false"></v-date-picker>
                        </v-menu>
                    </v-flex>
                    <v-flex xs3="xs3">
                        <v-menu
                            v-model="menufilterdateend"
                            :close-on-content-click="false"
                            :nudge-right="40"
                            lazy="lazy"
                            transition="scale-transition"
                            offset-y="offset-y"
                            full-width="full-width"
                            max-width="290px"
                            min-width="290px">
                            <template v-slot:activator="{ on }">
                                <v-text-field
                                    class="mr-2"
                                    v-model="filterComputedDateFormattedEnd"
                                    label="Tanggal Akhir"
                                    outline="outline"
                                    hide-details="hide-details"
                                    readonly="readonly"
                                    v-on="on"
                                    @blur="date = deFormatedDate(filterComputedDateFormattedEnd)"></v-text-field>
                            </template>
                            <v-date-picker
                                v-model="xdateend"
                                no-title="no-title"
                                @input="menufilterdateend = false"></v-date-picker>
                        </v-menu>
                    </v-flex>
                    <v-flex xs3="xs3">
                        <v-text-field
                            style="font-size:14px"
                            label="No Reg / Nama"
                            class="mr-1"
                            outline="outline"
                            v-on:keyup.enter="searchPatient"
                            v-model="searchnamelab"
                            hide-details="hide-details"></v-text-field>
                    </v-flex>
                    <v-flex xs3="xs3">
                        <v-autocomplete
                            label="Kel. Pelanggan"
                            v-model="selected_company"
                            class="ma-1"
                            :items="xcompanies"
                            :search-input.sync="search_company"
                            auto-select-first="auto-select-first"
                            hide-details="hide-details"
                            style="font-size:14px"
                            outline="outline"
                            no-filter="no-filter"
                            item-text="name"
                            return-object="return-object"
                            :loading="isLoading"
                            no-data-text="Semua Kel. Pelanggan">
                            <template slot="item" slot-scope="{ item }">
                                <v-list-tile-content>
                                    <v-list-tile-title v-text="item.name"></v-list-tile-title>
                                </v-list-tile-content>
                            </template>
                        </v-autocomplete>
                    </v-flex>
                </v-layout>
            </v-card>
            <v-card >
                <v-layout pl-2="pl-2" pt-2="pt-2" row="row">
                    <h5>TOTAL PASIEN :
                        <span class="info--text">{{total_patients_all}}</span>
                        ORANG</h5>
                </v-layout>
                <v-layout align-center="align-center" row="row">
                    <v-flex xs12="xs12"  style="height:650px;overflow: auto;" pl-2="pl-2" pr-2="pr-2" pt-2="pt-2" pb-2="pb-2">
                        <v-data-table
                            :headers="headers"
                            :items="patients"
                            :loading="isLoading"
                            hide-actions="hide-actions"
                            class="elevation-1">
                            <template slot="items" slot-scope="props">
                                <tr :class="{notlunas: props.item.flaglunas=='N'} ">
                                    <td
                                        class="text-xs-left pa-2 'cito': isCito(props.item)"
                                        v-bind:class="{'':isSelected(props.item),'cito':  props.item.T_OrderHeaderIsCito === 'Y'}"
                                        @click="selectMe(props.item)">
                                        <span class="font-weight-black mono">{{ props.item.T_OrderHeaderLabNumber}}</span>
                                        <br/>
                                        <span class="font-weight-bold" style="color:#800000">
                                            {{props.item.external_numbering}}
                                        </span>
                                    </td>
                                    <td
                                        class="text-xs-left pa-2 'cito': isCito(props.item)"
                                        v-bind:class="{'':isSelected(props.item),'cito':  props.item.T_OrderHeaderIsCito === 'Y'}"
                                        @click="selectMe(props.item)">
                                        <p class="mb-0">{{ props.item.patient_fullname}}</p>
                                        <p class="mb-0">
                                            <kbd>{{props.item.test}}</kbd>
                                        </p>
                                        <p style="font-size:9px;color:red" class="pt-2 caption mb-0" >
                                            {{props.item.note}}
                                        </p>
                                    </td>
                                    <td
                                        class="text-xs-left pa-2 'cito': isCito(props.item)"
                                        v-bind:class="{'':isSelected(props.item),'cito':  props.item.T_OrderHeaderIsCito === 'Y'}"
                                        @click="selectMe(props.item)">
                                        <v-btn
                                            v-if="props.item.xid === '0'"
                                            color="grey"
                                            style="min-width:35px;"
                                            small="small"
                                            dark="dark"
                                            @click="opendialogForm(props.item)">
                                            <v-icon small="small">description</v-icon>
                                        </v-btn>
                                        <v-btn
                                            v-if="props.item.xid !== '0'"
                                            color="blue"
                                            style="min-width:35px;"
                                            small="small"
                                            dark="dark"
                                            @click="opendialogForm(props.item)">
                                            <v-icon small="small">description</v-icon>
                                        </v-btn>
                                        <v-btn
                                            v-if="props.item.xid !== '0'"
                                            color="orange"
                                            style="min-width:35px;"
                                            small="small"
                                            dark="dark"
                                            @click="openPrint(props.item)">
                                            <v-icon small="small">print</v-icon>
                                        </v-btn>
                                    </td>
                                </tr>
                            </template>
                        </v-data-table>
                        <v-divider></v-divider>
                        <v-layout>
                            <v-flex>
                                <v-pagination
                                    style="margin-top:10px;margin-bottom:10px"
                                    v-model="curr_page"
                                    :length="xtotal_page"></v-pagination>
                            </v-flex>
                            <v-flex ></v-flex>
                        </v-layout>
                    </v-flex>
                </v-layout>
            </v-card>
            <one-dialog-alert
                :status="openalertnopay"
                :msg="msgalertnopay"
                @forget-dialog-alert="forgetAlertNoPay()"
                @close-dialog-alert="closeAlertNoPay()"></one-dialog-alert>
            <div class="text-xs-left">
                <v-bottom-sheet persistent="persistent" v-model="sheet">
                    <v-card tile="tile">
                        <v-list>
                            <v-list-tile>
                                <v-list-tile-content>
                                    <v-list-tile-title>{{selected_patient.T_OrderHeaderLabNumber}}</v-list-tile-title>
                                    <v-list-tile-sub-title>{{selected_patient.M_PatientName}}</v-list-tile-sub-title>
                                </v-list-tile-content>

                                <v-list-tile-content class="ma-2">
                                    <v-btn @click="openBarcode()" color="warning" block="block" dark="dark">
                                        barcode
                                    </v-btn>
                                </v-list-tile-content>
                                <v-list-tile-content class="ma-2">
                                    <v-btn color="warning" block="block" dark="dark" @click="opendialogDob()">
                                        Revisi Tanggal Lahir
                                    </v-btn>
                                </v-list-tile-content>
                                <v-spacer></v-spacer>

                                <v-list-tile-action class="mr-3">
                                    <v-btn @click="sheet = false" icon="icon">
                                        <v-icon>close</v-icon>
                                    </v-btn>
                                </v-list-tile-action>
                            </v-list-tile>
                        </v-list>
                    </v-card>
                </v-bottom-sheet>
            </div>
        </v-layout>
        </v-flex>
        <v-flex ml-1 xs7>
           <v-card>
           <v-card-text class="pt-2 pb-2">

          <v-layout>
              <v-flex xs12>
                  <object :data="rpt_url"
                    width="100%" height="912px"></object>
              </v-flex>
          </v-layout>
          
        </v-card-text>
            </v-card>
        </v-flex>
        </v-layout>
    </template>

<style scoped="scoped">
.notlunas {
color: red;
}
.cito {
color: white;
background-color: #FFC107;
}
.citoo {
color: red;
}

span.xtd {
margin-right: 10px;
}
.searchbox .v-input.v-text-field .v-input__slot {
min-height: 40px;
}
.searchbox .v-btn {
min-height: 40px;
}
table.v-table tbody td,
table.v-table tbody th {
height: 40px;
}

table.v-table thead tr {
height: 40px;
}

.v-messages {
min-height: 0px!important;
}
.cursor_pointer {
cursor: 'pointer'!important;
}
</style>

<script>
        module.exports = {
            components: {
                'one-dialog-info': httpVueLoader('../../common/oneDialogInfo.vue'),
                'one-dialog-alert': httpVueLoader('../../common/oneDialogAlert.vue')
            },
            mounted() {
                //this.$store.dispatch("patient/searchcompany", this.search_company)
                this
                    .$store
                    .dispatch("patient/search", {
                        startdate: this.$store.state.patient.start_date,
                        enddate: this.$store.state.patient.end_date,
                        search: this.searchnamelab,
                        companyid: this.$store.state.patient.selected_company.id,
                        current_page: 1,
                        lastidx: -1
                    })
            },
            methods: {
                updateAlert_success(val) {
                    this
                        .$store
                        .commit("patient/update_alert_success", val)
                },
                changeUpdateDOB(value) {
                    this.data_patient.M_PatientDOB = value
                },
                saveFormLetter() {
                    var xval = this.data_surat
                    var patients = this.$store.state.patient.patients
                    var idx = _.findIndex(patients, function (o) {
                        return o.T_OrderHeaderID == xval.T_OrderHeaderID
                    })
                    xval.doctorid = this.$store.state.patient.selected_doctor.id
                    xval.search = {
                        startdate: this.$store.state.patient.start_date,
                        enddate: this.$store.state.patient.end_date,
                        search: this.searchnamelab,
                        companyid: this.$store.state.patient.selected_company.id,
                        current_page: this.$store.state.patient.current_page,
                        lastidx: idx
                    }
                    this
                        .$store
                        .dispatch("patient/saveformletter", xval)
                },
                openPrint(item){
                   var xdate = Date.now()
                   this.rpt_url = '/birt/frameset?__report=report/one/lab/rpt_hasil_sk.rptdesign&__format=pdf&username=adhi&PID='+item.xid+'&'+xdate
                },
                opendialogForm(item) {
                    var patients = this.$store.state.patient.patients
                    var idx = _.findIndex(patients, function (o) {
                        return o.T_OrderHeaderID == item.T_OrderHeaderID
                    })
                    this
                        .$store
                        .commit("patient/update_lastidx", idx)
                    this
                        .$store
                        .commit("patient/update_selected_patient", item)
                    this.data_surat = item
                    this.selected_doctor = {id:item.doctor_id,name:item.doctor_name}
                    //console.log({id:item.doctor_id,name:item.doctor_name})
                    this.$store.commit("patient/update_doctors", [{id:item.doctor_id,name:item.doctor_name}])
                    //console.log(this.doctors)
                    this.dialog_form = true
                },
                getTimeline(value) {
                    this.selected_delivery = value
                    console.log(this.selected_delivery)
                    if (value.delivery_type_id === '2') {
                        this
                            .$store
                            .dispatch("patient/gettimelinedelivery", value)
                    }
                },
                changeCbxAll(value) {
                    var arr = _.filter(this.barcodes, function (o) {
                        return o.type === 'barcode' || o.type === 'formulir'
                    })
                    this.indeterminatex = false
                    arr.forEach((el) => {
                        el.chex = value
                    })
                    var selected = _.filter(arr, function (o) {
                        return o.chex;
                    })
                    this.selected_barcode = selected
                },
                checkTop() {
                    var barcodes = _.filter(this.barcodes, function (o) {
                        return o.type === 'barcode' || o.type === 'formulir'
                    })
                    var selected = _.filter(barcodes, function (o) {
                        return o.chex;
                    })
                    this.bar_chx_all = false
                    this.indeterminatex = false
                    if (selected.length > 0 && barcodes.length === selected.length) {
                        this.bar_chx_all = true
                        this.indeterminatex = false
                    }
                    if (selected.length > 0 && barcodes.length > selected.length) {
                        this.bar_chx_all = false
                        this.indeterminatex = true
                    }
                    this.selected_barcode = selected
                    console.log(selected)
                },
                printSingleBarcode(value) {
                    var label = value.T_BarcodeLabBarcode
                    if (value.type === 'barcode') 
                        one_print_barcode_pk(label)
                    if (value.type === 'formulir') 
                        one_print_barcode_formulir(value.id)
                    if (value.type === 'nonlab') 
                        one_print_barcode_amplop_so(value.T_SampleTypeID)
                    if (value.type === 'nonlab_group') 
                        one_print_barcode_amplop_so_group(value.orderid)
                },
                printRobo() {
                    var arr = this.barcodes
                    var xarrtojoin = []
                    _.forEach(arr, function (value) {
                        if (value.type === 'barcode') {
                            xarrtojoin.push(value.T_BarcodeLabBarcode)
                        }
                    })
                    if (xarrtojoin.length > 0) {
                        one_print_robo(xarrtojoin.join(','))
                    }
                },
                printMultipleBarcode() {
                    var arr = this.barcodes
                    var xarrtojoin = []
                    var xformulir = {}
                    _.forEach(arr, function (value) {
                        if (value.chex && value.type === 'barcode') {
                            xarrtojoin.push(value.T_BarcodeLabBarcode)
                        }
                        if (value.chex && value.type === 'formulir') {
                            xformulir = value
                        }
                    })
                    if (xarrtojoin.length > 0) {
                        one_print_barcode_pk(xarrtojoin.join(','))
                    }

                    if (!_.isEmpty(xformulir)) {
                        one_print_barcode_formulir(xformulir.id)
                    }

                },
                openDetails(value) {
                    this.sheet = true
                },
                openBarcode() {
                    this.bar_chx_all = false
                    this.indeterminatex = false
                    this.dialogbarcode = true
                    this.selected_barcode = []
                    this
                        .$store
                        .dispatch("patient/getdatabarcodes", this.selected_patient)
                },
                number_format(val) {
                    return numeral(val).format('0,0');
                },
                notToday(item) {
                    return item.order_date !== moment(new Date()).format('YYYY-MM-DD')
                },
                splittest(inp) {
                    if (inp != '') {
                        let a_test = inp.split(',')
                        let s_test = ''
                        for (let i = 0; i < a_test.length; i++) {
                            let test = a_test[i]
                            let a_cito = test.split('^')
                            s_test += '<span class="xtd '
                            if (a_cito[1] == 'Y') 
                                s_test += 'citoo'
                            s_test += '" >'
                            s_test += a_cito[0] + '</span>'
                        }
                        return s_test
                    } else {
                        return ''
                    }

                },
                formatDate(date) {
                    if (!date) 
                        return null

                    const [year, month, day] = date.split('-')
                    return `${day}-${month}-${year}`
                },
                deFormatedDate(date) {
                    if (!date) 
                        return null

                    const [day, month, year] = date.split('-')
                    return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
                },
                isSelected(p) {
                    return p.T_OrderHeaderID == this.$store.state.patient.selected_patient.T_OrderHeaderID
                },
                isCito(p) {
                    return p.cito == 1
                },
                async searchPatient() {
                    let inp_no = this
                        .searchnamelab

                        this
                        .$store
                        .dispatch("patient/search", {
                            startdate: this.$store.state.patient.start_date,
                            enddate: this.$store.state.patient.end_date,
                            search: inp_no,
                            doctorid: this.$store.state.patient.selected_doctor.id,
                            doctorcode: this.$store.state.patient.selected_doctor.code,
                            companyid: this.$store.state.patient.selected_company.id,
                            current_page: 1,
                            lastidx: -1
                        })
                },
                selectMe(pat) {
                    var patients = this.$store.state.patient.patients
                    var idx = _.findIndex(patients, function (o) {
                        return o.T_OrderHeaderID == pat.T_OrderHeaderID
                    })
                    this
                        .$store
                        .commit("patient/update_lastidx", idx)
                    this
                        .$store
                        .commit("patient/update_selected_patient", pat)
                },
                closeAlertNoPay() {
                    this
                        .$store
                        .commit("patient/update_open_alert_no_pay", false)
                },
                forgetAlertNoPay() {
                    var xval = this.$store.state.payment.types
                    var valpay = 0
                    xval.forEach(function (obj) {
                        obj.leftvalue = 0
                        obj.rightvalue = 0
                    })
                    this
                        .$store
                        .commit("payment/update_total_payment", 0)
                    this
                        .$store
                        .commit("patient/update_open_alert_no_pay", false)
                },
                patientComing(patient) {
                    var prm = patient
                    this
                        .$store
                        .dispatch("patient/lookup_promises", prm)
                },
                doSavePromise() {
                    let arrx = this.$store.state.patient.promises
                    var errors = []
                    arrx.forEach(function (arr, index) {
                        var xDate = moment(arr.xdate, 'DDMMYYYY', true)
                        var isValidDate = xDate.isValid()
                        var xTime = moment(arr.xtime, 'HHmm', true)
                        var isValidTime = xTime.isValid()
                        if (!isValidDate || !isValidTime) {
                            errors.push(arr)
                        } else {
                            arrx[index].xdate = moment(arr.xdate, 'DDMMYYYY').format('DD-MM-YYYY')
                            arrx[index].xtime = moment(arr.xtime, 'HHmm').format('HH:mm')
                        }
                    })

                    this.errors = errors
                    if (errors.length === 0) {
                        var prm = {
                            data: arrx,
                            orderid: this.$store.state.patient.selected_patient.T_OrderHeaderID
                        }

                        prm.search = {
                            startdate: this.$store.state.patient.start_date,
                            enddate: this.$store.state.patient.end_date,
                            search: this.searchnamelab,
                            doctorid: this.$store.state.patient.selected_doctor.id,
                            doctorcode: this.$store.state.patient.selected_doctor.code,
                            companyid: this.$store.state.patient.selected_company.id,
                            current_page: this.$store.state.patient.current_page,
                            lastidx: this.$store.state.patient.lastidx
                        }
                        this
                            .$store
                            .dispatch("patient/savepromises", prm)
                    }

                },
                thr_search_company: _.debounce(function () {
                    this
                        .$store
                        .dispatch("patient/searchcompany", this.search_company)
                }, 2000),
                thr_search_doctor: _.debounce(function () {
                    this
                        .$store
                        .dispatch("patient/searchdoctor", this.search_doctor)
                }, 2000)
            },
            computed: {
                dialog_form: {
                    get() {
                        return this.$store.state.patient.dialog_form
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_dialog_form", val)
                    }
                },
                snackbar: {
                    get() {
                        return this.$store.state.patient.alert_success
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_alert_success", val)
                    }
                },
                msgsnackbar() {
                    return this.$store.state.patient.msg_success
                },
                data_patient: {
                    get() {
                        return this.$store.state.patient.data_patient
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_data_patient", val)
                    }
                },
                show_form_dob: {
                    get() {
                        return this.$store.state.patient.show_form_dob
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_show_form_dob", val)
                    }
                },
                dialog_update_dob: {
                    get() {
                        return this.$store.state.patient.dialog_update_dob
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_dialog_update_dob", val)
                    }
                },
                timeline_delivery: {
                    get() {
                        return this.$store.state.patient.timeline_delivery
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_timeline_delivery", val)
                    }
                },
                dialog_timeline_delivery: {
                    get() {
                        return this.$store.state.patient.dialog_timeline_delivery
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_dialog_timeline_delivery", val)
                    }
                },
                xcompanies() {
                    return this.$store.state.patient.companies
                },
                selected_company: {
                    get() {
                        return this.$store.state.patient.selected_company
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_selected_company", val)
                        this.searchPatient()
                    }
                },
                doctors() {
                    return this.$store.state.patient.doctors
                },
                selected_doctor: {
                    get() {
                        return this.$store.state.patient.selected_doctor
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_selected_doctor", val)
                        //this.searchPatient()
                    }
                },
                filterComputedDateFormattedStart() {
                    return this.formatDate(this.xdatestart)
                },
                filterComputedDateFormattedEnd() {
                    return this.formatDate(this.xdateend)
                },
                xdatestart: {
                    get() {
                        return this.$store.state.patient.start_date
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_start_date", val)
                        this.searchPatient()
                    }
                },
                xdateend: {
                    get() {
                        return this.$store.state.patient.end_date
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_end_date", val)
                        this.searchPatient()
                    }
                },
                dialogbarcode: {
                    get() {
                        return this.$store.state.patient.dialog_barcode
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_dialog_barcode", val)
                    }
                },
                barcodes: {
                    get() {
                        return this.$store.state.patient.barcodes
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_barcodes", val)
                    }
                },
                total_patients_all() {
                    return this.$store.state.patient.total_patients_all
                },
                xpromisedialog: {
                    get() {
                        return this.$store.state.patient.promise_dialog
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_promise_dialog", val)
                    }
                },
                xpromises: {
                    get() {
                        return this.$store.state.patient.promises
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_promises", val)
                    }
                },
                xenddate: {
                    get() {
                        return this.$store.state.patient.end_date
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_end_date", val)
                        this.searchPatient()
                    }
                },
                searchnamelab: {
                    get() {
                        return this.$store.state.patient.search
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_search", val)
                        //this.searchPatient()
                    }
                },
                statuses() {
                    return this.$store.state.patient.statuses
                },
                status: {
                    get() {
                        return this.$store.state.patient.selected_status
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_selected_status", val)
                        this.searchPatient()
                    }
                },
                startDateFormatted() {
                    return this.formatDate(this.xstartdate)
                },
                endDateFormatted() {
                    return this.formatDate(this.xenddate)
                },
                isLoading() {
                    return this.$store.state.patient.search_status == 1
                },
                patients() {
                    return this.$store.state.patient.patients
                },
                selected_patient: {
                    get() {
                        let sp = this.$store.state.patient.selected_patient
                        if (sp == undefined) 
                            return {}
                        if (!sp.hasOwnProperty('T_OrderHeaderLabNumber')) {
                            sp["T_OrderHeaderLabNumber"] = ""
                            sp["M_PatientName"] = ""
                        }
                        return sp
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_selected_patient", val)
                    }
                },
                openalertnopay: {
                    get() {
                        return this.$store.state.patient.open_alert_no_pay
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_open_alert_no_pay", false)
                    }
                },
                msgalertnopay() {
                    return this.$store.state.patient.msg_alert_no_pay
                },
                curr_page: {
                    get() {
                        return this.$store.state.patient.current_page
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_current_page", val)
                        this
                            .$store
                            .dispatch("patient/search", {
                                startdate: this.$store.state.patient.start_date,
                                enddate: this.$store.state.patient.end_date,
                                search: this.searchnamelab,
                                search: this.searchnamelab,
                                doctorid: this.$store.state.patient.selected_doctor.id,
                                companyid: this.$store.state.patient.selected_company.id,
                                current_page: val,
                                lastidx: -1
                            })
                    }
                },
                xtotal_page: {
                    get() {
                        return this.$store.state.patient.total_page
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_total_page", val)
                    }
                },

                xtotal_patients: {
                    get() {
                        return this.$store.state.patient.total_patient
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_total_patient", val)
                    }
                },

                xtotalpatients() {
                    return this.$store.state.patient.total_patients
                },
                xtotalfilterpatients() {
                    return this.$store.state.patient.total_filter_patients
                },
                filters: {
                    get() {
                        return this.$store.state.patient.filters
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_filters", val)
                    }
                },
                selected_filter: {
                    get() {
                        return this.$store.state.patient.selected_filter
                    },
                    set(val) {
                        this
                            .$store
                            .commit("patient/update_selected_filter", val)
                        this.searchPatient()
                    }
                }
            },
            watch: {
                search_company(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.thr_search_company();
                },
                search_doctor(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.thr_search_doctor();
                }
            },
            data() {
                return {
                   rpt_url:'',
                    data_surat: {},
                    selected_delivery: {},
                    search_company: '',
                    menufilterdatestart: false,
                    menufilterdateend: false,
                    date: new Date()
                        .toISOString()
                        .substr(0, 10),
                    items: [],
                    menustartdate: false,
                    menuenddate: false,
                    errors: [],
                    sheet: false,
                    indeterminatex: false,
                    checkednotall: false,
                    bar_chx_all: false,
                    selected_barcode: [],
                    dialogtimeline: false,
                    search_doctor: '',
                    headers: [
                        {
                            text: "NO REG",
                            align: "left",
                            sortable: false,
                            value: "lab",
                            width: "8%",
                            class: "pa-2 blue lighten-3 white--text"
                        }, {
                            text: "NAMA",
                            align: "left",
                            sortable: false,
                            value: "name",
                            width: "45%",
                            class: "pa-2 blue lighten-3 white--text"
                        }, {
                            text: "AKSI",
                            align: "center",
                            sortable: false,
                            value: "name",
                            width: "15%",
                            class: "pa-2 blue lighten-3 white--text"
                        }
                    ]
                }
            }
        }
    </script>