<template>
    <v-layout v-if="xact !== 'new'" column>
        <v-dialog v-model="dialogconfirmationdeletepat" persistent max-width="290">
            <v-card>
                <v-card-title dark class="headline error pt-2 pb-2" primary-title style="color:white">
                    <h4 dark>Konfirmasi</h4>
                </v-card-title>
                <v-card-text>
                    {{msgconfirmationdeletepat}}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn small color="error darken-1 text-sm-left" flat @click="doDeletePat()">Hapus</v-btn>
                    <v-btn small color="primary darken-1 text-sm-right" flat @click="dialogconfirmationdeletepat = false">Batal</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-dialog v-model="dialogchooseprint" persistent max-width="20%">
            <v-card>
                <v-card-title class="headline white--text grey darken-1 pt-2 pb-2" primary-title style="color:white">
                    <h4>Pilih Format Laporan</h4>
                </v-card-title>
                <v-card-text class="pt-2 pb-2">
                    <v-layout row>
                        <v-flex xs12 d-flex>
                            <v-layout row>
                                <v-flex pb-1 xs12>
                                    <v-layout row>
                                        <v-flex pt-2 pr-2 xs12>
                                            <v-radio-group v-model="formatreport" row>
                                                <v-radio color="grey" label="PDF" value="pdf"></v-radio>
                                                <v-radio color="grey" label="EXCEL" value="xls"></v-radio>
                                            </v-radio-group>
                                        </v-flex>
                                    </v-layout>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                    </v-layout>
                </v-card-text>
                <v-divider></v-divider>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="black" flat @click="dialogchooseprint = false">
                        Tutup
                    </v-btn>
                    <v-btn color="grey" flat @click="doPrint()">
                        Cetak
                    </v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-dialog v-model="dialogconfirmationsend" persistent max-width="290">
            <v-card>
                <v-card-title dark class="headline success pt-2 pb-2" primary-title style="color:white">
                    <h4 dark>Konfirmasi</h4>
                </v-card-title>
                <v-card-text>
                    {{msgconfirmationsend}}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn small color="success darken-1 text-sm-left" flat @click="doOrderNilaiNormal()">Kirim</v-btn>
                    <v-btn small color="primary darken-1 text-sm-right" flat @click="dialogconfirmationsend = false">Batal</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-dialog v-model="dialogformnilainormal" persistent max-width="650">
            <v-card>
                <v-card-title>
                    <span class="headline">Form Nilai Normal</span>
                </v-card-title>
                <v-card-text class="pt-0 pb-0">
                    <v-layout wrap>
                        <v-flex xs12>
                            <v-checkbox v-model="isabnormal" label="Abnormal"></v-checkbox>
                        </v-flex>
                        <v-flex xs12>
                            <v-layout>
                                <v-flex xs6 pa-1>
                                    <v-autocomplete label="Metode" v-model="methode" :items="xmethodes" :search-input.sync="search_methode" auto-select-first
                                        no-filter item-text="Nat_MethodeName" return-object :loading="isLoading" no-data-text="Pilih Metode">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.Nat_MethodeName"></v-list-tile-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <p v-if="checkError('requirexmethode')" class="error pl-2 pr-2" style="color:#fff">Pilih Metode</p>
                                </v-flex>
                                <v-flex xs6 pa-1>
                                    <v-select item-text="Nat_NormalValueTypeName" return-object :items="xnormalvaluetypees" v-model="xnormalvaluetype" label="Tipe*"></v-select>
                                    <p v-if="checkError('requirexnormalvaluetype')" class="error pl-2 pr-2" style="color:#fff">Pilih tipe</p>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                        <v-flex xs12>
                        <v-layout>
                                <v-flex xs6 pa-1>
                            <v-menu ref="menuvaliddate" v-model="menuvaliddate" :close-on-content-click="false" :nudge-right="0" lazy transition="scale-transition"
                                offset-y full-width max-width="290px" min-width="290px">
                                <template v-slot:activator="{ on }">
                                    <v-text-field v-model="validComputedDateFormatted" label="Tgl. Valid" readonly v-on="on" @blur="date = deFormatedDate(validComputedDateFormatted)"></v-text-field>
                                </template>
                                <v-date-picker v-model="xvaliddate" no-title @input="menuvaliddate = false"></v-date-picker>
                         </v-flex>
                         <v-flex xs6 pa-1>
                         <v-select v-if="this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 1 || this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 3" item-text="Nat_SexName" return-object :items="xsexes" v-model="xsex" label="Jenis Kelamin*"></v-select>
                            <p v-if="checkError('requirexsex')" class="error pl-2 pr-2" style="color:#fff">Pilih jenis kelamin dulu dong</p>
                        </v-flex>
                            </v-layout>
                        </v-flex>

                            
                        <v-flex xs12>
                            <v-layout>
                                <v-flex xs3 pa-1>
                                    <v-text-field v-if="this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 1 || this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 2" v-model="xminage" label="Min Age"></v-text-field>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                    <v-text-field v-if="this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 1 || this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID ==2" v-model="xmaxage" label="Max Age"></v-text-field>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                    <v-checkbox v-if="this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 1 || this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 2" v-model="isminageinclusive" label="Min Inclusive"></v-checkbox>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                    <v-checkbox v-if="this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 1 || this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 2" v-model="ismaxageinclusive" label="Max Inclusive"></v-checkbox>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                    <v-select v-if="this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 1 || this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID == 2" item-text="Nat_AgeUnitName" return-object :items="xageunites" v-model="xageunit" label="Satuan Umur"></v-select>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                        <v-flex xs12>
                            <v-layout>
                                <v-flex xs3 pa-1>
                                    <v-text-field v-model="xminvalue" label="Min Value"></v-text-field>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                    <v-text-field v-model="xmaxvalue" label="Max Value"></v-text-field>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                    <v-checkbox v-model="isminvalueinclusive" label="Min Inclusive"></v-checkbox>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                    <v-checkbox v-model="ismaxvalueinclusive" label="Max Inclusive"></v-checkbox>
                                </v-flex>
                                <v-flex xs3 pa-1>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                        <v-flex xs12>
                            <v-layout>
                                <v-flex xs6 pa-1>
                                    <v-textarea label="Catatan" v-model="xnote"></v-textarea>
                                </v-flex>
                                <v-flex xs6 pa-1>
                                    <v-textarea label="Deskripsi" v-model="xdescription"></v-textarea>
                                </v-flex>
                            </v-layout>

                        </v-flex>
                    </v-layout>
                    <v-divider></v-divider>

                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="blue darken-1" flat @click="dialogformnilainormal = false">Tutup</v-btn>
                    <v-btn v-if="xactpat === 'new'" color="blue darken-1" flat @click="saveNewNilaiNormal()">Simpan</v-btn>
                    <v-btn v-if="xactpat === 'edit'" color="blue darken-1" flat @click="saveEditNilaiNormal()">Simpan</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-card>
            <v-layout row>
                <v-flex xs12>

                    <v-divider></v-divider>
                    <v-card class="mb-2 pa-2 searchbox">
                        <v-subheader red--text text--lighten-1> DAFTAR NILAI NORMAL
                            <v-layout><span @click="createNewNilaiNormal" class="icon-medium-fill-base xs1 white--text primary  ml-1 icon-add"></span>
                            <span @click="openprintformat" class="icon-medium-fill-base xs1 white--text grey darken-1  ml-1 icon-print"></span>
                        </v-subheader>
                        </v-layout>
                    </v-card>
                    <v-layout>
                        <v-flex xs12>
                            <v-card class="mb-2" color="white">
                                <v-layout row wrap>
                                    <v-flex class="border-bottom-dashed" xs12 pt-2 pl-4 pr-4 pb-4>
                                        <div class="rTable">
                                            <div class="rTableHeading">
                                                <div style="width:5%" class="rTableHead">ABNORMAL</div>
                                                <div style="width:15%" class="rTableHead">METODE</div>
                                                <div style="width:15%" class="rTableHead">TIPE</div>
                                                <div style="width:10%" class="rTableHead">SEX</div>
                                                <div style="width:15%" class="rTableHead">AGE RANGE</div>
                                                <div style="width:10%" class="rTableHead">VALUE RANGE</div>
                                                <div style="width:10%" class="rTableHead">AKSI</div>
                                            </div>
                                        </div>
                                        <div v-if="xnilainormals.length === 0" class="rTable pt-2">
                                            <div class="rTableRow">
                                                <div style="width:100%;text-align:center" class="rTableCell">Belum ada data</div>
                                            </div>
                                        </div>
                                        <div v-if="xnilainormals.length > 0" v-for="(vo,idx) in xnilainormals" :key="vo.Nat_NormalValueID">
                                            <div class="rTable">
                                                <div class="rTableGroup">
                                                    <div class="rTableRow">
                                                        <div style="width:5%" class="rTableCell rfirstCell">{{vo.Nat_NormalValueIsAbnormal}}</div>
                                                        <div style="width:15%" class="rTableCell">{{vo.Nat_MethodeName}}</div>
                                                        <div style="width:15%" class="rTableCell">{{vo.Nat_NormalValueTypeName}}</div>
                                                        <div style="width:10%" class="rTableCell">{{vo.Nat_SexName}}</div>
                                                        <div style="width:15%" class="rTableCell">{{vo.Nat_NormalValueAge}}</div>
                                                        <div style="width:10%" class="rTableCell">{{vo.Nat_NormalValueValue}}</div>
                                                        <div style="width:10%" class="rTableCell">

                                                            <v-icon style="color:#757575" @click="editNilaiNormal(vo)">edit</v-icon>
                                                            <v-icon style="color:#757575" @click="deleteNilaiNormal(vo)">clear</v-icon>
                                                            <v-icon v-if="vo.show_detail === 'N'" style="color:#757575" class="text-sm-right" @click="showDetail(idx)">more_vert</v-icon>
                                                            <v-icon v-if="vo.show_detail === 'Y'" style="color:#757575" class="text-sm-right" @click="hideDetail(idx)">more_vert</v-icon>
                                                            <v-icon v-if="vo.show_detail === 'Y'" style="color:#757575" @click="simpanLang(idx)">save</v-icon>
                                                        </div>
                                                    </div>
                                                </div>
                                                <transition name="fade">
                                                    <div v-if="vo.show_detail === 'Y'" style="width:100%;border:1px solid black" class="caption">
                                                        <v-layout row>
                                                            <table>
                                                                <tr>
                                                                    <th class="text-md-center pt-2 pb-2">BAHASA</th>
                                                                    <th class="text-md-center pt-2 pb-2">CATATAN</th>
                                                                    <th class="text-md-center pt-2 pb-2">CATATAN SI</th>
                                                                    <th class="text-md-center pt-2 pb-2">DESKRIPSI</th>
                                                                    <th class="text-md-center pt-2 pb-2">DESKRIPSI SI</th>

                                                                </tr>
                                                                <tr v-for="(vt,tidx) in vo.tests" :key="vt.Nat_NormalValueLangID">
                                                                    <td class="text-md-left pl-3">
                                                                        <v-text-field style="margin-top:0;padidng-top:0" v-model="vt.Nat_LangName" hide-details></v-text-field>
                                                                    </td>
                                                                    <td class="text-md-right pr-2">
                                                                    <v-textarea v-model="vt.Nat_NormalValueLangNote" hide-details></v-textarea>
                                                                    </td>
                                                                    <td class="text-md-right pr-2">
                                                                    <v-textarea v-model="vt.Nat_NormalValueLangNoteSI" hide-details></v-textarea>
                                                                    </td>
                                                                    <td class="text-md-right pr-2">
                                                                    <v-textarea v-model="vt.Nat_NormalValueLangDescription" hide-details></v-textarea>
                                                                    </td>
                                                                    <td class="text-md-right pr-2">
                                                                    <v-textarea v-model="vt.Nat_NormalValueLangDescriptionSI" hide-details></v-textarea>
                                                                    </td>

                                                                </tr>

                                                                <!--<tfoot>
                            <tr>
                                <th style="background:#03a9f43d" colspan="3" class="text-md-right pr-2 pt-1 pb-1">SUB TOTAL</th>
                                <th style="background:#03a9f43d" class="text-md-right pr-2 pt-2 pb-2" colspan="2">300.000</th>

                            </tr>
                            <tr>
                                <th colspan="3"  class="text-md-right pr-2 pt-1 pb-1">DISKON PEMBULATAN</th>
                                <th class="text-md-right pr-2 pt-1 pb-1"  colspan="2">0</th>

                            </tr>
                            <tr>
                                <th style="background:#03a9f43d" colspan="3"  class="text-md-right pr-2 pt-2 pb-2">TOTAL</th>
                                <th style="background:#03a9f43d" class="text-md-right pr-2 pt-1 pb-1"  colspan="2">300.000</th>

                            </tr>
                            </tfoot>-->
                                                            </table>
                                                        </v-layout>
                                                    </div>
                                                </transition>
                                            </div>
                                        </div>

                                    </v-flex>
                                </v-layout>
                            </v-card>
                        </v-flex>
                    </v-layout>

                    <v-layout row wrap>
                        <!--  <v-flex xs12 pa-2>
                            Keterangan :
                            <v-btn @click="" small color="grey"></v-btn> Baru
                            <v-btn @click="" small color="yellow"></v-btn> Proses
                            <v-btn @click="" small color="green"></v-btn> Selesai
                        </v-flex>
                        -->
                    </v-layout>

                </v-flex>
                </v-flex>
        </v-card>
        <one-dialog-print :title="printtitle" :width="printwidth" :height="500" :status="openprint" :urlprint="urlprint" @close-dialog-print="closePrint"></one-dialog-print>
        </v-layout>
</template>

<style scoped>
    .fade-enter-active,
    .fade-leave-active {
        transition: opacity .5s;
    }

    .fade-enter,
    .fade-leave-to {
        opacity: 0;
    }

    .bounce-enter-active {
        animation: bounce-in .5s;
    }

    .bounce-leave-active {
        animation: bounce-in .5s reverse;
    }

    @keyframes bounce-in {
        0% {
            transform: scale(0);
        }
        25% {
            transform: scale(.50);
        }
        50% {
            transform: scale(.75);
        }
        75% {
            transform: scale(1.1);
        }
        100% {
            transform: scale(1);
        }
    }

    .rTable {
        display: table;
        width: 100%;
        border-spacing: 0 .2em;
    }

    .rTableGroup {
        display: table-row-group;
    }

    .rTableRow {
        display: table-row;
        font-size: 14px;
        -webkit-flex-wrap: wrap;
        /* Safari 6.1+ */
        flex-wrap: wrap;

    }

    .rTableHeading {
        display: table-header-group;
        background-color: #fffff;
    }

    .rTableCell {
        display: table-cell;
        padding-left: 10px;
        padding-right: 10px;
        padding-top: 5px;
        padding-bottom: 5px;
        line-height: 2;
        border: 1px solid #2196f3;
        background-color: #fffff;
        border-spacing: 5px;
    }

    .rTableHead {
        display: table-cell;
        padding-left: 10px;
        padding-right: 10px;
        padding-top: 10px;
        padding-bottom: 0px;
        background-color: #fffff;
    }

    .rTableHeading {
        display: table-header-group;
        text-transform: uppercase;
        font-weight: 500;
    }

    .rTableFoot {
        display: table-footer-group;
        font-weight: bold;
        background-color: #ddd;
    }

    .rTableBody {
        display: table-row-group;
    }

    .rfirstCell {
        border-left: 10px solid #2196f3;
        border-top-left-radius: 3px;
        border-bottom-left-radius: 3px;
    }

    .caption {
        border: 1px solid grey;
        caption-side: bottom;
        display: table-caption;
        text-align: center;
        padding: 5px
    }

    .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;
    }

    .text-fajrihm {
        padding: 3px 20px 3px 0;
        text-align: left;
        font-size: 13px;
        font-family: open sans, tahoma, sans-serif;
    }

    .label-delivery {
        font-size: 11px;
        padding: 3px 10px 3px 0;
        font-family: open sans, tahoma, sans-serif;
    }

    .text-delivery {
        font-size: 12px;
        padding: 3px 10px 3px 0;
        font-family: open sans, tahoma, sans-serif;
    }

    .nota {
        font-size: 2em;
        font-weight: bold;
        text-align: left;
    }

    .total {
        min-height: 76px;
    }

    table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;
        background: white;
        border: 0px;
    }

    th,
    td {
        border: 1px solid black;
        border-collapse: collapse;
        padding-top: 2px;
        padding-bottom: 2px;
    }

    table>tr>td {
        padding: 8px;
    }

    table>tr>td:first {
        padding-left: 15px !important;
    }

    .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;
    }

    .border-bottom-dashed {
        border-bottom: 1px dashed rgba(0, 0, 0, .12);
    }

    .v-breadcrumbs__item {
        color: #fff !important;
    }
</style>

<script>
    module.exports = {
        components: {
            'one-dialog-print': httpVueLoader('../../common/oneDialogPrintX.vue')
        },
        data: () => ({
            oldlabel: '',
            search_test: '',
            dialog: false,
            urlprintnote: '',
            printtitle: '',
            printwidth: 600,
            xid: 0,
            validdate: "",
            menuvaliddate: false,
            isabnormal: "",
            isminageinclusive: "",
            ismaxageinclusive: "",
            isminvalueinclusive: "",
            ismaxvalueinclusive: "",
            search_methode: '',
            dialogchooseprint: false,
                openprint: false,
                urlprint: '',
                printtitle: '',
                printwidth: 600,
                formatreport: 'pdf',
            headers: [

                {
                    text: "NAMA",
                    align: "left",
                    sortable: false,
                    value: "mr",
                    width: "15%",
                    class: "pa-1 blue lighten-3 white--text"
                },
                {
                    text: "NO. REFERENSI",
                    align: "left",
                    sortable: false,
                    value: "lab",
                    width: "3%",
                    class: "pa-1 blue lighten-3 white--text"
                },
                {
                    text: "TGL. LAHIR",
                    align: "left",
                    sortable: false,
                    value: "lab",
                    width: "10%",
                    class: "pa-1 blue lighten-3 white--text"
                },
                {
                    text: "PEMERIKSAAN",
                    align: "left",
                    sortable: false,
                    value: "lab",
                    width: "10%",
                    class: "pa-1 blue lighten-3 white--text"
                },
                {
                    text: "TOTAL",
                    align: "left",
                    sortable: false,
                    value: "lab",
                    width: "15%",
                    class: "pa-1 blue lighten-3 white--text"
                },
                {
                    text: "AKSI",
                    align: "center",
                    sortable: false,
                    value: "action",
                    width: "10%",
                    class: "pa-1 blue lighten-3 white--text"
                }
            ]
        }),
        computed: {
            validComputedDateFormatted() {
                return this.formatDate(this.xvaliddate)
            },
            xvaliddate: {
                get() {
                    return this.$store.state.normalvalue.validdate
                },
                set(val) {
                    this.$store.commit("normalvalue/update_validdate", val)
                }
            },
            dialogconfirmationdeletepat: {
                get() {
                    return this.$store.state.normalvalue.dialog_confirmation_delete_pat
                },
                set(val) {
                    this.$store.commit("normalvalue/update_dialog_confirmation_delete_pat", val)
                }
            },
            msgconfirmationdeletepat() {
                return this.$store.state.normalvalue.msg_confirmation_delete_pat
            },
            dialogconfirmationsend: {
                get() {
                    return this.$store.state.normalvalue.dialog_confirmation_send
                },
                set(val) {
                    this.$store.commit("normalvalue/update_dialog_confirmation_send", val)
                }
            },
            msgconfirmationsend() {
                return this.$store.state.normalvalue.msg_confirmation_send
            },
            xact() {
                return this.$store.state.normalvalue.act
            },
            xactpat() {
                return this.$store.state.normalvalue.act_pat
            },
            xactsend() {
                return this.$store.state.normalvalue.act_send
            },

            dialogformnilainormal: {
                get() {
                    return this.$store.state.normalvalue.dialog_form_nilainormal
                },
                set(val) {
                    this.$store.commit("normalvalue/update_dialog_form_nilainormal", val)
                }
            },
            isLoading() {
                return this.$store.state.normalvalue.search_status == 1
            },
            xnilainormals(p) {
                return this.$store.state.normalvalue.nilainormals
            },
            xnoref: {
                get() {
                    return this.$store.state.normalvalue.noref
                },
                set(val) {
                    this.$store.commit("normalvalue/update_noref", val)
                }
            },
            namapasien: {
                get() {
                    return this.$store.state.normalvalue.namapasien
                },
                set(val) {
                    this.$store.commit("normalvalue/update_nama_pasien", val)
                }
            },
            xminage: {
                get() {
                    return this.$store.state.normalvalue.minage
                },
                set(val) {
                    this.$store.commit("normalvalue/update_minage", val)
                }
            },
            xmaxage: {
                get() {
                    return this.$store.state.normalvalue.maxage
                },
                set(val) {
                    this.$store.commit("normalvalue/update_maxage", val)
                }
            },
            xminvalue: {
                get() {
                    return this.$store.state.normalvalue.minvalue
                },
                set(val) {
                    this.$store.commit("normalvalue/update_minvalue", val)
                }
            },
            xmaxvalue: {
                get() {
                    return this.$store.state.normalvalue.maxvalue
                },
                set(val) {
                    this.$store.commit("normalvalue/update_maxvalue", val)
                }
            },
            xageunites() {
                return this.$store.state.normalvalue.ageunites
            },
            xageunit: {
                get() {
                    return this.$store.state.normalvalue.selected_ageunit
                },
                set(val) {
                    this.$store.commit("normalvalue/update_selected_ageunit", val)
                }
            },
            xnote: {
                get() {
                    return this.$store.state.normalvalue.note
                },
                set(val) {
                    this.$store.commit("normalvalue/update_note", val)
                }
            },
            xdescription: {
                get() {
                    return this.$store.state.normalvalue.description
                },
                set(val) {
                    this.$store.commit("normalvalue/update_description", val)
                }
            },
            xsexes() {
                return this.$store.state.normalvalue.sexes
            },
            xsex: {
                get() {
                    return this.$store.state.normalvalue.selected_sex
                },
                set(val) {
                    this.$store.commit("normalvalue/update_selected_sex", val)
                }
            },
            xmethodes() {
                return this.$store.state.normalvalue.methodes
            },
            methode: {
                get() {
                    return this.$store.state.normalvalue.methode
                },
                set(val) {
                    this.$store.commit("normalvalue/update_methode", val)
                }
            },
            xnormalvaluetypees() {
                return this.$store.state.normalvalue.normalvaluetypees
            },
            xnormalvaluetype: {
                get() {
                    return this.$store.state.normalvalue.selected_normalvaluetype
                },
                set(val) {
                    this.$store.commit("normalvalue/update_selected_normalvaluetype", val)
                }
            },
            xflages() {
                return this.$store.state.normalvalue.flages
            },
            xflag: {
                get() {
                    return this.$store.state.normalvalue.selected_flag
                },
                set(val) {
                    this.$store.commit("normalvalue/update_selected_flag", val)
                }
            },
            xorderautotests() {
                return this.$store.state.normalvalue.orderautotests
            },
            xorderautotest: {
                get() {
                    return this.$store.state.normalvalue.orderautotest
                },
                set(val) {
                    this.$store.commit("normalvalue/update_orderautotest", val)
                }
            },
            xordertests() {
                return this.$store.state.normalvalue.ordertests
            },
            sub_total() {
                let tests = this.xordertests
                sub_total = 0
                tests.forEach(function (vpx, idx) {
                    let total = parseInt(vpx.total)
                    sub_total = sub_total + total
                })
                return sub_total
            },
            dp() {
                let mindp = this.$store.state.normalvalue.selected_normalvalue.Nat_TestMinDP
                let dp = mindp / 100 * this.sub_total
                return dp
            },
            isbill() {
                let isbill = this.$store.state.normalvalue.selected_normalvalue.Nat_TestIsBill
                return isbill
            },
            openprintnote: {
                get() {
                    return this.$store.state.normalvalue.open_print_note
                },
                set(val) {
                    this.$store.commit("normalvalue/update_open_print_note", false)
                }
            }
        },
        methods: {
            createNewNilaiNormal() {
                this.xid = 0
                this.validdate = ''
                this.xminage = ''
                this.xmaxage = ''
                this.xminvalue = ''
                this.xmaxvalue = ''
                this.xnote = ''
                this.xdescription = ''
                this.search_methode = ''
                this.isabnormal = ''
                this.isminageinclusive = ''
                this.ismaxageinclusive = ''
                this.isminvalueinclusive = ''
                this.ismaxvalueinclusive = ''
                this.$store.commit("normalvalue/update_methodes", [])
                this.methode = {}
                this.$store.commit("normalvalue/update_act_pat", 'new')
                this.$store.commit("normalvalue/update_dialog_form_nilainormal", true)
            },
            saveNewNilaiNormal() {
                this.$store.commit("normalvalue/update_errors", [])
                var errors = this.$store.state.normalvalue.errors
                if (_.isEmpty(this.xmethodes)) {
                    errors.push("requirexmethode")
                }
                if (_.isEmpty(this.xnormalvaluetype)) {
                    errors.push("requirexnormalvaluetype")
                }
                if (errors.length === 0) {
                    var prm = {}
                    prm.Nat_NormalValueNat_TestID = this.$store.state.normalvalue
                        .selected_normalvalue
                        .Nat_TestID
                    prm.Nat_TestName = this.$store.state.normalvalue.selected_normalvalue.Nat_TestName
                    prm.Nat_NormalValueNat_MethodeID = this.methode.Nat_MethodeID,
                    prm.Nat_NormalValueNat_NormalValueTypeID = this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID
                    prm.Nat_NormalValueNat_FlagID = this.$store.state.normalvalue.selected_flag.Nat_FlagID
                    prm.Nat_NormalValueValidDate = this.xvaliddate
                    prm.Nat_NormalValueMinAge = this.xminage
                    prm.Nat_NormalValueMaxAge = this.xmaxage
                    prm.Nat_NormalValueMinAgeInclusive = this.isminageinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueMaxAgeInclusive = this.ismaxageinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueAgeUnit = this.$store.state.normalvalue.selected_ageunit.Nat_AgeUnitName
                    prm.Nat_NormalValueNat_SexID = this.$store.state.normalvalue.selected_sex.Nat_SexID
                    prm.Nat_NormalValueNote = this.xnote
                    prm.Nat_NormalValueMinValue = this.xminvalue
                    prm.Nat_NormalValueMaxValue = this.xmaxvalue
                    prm.Nat_NormalValueMinValueInclusive = this.isminvalueinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueMaxValueInclusive = this.ismaxvalueinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueDescription = this.xdescription
                    prm.Nat_NormalValueIsAbnormal = this.isabnormal === true ?"Y":"N" 
                    this.$store.dispatch("normalvalue/savenewnilainormal", prm)
                }
            },
            thr_search_methode: _.debounce(function () {
                this.$store.dispatch("normalvalue/searchmethode", this.search_methode)
            }, 2000),
            checkError(value) {
                var errors = this.$store.state.normalvalue.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            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')}`
            },
            printNote(val, idx) {
                this.printwidth = 600
                this.printtitle = ""
                let user = one_user()
                var rpt = 'rpt_t_003'
                if (val.note_amount < 0)
                    rpt = 'rpt_t_004'
                this.urlprintnote = "/birt/run?__report=report/one/fo/" + rpt + ".rptdesign&__format=pdf&username=" +
                    user.M_UserUsername + "&PID=" + val.note_id
                this.$store.commit("normalvalue/update_open_print_note", true)
            },          
            showDetailold(value) {
                var arrOrders = this.$store.state.normalvalue.ordertests
                arrOrders[value].show_detail = arrOrders[value].show_detail === 'Y' ? 'N' : 'Y'

                this.$store.commit("normalvalue/update_act_pat", 'edit')
                this.$store.commit("normalvalue/update_x_pat_id", value.Nat_NormalValueID)
                this.$store.commit("normalvalue/update_ordertests", value.tests)
            },
            showDetail(idx) {
                var arrOrders = this.$store.state.normalvalue.nilainormals
                arrOrders[idx].show_detail = arrOrders[idx].show_detail === 'Y' ? 'N' : 'Y'
                this.$store.commit("normalvalue/update_ordertests", arrOrders)
            },
            hideDetail(idx) {
                var arrOrders = this.$store.state.normalvalue.nilainormals

                arrOrders[idx].show_detail = arrOrders[idx].show_detail === 'Y' ? 'N' : 'Y'
                this.$store.commit("normalvalue/update_ordertests", arrOrders)
            },
            simpanLang(idx) {
                var arrOrders = this.$store.state.normalvalue.nilainormals
                var prm = {}
                prm.normalvalueid = arrOrders[idx].Nat_NormalValueID
                prm.ordertests = arrOrders[idx].tests
                this.$store.dispatch("normalvalue/savenormalvaluelang", prm)
            },
            editNilaiNormal(value) {
                this.xid = value.Nat_NormalValueID
                this.$store.commit("normalvalue/update_act_pat", 'edit')
                this.$store.commit("normalvalue/update_x_pat_id", value.Nat_NormalValueID)
                this.xminage = value.Nat_NormalValueMinAge
                this.xmaxage = value.Nat_NormalValueMaxAge
                this.xminvalue = value.Nat_NormalValueMinValue
                this.xmaxvalue = value.Nat_NormalValueMaxValue
                this.xnote = value.Nat_NormalValueNote
                this.xdescription = value.Nat_NormalValueDescription
                this.isabnormal = value.Nat_NormalValueIsAbnormal === 'N' ? false : true
                this.isminageinclusive = value.Nat_NormalValueMinAgeInclusive === 'N' ? false : true
                this.ismaxageinclusive = value.Nat_NormalValueMaxAgeInclusive === 'N' ? false : true
                this.isminvalueinclusive = value.Nat_NormalValueMinValueInclusive === 'N' ? false : true
                this.ismaxvalueinclusive = value.Nat_NormalValueMaxValueInclusive === 'N' ? false : true
                this.$store.commit("normalvalue/update_methodes", [{
                    Nat_MethodeID: value.Nat_MethodeID,
                    Nat_MethodeName: value.Nat_MethodeName
                }])
                this.methode = {
                    Nat_MethodeID: value.Nat_MethodeID,
                    Nat_MethodeName: value.Nat_MethodeName
                }
                this.$store.commit("normalvalue/update_selected_normalvaluetype", {
                    Nat_NormalValueTypeID: value.Nat_NormalValueTypeID,
                    Nat_NormalValueTypeName: value.Nat_NormalValueTypeName
                })
                this.$store.commit("normalvalue/update_selected_flag", {
                    Nat_FlagID: value.Nat_FlagID,
                    Nat_FlagName: value.Nat_FlagName
                })
                this.$store.commit("normalvalue/update_selected_ageunit", {
                    Nat_AgeUnitID: value.Nat_NormalValueAgeUnit,
                    Nat_AgeUnitName: value.Nat_NormalValueAgeUnit
                })
                this.$store.commit("normalvalue/update_selected_sex", {
                    Nat_SexID: value.Nat_SexID,
                    Nat_SexName: value.Nat_SexName
                })
                this.validdate = value.Nat_NormalValueValidDate
                this.$store.commit("normalvalue/update_validdate", value.Nat_NormalValueValidDate)
                this.$store.commit("normalvalue/update_ordertests", value.tests)
                this.$store.commit("normalvalue/update_dialog_form_nilainormal", true)
            },
            saveEditNilaiNormal() {
                this.$store.commit("normalvalue/update_errors", [])
                var errors = this.$store.state.normalvalue.errors
                if (_.isEmpty(this.xsex)) {
                    errors.push("requirexsex")
                }
                if (_.isEmpty(this.xmethodes)) {
                    errors.push("requirexmethode")
                }
                if (_.isEmpty(this.xnormalvaluetype)) {
                    errors.push("requirexnormalvaluetype")
                }
                if (_.isEmpty(this.xflag)) {
                    errors.push("requirexflag")
                }
                if (errors.length === 0) {
                    var prm = {}
                    prm.Nat_NormalValueID = this.xid
                    prm.Nat_NormalValueNat_TestID = this.$store.state.normalvalue
                        .selected_normalvalue
                        .Nat_TestID
                    prm.Nat_TestName = this.$store.state.normalvalue.selected_normalvalue.Nat_TestName
                    prm.Nat_NormalValueNat_MethodeID = this.methode.Nat_MethodeID,
                    prm.Nat_NormalValueNat_NormalValueTypeID = this.$store.state.normalvalue.selected_normalvaluetype.Nat_NormalValueTypeID
                    prm.Nat_NormalValueNat_FlagID = this.$store.state.normalvalue.selected_flag.Nat_FlagID
                    prm.Nat_NormalValueValidDate = this.xvaliddate
                    prm.Nat_NormalValueMinAge = this.xminage
                    prm.Nat_NormalValueMaxAge = this.xmaxage
                    prm.Nat_NormalValueMinAgeInclusive = this.isminageinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueMaxAgeInclusive = this.ismaxageinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueAgeUnit = this.$store.state.normalvalue.selected_ageunit.Nat_AgeUnitName
                    prm.Nat_NormalValueNat_SexID = this.$store.state.normalvalue.selected_sex.Nat_SexID
                    prm.Nat_NormalValueNote = this.xnote
                    prm.Nat_NormalValueMinValue = this.xminvalue
                    prm.Nat_NormalValueMaxValue = this.xmaxvalue
                    prm.Nat_NormalValueMinValueInclusive = this.isminvalueinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueMaxValueInclusive = this.ismaxvalueinclusive === true ?"Y":"N"
                    prm.Nat_NormalValueDescription = this.xdescription
                    prm.Nat_NormalValueIsAbnormal = this.isabnormal === true ?"Y":"N" 
                    this.$store.dispatch("normalvalue/saveeditnilainormal", prm)
                }
            },
            thr_search_test: _.debounce(function () {
                this.$store.dispatch("normalvalue/searchtest", {
                    tes: this.search_test,
                    mouid: this.$store.state.normalvalue.selected_normalvalue
                        .Nat_TestM_MouID
                })
            }, 2000),
            deleteNilaiNormal(value) {
                this.$store.commit("normalvalue/update_act_pat", 'delete')
                this.$store.commit("normalvalue/update_x_pat_id", value.Nat_NormalValueID)
                this.$store.commit("normalvalue/update_errors", [])
                var errors = this.$store.state.normalvalue.errors
                var msg = ''
                msg = "Yakin, akan menghapus data normal value ini ?"
                this.$store.commit("normalvalue/update_msg_confirmation_delete_pat", msg)
                this.$store.commit("normalvalue/update_dialog_confirmation_delete_pat", true)
            },
            doDeletePat() {
                var prm = {}
                prm.Nat_NormalValueNat_TestID = this.$store.state.normalvalue.selected_normalvalue
                    .Nat_TestID
                prm.Nat_NormalValueID = this.$store.state.normalvalue.x_pat_id
                prm.Nat_NormalValueName = this.namapasien
                prm.Nat_TestName = this.$store.state.normalvalue.selected_normalvalue.Nat_TestName
                this.$store.dispatch("normalvalue/deletenilainormal", prm)
            },
            openprintformat() {
                this.formatreport = 'pdf'
                this.dialogchooseprint = true
            },
            doPrint() {
                console.log('doprint')
                this.dialogchooseprint = false
                this.printwidth = 1028
                this.printtitle = ""
                let user = one_user()
                var d = new Date();
                var n = d.getTime()
                var rptname = 'nilainormalnew'
                var formatrpt = this.formatreport

                this.urlprint = "/birt/run?__report=report/nasional/masterdata/" + rptname + ".rptdesign&__format=" +
                    formatrpt + "&username=" + user.M_UserUsername + "&tm=" + n

                this.openprint = true
            },
            closePrint() {
                this.openprint = false
            },
            sendOrderNilaiNormal(value) {
                let msg = "Yakin, akan mengirim permintaan nomor " + this.$store.state.normalvalue.selected_normalvalue
                    .Nat_TestNumber + " ?"
                this.$store.commit("normalvalue/update_msg_confirmation_send", msg)
                this.$store.commit("normalvalue/update_dialog_confirmation_send", true)
            },
            doOrderNilaiNormal() {
                var prm = {}
                prm.Nat_TestID = this.$store.state.normalvalue.selected_normalvalue
                    .Nat_TestID
                prm.Nat_TestNumber = this.$store.state.normalvalue.selected_normalvalue
                    .Nat_TestNumber
                this.$store.dispatch("normalvalue/sendorder", prm)
            },
            convertMoney(money) {
                return one_money(money)
            },
            addTest() {
                var oldArr = this.$store.state.normalvalue.ordertests
                oldArr.push(this.$store.state.normalvalue.orderautotest)
                this.searchtest = ''
                this.$store.commit("normalvalue/update_orderautotests", [])
                this.$store.commit("normalvalue/update_orderautotest", {})
            },
            deleteDataPx(idx) {
                var inx = parseInt(idx);
                var xrow = this.$store.state.normalvalue.ordertests[inx]
                if (parseInt(xrow.xid) !== 0) {
                    var xdeltest = this.$store.state.normalvalue.deleted_ordertests
                    xdeltest.push(xrow)
                    this.$store.commit("normalvalue/update_deleted_ordertests", xdeltest)
                }
                var oldArr = this.$store.state.normalvalue.ordertests
                oldArr.splice(inx, 1)
                this.$store.commit("normalvalue/update_ordertests", oldArr)
            },
        },
        watch: {
            search_city(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.normalvalue.update_autocomplete_status == 1) return
                this.thr_search_city()
            },
            search_test(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.normalvalue.update_autocomplete_status == 1) return
                this.thr_search_test()
            },
            search_methode(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.normalvalue.update_autocomplete_status == 1) return
                this.thr_search_methode()
            }
        }
    }
</script>