<template>
    <v-layout class="mb-2" column>
        <v-dialog v-model="dialogconfirmationdelete" 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>
                    {{msgconfirmationdelete}}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn small color="blue darken-1 text-sm-right" flat @click="dialogconfirmationdelete = false">Batal</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-card class="mb-2">
            <v-layout row>
                <v-flex xs12>
                    <v-subheader red--text text--lighten-1> DATA DOCTOR
                        <v-flex text-md-right>
                            <v-btn v-if="!pgrs_save" @click="saveData()"  color="primary">Simpan</v-btn>
                        </v-flex>
                    </v-subheader>
                    <v-divider></v-divider>
                    <v-layout row>
                        <v-flex class="pa-2" xs3>
                            <v-card class="pt-2 pb-2" color="blue darken-2"  tile >
                                <v-img
                                :src="patient_photo"
                                aspect-ratio="1"
                                class="blue darken-2 pt-2"
                                contain
                                >
                                <template v-slot:placeholder>
                                <v-layout
                                    fill-height
                                    align-center
                                    justify-center
                                    ma-0
                                >
                                    <v-progress-circular indeterminate color="blue lighten-5"></v-progress-circular>
                                </v-layout>
                                </template>
                                </v-img>
                            </v-card>
                            <v-flex xs12>
                                <v-btn
                                class="mt-0 mb-0"
                                deppressed
                                small
                                color="blue darken-2 white--text"
                                :dark="patient.M_DoctorID ? true : false"
                                block
                                @click="update_photo"
                                :disabled="!patient.M_DoctorID"
                                >
                                Update Foto
                                </v-btn>
                            </v-flex>
                        </v-flex>
                        <v-flex xs9>
                            <v-layout pa-2 row>
                                <v-flex xs2 pa-2>
                                    <v-text-field v-model="xpatientprefix" label="Awalan 1" hide-details></v-text-field>
                                </v-flex>
                                <v-flex xs2 pa-2>
                                    <v-text-field v-model="xpatientprefix2" label="Awalan 2" hide-details></v-text-field>
                                </v-flex>
                                <v-flex xs6  pa-2>
                                    <v-text-field v-model="xpatientname" label="Nama Doctor*" hide-details></v-text-field>
                                    <p v-if="checkError('requirename')" class="error pl-2 pr-2" style="color:#fff">Nama harus diisi dong</p>
                                </v-flex>
                                <v-flex xs2  pa-2>
                                    <v-text-field v-model="xpatientsuffix" label="Akhiran 1" hide-details></v-text-field>
                                </v-flex>
                                <v-flex xs2  pa-2>
                                    <v-text-field v-model="xpatientsuffix2" label="Akhiran 2" hide-details></v-text-field>
                                </v-flex>
                            </v-layout>
                            <v-layout  pa-2  row>
                                <v-flex xs6 pa-2>
                                    <v-select 
                                        item-text="M_TitleName" 
                                        return-object :items="xtitles" 
                                        v-model="xtitle" 
                                        label="Sapaan" 
                                        hide-details
                                        @change="changeSapaan($event)"
                                    ></v-select>
                                    <!-- <p v-if="checkError('requiretitle')" class="error pl-2 pr-2" style="color:#fff">Panggilan harus diisi dong</p> -->
                                </v-flex>
                                <v-flex xs6 pa-2>
                                    <v-select item-text="M_DoctorGender" return-object :items="xsexes" v-model="xsex" label="Jenis Kelamin*" hide-details></v-select>
                                    <!-- <v-select item-text="m_sexname" return-object :items="xsexes" v-model="xsex" label="Jenis Kelamin*" hide-details></v-select> -->
                                    <p v-if="checkError('requiresex')" class="error pl-2 pr-2" style="color:#fff">Jenis kelamin harus diisi dong</p>
                                </v-flex>
                                <!-- <v-flex xs6 pa-2>
                                    <v-select item-text="M_TitleName" :disabled="_.isEmpty(xsex)" return-object :items="xtitles" v-model="xtitle" label="Panggilan*" hide-details></v-select>
                                    <p v-if="checkError('requiretitle')" class="error pl-2 pr-2" style="color:#fff">Panggilan harus diisi dong</p>
                                </v-flex> -->
                            </v-layout>
                            <v-layout  pa-2 row>
                                <!-- <v-flex xs4 pa-2>
                                    <v-text-field v-model="xpob" label="Tempat Lahir" hide-details></v-text-field>
                                </v-flex> -->
                                <!-- <v-flex xs4 pa-2>
                                    <v-text-field v-model="xdob" :readonly="age != '' && age" label="Tanggal Lahir*" hint="format : DD-MM-YYYY , contoh : 22-06-1988"></v-text-field>
                                    <p v-if="checkError('requiredob')" class="error pl-2 pr-2" style="color:#fff">Tanggal lahir harus diisi dong</p>
                                    <p v-if="checkError('wrongformatdob')" class="error pt-1 pl-2 pr-2" style="color:#fff">format nya belum benar : dd-mm-yyy , OK ?</p>
                                </v-flex> -->
                                <v-flex xs6 pa-2>
                                    <v-text-field v-model="xdob" label="Tanggal Lahir" hint="format : DD-MM-YYYY , contoh : 22-06-1988"
                                        @keyup.enter="calculateAge($event)" 
                                    ></v-text-field>
                                    <p v-if="checkError('requiredob')" class="error pl-2 pr-2" style="color:#fff">Tanggal lahir harus diisi dong</p>
                                    <p v-if="checkError('wrongformatdob')" class="error pt-1 pl-2 pr-2" style="color:#fff">format nya belum benar : dd-mm-yyy , OK ?</p>
                                </v-flex>
                                <v-flex xs2 pa-2>
                                    <!-- <v-text-field
                                        v-model="age"
                                        label="Umur"
                                        @change="changeAge($event)"
                                        placeholder="Isi Tahun"
                                    ></v-text-field> -->
                                    <v-text-field
                                        v-model="ageYear"
                                        label="Tahun"
                                        :readonly="true"
                                        placeholder="Tahun"
                                    ></v-text-field>
                                </v-flex>
                                <v-flex xs2 pa-2>
                                    <!-- <v-text-field
                                        v-model="age"
                                        label="Umur"
                                        @change="changeAge($event)"
                                        placeholder="Isi Tahun"
                                    ></v-text-field> -->
                                    <v-text-field
                                        v-model="ageMonth"
                                        label="Bulan"
                                        placeholder="Bulan"
                                        :readonly="true"
                                    ></v-text-field>
                                </v-flex>
                                <v-flex xs2 pa-2>
                                    <!-- <v-text-field
                                        v-model="age"
                                        label="Umur"
                                        @change="changeAge($event)"
                                        placeholder="Isi Tahun"
                                    ></v-text-field> -->
                                    <v-text-field
                                        v-model="ageDay"
                                        label="Hari"
                                        placeholder="Hari"
                                        :readonly="true"
                                    ></v-text-field>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                    </v-layout>

                    <v-layout  pa-2  row>
                        <v-flex xs4 pa-2>
                            <!-- <v-select item-text="M_ReligionName" return-object :items="xreligions" v-model="xreligion" label="Agama" hide-details></v-select> -->
                            <v-autocomplete item-text="display" 
                                return-object :items="xbloodtypes" v-model="xbloodtype" label="Gol Darah" hide-details></v-autocomplete>
                        </v-flex>
                        <v-flex xs4 pa-2>
                            <v-autocomplete item-text="display" 
                                return-object :items="xbloodrhs" v-model="xbloodrh" label="Rhesus" hide-details></v-autocomplete>
                        </v-flex>
                        <v-flex xs4 pa-2>
                            <v-autocomplete item-text="display" 
                            return-object :items="xeducations" v-model="xeducation" label="Pendidikan Terakhir" hide-details></v-autocomplete>
                        </v-flex>
                    </v-layout>

                    <v-layout  pa-2  row>
                        <v-flex xs6 pa-2>
                            <!-- <v-select item-text="M_ReligionName" return-object :items="xreligions" v-model="xreligion" label="Agama" hide-details></v-select> -->
                            <v-autocomplete item-text="M_DoctorCitizenship" 
                                return-object :items="xcitizenships" v-model="xcitizenship" label="Kewarganegaraan" hide-details></v-autocomplete>
                        </v-flex>
                        <v-flex xs6 pa-2>
                            <v-autocomplete item-text="display" 
                                return-object :items="xetnicitys" v-model="xetnicity" label="Etnis" hide-details></v-autocomplete>
                        </v-flex>
                        <!-- <v-flex xs4 pa-2>
                            <v-autocomplete item-text="display" 
                            return-object :items="xreligions" v-model="xreligion" label="Pendidikan Terakhir" hide-details></v-autocomplete>
                        </v-flex> -->
                    </v-layout>
                   
                    <v-layout  pa-2  row>
                        <v-flex xs4 pa-2>
                            <!-- <v-select item-text="M_ReligionName" return-object :items="xreligions" v-model="xreligion" label="Agama" hide-details></v-select> -->
                            <v-autocomplete item-text="display" 
                                return-object :items="xreligions" v-model="xreligion" label="Agama" hide-details></v-autocomplete>
                        </v-flex>
                        <v-flex xs4 pa-2>
                            <v-text-field v-model="xhp" label="HP" hide-details></v-text-field>
                        </v-flex>
                        <v-flex xs4 pa-2>
                            <v-text-field v-model="xemail" label="Email" @keyup="validateEmail()"></v-text-field>
                            <p v-if="!_.isEmpty(emailvalidate) && !_.isEmpty(xemail)" class="error caption mt-1 mb-0 pl-2 pr-2" style="color:#fff">{{ emailvalidate }}</p> 
                        </v-flex>
                    </v-layout>

                    <v-layout  pa-2  row>
                        <!-- <v-flex xs6 pa-2>
                            <v-select item-text="M_IdTypeName" return-object :items="xkartuidentitass" v-model="xkartuidentitas" label="Kartu Identitas"
                            hide-details></v-select>
                            <p v-if="checkError('identity')" class="error pl-2 pr-2" style="color:#fff">Identitas belum dipilih</p>
                        </v-flex> -->
                        <v-flex xs6 pa-2>
                            <v-autocomplete item-text="display" return-object :items="xkartuidentitass" v-model="xkartuidentitas" label="Kartu Identitas"
                            hide-details></v-autocomplete>
                            <p v-if="checkError('identity')" class="error pl-2 pr-2" style="color:#fff">Identitas belum dipilih</p>
                        </v-flex>
                        <v-flex xs6 pa-2>
                            <!-- <v-text-field
                                v-model="xnoidentitas"
                                label="Nomor ID"
                                :readonly="xkartuidentitas && !xkartuidentitas.M_IdTypeID"
                                @keyup="changeNumberID($event)"
                                hide-details
                            ></v-text-field>
                            <p v-if="checkError('identytynumber')" class="error pl-2 pr-2" style="color:#fff">Nomor identitas belum diisi / format salah</p> -->
                            <v-text-field
                                v-model="xnoidentitas"
                                label="Nomor ID"
                                @keyup="changeNumberIDNew($event)"
                                hide-details
                            ></v-text-field>
                            <p v-if="checkError('identytynumber')" class="error pl-2 pr-2" style="color:#fff">Nomor identitas belum diisi / format salah</p>
                        </v-flex>
                        <!-- <v-flex xs4 pa-2>
                            <v-text-field v-model="xjob" label="Pekerjaan" hide-details></v-text-field>
                        </v-flex> -->
                    </v-layout>
                    <v-layout row pa-2>
                        <v-flex xs12 pa-2>
                            <v-autocomplete item-text="M_SpecialistName" 
                            item-value="M_SpecialisID"
                            return-object :items="xspecialists" v-model="xspecialist" label="Spesialis" hide-details></v-autocomplete>
                        </v-flex>
                    </v-layout>
                    <!-- <v-layout row pa-2>
                        <v-flex xs12 pa-2>
                            <v-textarea
                            style="font-size:12px;padding:4px 0"
                            auto-grow
                            rows="1"
                            v-model="xnote"
                            label="Catatan"
                            >
                        </v-textarea>
                        </v-flex>
                    </v-layout> -->
                </v-flex>
            </v-layout>
        </v-card>
        <v-card>
            <v-layout row>
                <v-flex xs12 pa-2>
                    <v-subheader red--text text--lighten-1> ALAMAT DOCTOR</v-subheader>
                    <v-divider></v-divider>
                   
                        <!-- dropdown auto complete country -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-autocomplete 
                                :items="xCountryCb" 
                                v-model="selected_countryCb" 
                                item-text="display"
                                hide-details
                                item-value="code" 
                                return-object 
                                label="Country"
                            >
                            </v-autocomplete>
                            <!-- <p  v-if="_.isEmpty(selected_countryCb)" class="error caption mt-1 mb-0 pl-2 pr-2 pb-2" style="color:#fff">Belum pilih Country</p> -->
                        </v-flex>
                        <!-- dropdown auto complete country -->
                        <!-- dropdown auto complete alamat -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-autocomplete 
                                :items="xWilayahCb" 
                                v-model="selected_wilayahCb" 
                                item-text="text_nm"
                                hide-details
                                item-value="id" 
                                return-object 
                                label="Cari Wilayah"
                                :search-input.sync="search_wilayah"
                            >
                            </v-autocomplete>
                            <!-- <p  v-if="_.isEmpty(selected_wilayahCb)" class="error caption mt-1 mb-0 pl-2 pr-2 pb-2" style="color:#fff">Belum pilih Country</p> -->
                        </v-flex>
                        <!-- dropdown auto complete alamat -->
                        <!-- provinsi -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-text-field
                                color="black"
                                label="Provinsi"
                                v-model="inp_CorporateAddressState"
                                hide-details
                                single-line
                                type="text"
                                readonly
                            ></v-text-field>
                        </v-flex>
                        <!-- provinsi -->
                        <!-- kota / kabupaten -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-text-field
                                color="black"
                                label="Kota/Kab"
                                v-model="inp_CorporateAddressCity"
                                hide-details
                                single-line
                                type="text"
                                readonly
                            ></v-text-field>
                        </v-flex>
                        <!-- kota / kabupaten -->
                        <!-- kecamatan -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-text-field
                                color="black"
                                label="Kecamatan"
                                v-model="inp_CorporateAddressDistrict"
                                hide-details
                                single-line
                                type="text"
                                readonly
                            ></v-text-field>
                        </v-flex>
                        <!-- kecamatan -->
                        <!-- kelurahan -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-text-field
                                color="black"
                                label="Kelurahan"
                                v-model="inp_CorporateAddressVillage"
                                hide-details
                                single-line
                                type="text"
                                readonly
                            ></v-text-field>
                        </v-flex>
                        <!-- kelurahan -->
                        <!-- rt -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-text-field
                                color="black"
                                label="RT"
                                v-model="inp_CorporateAddressRT"
                                hide-details
                                single-line
                                type="text"
                            ></v-text-field>
                        </v-flex>
                        <!-- rt -->
                        <!-- rw -->
                        <v-flex xs12 pt-2 pb-2>
                            <v-text-field
                                color="black"
                                label="RT"
                                v-model="inp_CorporateAddressRW"
                                hide-details
                                single-line
                                type="text"
                            ></v-text-field>
                        </v-flex>
                        <!-- rw -->
                        <!-- alamat inputan -->
                        <v-flex xs12 pa-2>
                            <v-textarea label="Alamat" v-model="inp_CorporateAddress"></v-textarea>
                        </v-flex>
                        <!-- alamat inputan -->
                   

                    <!-- BELOW unused alamat -->
                    <v-layout pa-2 row style="display: none;">
                        <v-flex xs6 pa-2>
                            <v-autocomplete
                                style="font-size:12px;padding:4px 0"
                                :items="provinces"
                                item-text="M_ProvinceName"
                                item-value="M_ProvinceID"
                                label="Propinsi"
                                v-model="province_address"
                                clearable
                                return-object
                                
                            ></v-autocomplete>
                            <p v-if="checkError('province')" class="error pl-2 pr-2" style="color:#fff">Province harus dipilih</p>
                        </v-flex>
                        <v-flex xs6  pa-2>
                            <v-autocomplete
                                style="font-size:12px;padding:4px 0"
                                :items="cities"
                                item-text="M_CityName"
                                item-value="M_CityID"
                                label="Kota"
                                v-model="city_address"
                                clearable
                                return-object
                            ></v-autocomplete>
                            <p v-if="checkError('city')" class="error pl-2 pr-2" style="color:#fff">Kota harus dipilih</p>
                        </v-flex>
                    </v-layout>
                    <v-layout pa-2 row style="display: none;">
                        <v-flex xs6 pa-2>
                            <v-autocomplete
                                style="font-size:12px;padding:4px 0"
                                :items="districts"
                                item-text="M_DistrictName"
                                item-value="M_DistrictID"
                                label="Kecamatan"
                                v-model="district_address"
                                clearable
                                return-object
                            ></v-autocomplete>
                            <p v-if="checkError('district')" class="error pl-2 pr-2" style="color:#fff">Kecamatan harus dipilih</p>
                        </v-flex>
                        <v-flex xs6  pa-2>
                            <v-autocomplete
                                style="font-size:12px;padding:4px 0"
                                :items="kelurahans"
                                item-text="M_KelurahanName"
                                item-value="M_KelurahanID"
                                label="Kelurahan"
                                clearable
                                v-model="kelurahan_address"
                                return-object
                            ></v-autocomplete>
                            <p v-if="checkError('kelurahan')" class="error pl-2 pr-2" style="color:#fff">Kelurahan harus dipilih</p>
                        </v-flex>
                    </v-layout>
                    <v-layout row style="display: none;">
                        <v-flex xs12>
                            <v-textarea
                                style="font-size:12px;padding:4px 0"
                                auto-grow
                                rows="1"
                                v-model="address"
                                label="Alamat Lengkap"
                                hide-details
                                >
                            </v-textarea>
                            <p v-if="checkError('address')" class="error pl-2 pr-2" style="color:#fff">Alamat harus diisi</p>
                        </v-flex>
                    </v-layout>
                    <!-- BELOW unused alamat -->
                </v-flex>
            </v-layout>
            <v-divider></v-divider>
            <v-card-actions>
                <v-spacer></v-spacer>
                <!-- <v-btn v-if="!pgrs_save" @click="saveData()"  color="primary">Simpan</v-btn> -->
            </v-card-actions>
        </v-card>
        <patient-photo-dialog></patient-photo-dialog>
    </v-layout>
    
</template>

<style scoped>
    table,
    td,
    th {
        border: 1px solid #ddd;
        text-align: left;
    }

    table {
        border-collapse: collapse;
        width: 100%;
    }

    th,
    td {
        padding-top: 5px;
        padding-bottom: 5px;
        padding-left: 8px;
        padding-right: 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;
    }

    input.fhm-input {
        border: 1px solid black;
        border-radius: 2px;
        -webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1),
        0 0 4px rgba(0, 0, 0, 0.1);
        -moz-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1),
        0 0 4px rgba(0, 0, 0, 0.1);
        box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1),
        0 0 4px rgba(0, 0, 0, 0.1);
        padding: 2px 4px;
        background: rgba(255, 255, 255, 0.5);
        margin: 0 0 1px 0;
        width: 30px;
        text-align: center;
    }
</style>

<script>
    module.exports = {
        components : {
            'patient-photo-dialog': httpVueLoader('./oneDialogPhoto.vue')
        },
        mounted(){
            // country
            this.$store.dispatch("patient/getCountryTerminology")
            // agama
            this.$store.dispatch("patient/getReligionTerminology")
            // gol darah
            this.$store.dispatch("patient/getBloodTypeTerminology")
            // rhesus
            this.$store.dispatch("patient/getBloodRhesusTerminology")
            // kewarganegaraan
            this.$store.dispatch("patient/getKewarganegaraanHarcode")
            // sapaan
            this.$store.dispatch("patient/getSapaan")
            // jenis kelamin
            this.$store.dispatch("patient/getJenisKelaminHarcode")
            // etnicity
            this.$store.dispatch("patient/getEtnicityTerminology")
            // kartu identitas
            this.$store.dispatch("patient/getIdentifierTerminology")
            // spesialis
            this.$store.dispatch("patient/getSpecialist")
            // education
            this.$store.dispatch("patient/getEducationTerminology")
            
        },
        watch:{
            search_wilayah(val,old) {
            //console.log(val)
            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_wilayah()
        }
        },
        data: () => ({
            search_wilayah:'',
            age:'',
            // ageYear: 0,
            // ageMonth: 0,
            // ageDay: 0,
        }),
        computed: {
            emailvalidate:{
                get() {
                    return this.$store.state.patient.emailvalidate
                },
                set(val) {
                    this.$store.commit("patient/update_emailvalidate",val)
                }
            },
            ageYear:{
                get() {
                    return this.$store.state.patient.ageYear
                },
                set(val) {
                    this.$store.commit("patient/update_ageYear",val)
                }
            },
            ageMonth:{
                get() {
                    return this.$store.state.patient.ageMonth
                },
                set(val) {
                    this.$store.commit("patient/update_ageMonth",val)
                }
            },
            ageDay:{
                get() {
                    return this.$store.state.patient.ageDay
                },
                set(val) {
                    this.$store.commit("patient/update_ageDay",val)
                }
            },
            inp_CorporateAddressState:{
                get() {
                    return this.$store.state.patient.inp_CorporateAddressState
                },
                set(val) {
                    this.$store.commit("patient/update_inp_CorporateAddressState",val)
                }
            },
            inp_CorporateAddressVillage:{
                get() {
                    return this.$store.state.patient.inp_CorporateAddressVillage
                },
                set(val) {
                    this.$store.commit("patient/update_inp_CorporateAddressVillage",val)
                }
            },
            inp_CorporateAddressDistrict:{
                get() {
                    return this.$store.state.patient.inp_CorporateAddressDistrict
                },
                set(val) {
                    this.$store.commit("patient/update_inp_CorporateAddressDistrict",val)
                }
            },
            inp_CorporateAddressCity:{
                get() {
                    return this.$store.state.patient.inp_CorporateAddressCity
                },
                set(val) {
                    this.$store.commit("patient/update_inp_CorporateAddressCity",val)
                }
            },
            inp_CorporateAddress:{
                get() {
                    return this.$store.state.patient.inp_CorporateAddress
                },
                set(val) {
                    this.$store.commit("patient/update_inp_CorporateAddress",val)
                }
            },
            inp_CorporateAddressRW:{
                get() {
                    return this.$store.state.patient.inp_CorporateAddressRW
                },
                set(val) {
                    this.$store.commit("patient/update_inp_CorporateAddressRW",val)
                }
            },
            inp_CorporateAddressRT:{
                get() {
                    return this.$store.state.patient.inp_CorporateAddressRT
                },
                set(val) {
                    this.$store.commit("patient/update_inp_CorporateAddressRT",val)
                }
            },
            selected_wilayahCb:{
                get() {
                    return this.$store.state.patient.selected_wilayahCb
                },
                set(val) {
                    this.$store.commit("patient/update_selected_wilayahCb", val)
                    this.inp_CorporateAddressState = val.pro_nm
                    this.inp_CorporateAddressCity = val.kab_nm
                    this.inp_CorporateAddressDistrict = val.kec_nm
                    this.inp_CorporateAddressVillage = val.kel_nm
                }
            },
            xWilayahCb(){
                return this.$store.state.patient.wilayahCb
            },
            xCountryCb() {
                return this.$store.state.patient.countryCb
            },
            selected_countryCb:{
                get() {
                    return this.$store.state.patient.selected_countryCb
                },
                set(val) {
                    this.$store.commit("patient/update_selected_countryCb", val)
                }
            },
            patient:{
                get() {
                    return this.$store.state.patient.selected_patient
                },
                set(val) {
                    this.$store.commit("patient/update_selected_patient",val)
                }
            },
            patient_photo () {
                return this.$store.state.photo.photo_url
            },
            address:{
                get() {
                    return this.$store.state.patient.address
                },
                set(val) {
                    this.$store.commit("patient/update_address",val)
                }
            },
            provinces(){
                return this.$store.state.patient.provinces
            },
            provinceaddress:{
                get() {
                    return this.$store.state.patient.province_address
                },
                set(val) {
                    this.$store.commit("patient/update_province_address",val)
                    this.$store.dispatch("patient/getcities",val)
                }
            },
            provinces(){
                return this.$store.state.patient.provinces
            },
            province_address:{
                get() {
                    return this.$store.state.patient.province_address
                },
                set(val) {
                    this.$store.commit("patient/update_province_address",val)
                    this.$store.dispatch("patient/getcities",val)
                }
            },
            cities(){
                return this.$store.state.patient.cities
            },
            city_address:{
                get() {
                    return this.$store.state.patient.city_address
                },
                set(val) {
                    this.$store.commit("patient/update_city_address",val)
                    this.$store.dispatch("patient/getdistricts",val)
                }
            },
            districts(){
                return this.$store.state.patient.districts
            },
            district_address:{
                get() {
                    return this.$store.state.patient.district_address
                },
                set(val) {
                    this.$store.commit("patient/update_district_address",val)
                    this.$store.dispatch("patient/getkelurahans",val)
                }
            },
            kelurahans(){
                return this.$store.state.patient.kelurahans
            },
            kelurahan_address:{
                get() {
                    return this.$store.state.patient.kelurahan_address
                },
                set(val) {
                    this.$store.commit("patient/update_kelurahan_address",val)
                }
            },
            patient_note: {
                get() {
                    return this.$store.state.patient.patient_note
                },
                set(val) {
                    this.$store.commit("patient/update_patient_note", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            pgrs_save(){
                
                return this.$store.state.patient.pgrs_save
            },
            dialogconfirmationdelete: {
                get() {
                    return this.$store.state.patient.dialog_confirmation_delete
                },
                set(val) {
                    this.$store.commit("patient/update_dialog_confirmation_delete", val)
                }
            },
            msgconfirmationdelete() {
                return this.$store.state.patient.msg_confirmation_delete
            },
            xact() {
                return this.$store.state.patient.act
            },
            detail() {
                return this.$store.state.patient.selected_patient
            },
            xtitles() {
                return this.$store.state.patient.titles
            },
            xtitle: {
                get() {
                    return this.$store.state.patient.selected_title
                },
                set(val) {
                    this.$store.commit("patient/update_selected_title", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpatientprefix: {
                get() {
                    return this.$store.state.patient.patient_prefix
                },
                set(val) {
                    this.$store.commit("patient/update_patient_prefix", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpatientprefix2: {
                get() {
                    return this.$store.state.patient.patient_prefix2
                },
                set(val) {
                    this.$store.commit("patient/update_patient_prefix2", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpatientname: {
                get() {
                    return this.$store.state.patient.patient_name
                },
                set(val) {
                    this.$store.commit("patient/update_patient_name", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpatientsuffix: {
                get() {
                    return this.$store.state.patient.patient_suffix
                },
                set(val) {
                    this.$store.commit("patient/update_patient_suffix", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpatientsuffix2:{
                get() {
                    return this.$store.state.patient.patient_suffix2
                },
                set(val) {
                    this.$store.commit("patient/update_patient_suffix2", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xnorm: {
                get() {
                    return this.$store.state.patient.norm
                },
                set(val) {
                    this.$store.commit("patient/update_norm", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xdob: {
                get() {
                    return this.$store.state.patient.dob
                },
                set(val) {
                    this.$store.commit("patient/update_errors", [])
                    var errors = this.$store.state.patient.errors
                    var aDOB = moment(val, 'DD-MM-YYYY', true)
                    var isValidDOB = aDOB.isValid()
                    if (!isValidDOB) {
                        errors.push("wrongformatdob")
                    }

                    this.$store.commit("patient/update_dob", val)
                    this.$store.commit("patient/update_no_save", 1)

                }
            },
            xsexes() {
                return this.$store.state.patient.sexes
            },
            xsex: {
                get() {
                    return this.$store.state.patient.selected_sex
                },
                set(val) {
                    this.$store.commit("patient/update_selected_sex", val)
                    this.$store.commit("patient/update_no_save", 1)
                    let titles = this.$store.state.patient.titles_origin
                    // let new_titles = _.filter(titles, function(o) { return parseInt(o.M_TitleM_SexID) === parseInt(val.M_SexID) })
                    // this.$store.commit("patient/update_titles", new_titles)
                }
            },
            xreligions() {
                return this.$store.state.patient.religions
            },
            xreligion: {
                get() {
                    return this.$store.state.patient.selected_religion
                },
                set(val) {
                    this.$store.commit("patient/update_selected_religion", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xbloodtypes() {
                return this.$store.state.patient.bloodtypes
            },
            xbloodtype: {
                get() {
                    return this.$store.state.patient.selected_bloodtype
                },
                set(val) {
                    this.$store.commit("patient/update_selected_bloodtype", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xbloodrhs() {
                return this.$store.state.patient.bloodrhs
            },
            xbloodrh: {
                get() {
                    return this.$store.state.patient.selected_bloodrh
                },
                set(val) {
                    this.$store.commit("patient/update_selected_bloodrh", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xeducations() {
                return this.$store.state.patient.educations
            },
            xeducation: {
                get() {
                    return this.$store.state.patient.selected_education
                },
                set(val) {
                    this.$store.commit("patient/update_selected_education", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xcitizenships(){
                return this.$store.state.patient.citizenships
            },
            xcitizenship: {
                get() {
                    return this.$store.state.patient.selected_citizenship
                },
                set(val) {
                    this.$store.commit("patient/update_selected_citizenship", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xetnicitys(){
                return this.$store.state.patient.etnicitys
            },
            xetnicity: {
                get() {
                    return this.$store.state.patient.selected_etnicity
                },
                set(val) {
                    this.$store.commit("patient/update_selected_etnicity", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xspecialists(){
                return this.$store.state.patient.specialists
            },
            xspecialist: {
                get() {
                    return this.$store.state.patient.selected_specialist
                },
                set(val) {
                    this.$store.commit("patient/update_selected_specialist", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xphone: {
                get() {
                    return this.$store.state.patient.phone
                },
                set(val) {
                    this.$store.commit("patient/update_phone", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xhp: {
                get() {
                    return this.$store.state.patient.hp
                },
                set(val) {
                    this.$store.commit("patient/update_hp", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xemail: {
                get() {
                    return this.$store.state.patient.email
                },
                set(val) {
                    this.$store.commit("patient/update_email", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpob: {
                get() {
                    return this.$store.state.patient.pob
                },
                set(val) {
                    this.$store.commit("patient/update_pob", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xkartuidentitass() {
                return this.$store.state.patient.kartuidentitass
            },
            xkartuidentitas: {
                get() {
                    return this.$store.state.patient.selected_kartuidentitas
                },
                set(val) {
                    this.$store.commit("patient/update_selected_kartuidentitas", val)
                    this.$store.commit("patient/update_no_save", 1)
                    if(val){
                        this.changeNumberID_ByType(val.M_IdTypeName)
                    }
                }
            },
            xnoidentitas: {
                get() {
                    return this.$store.state.patient.noidentitas
                },
                set(val) {
                    this.$store.commit("patient/update_noidentitas", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xnote: {
                get() {
                    return this.$store.state.patient.note
                },
                set(val) {
                    this.$store.commit("patient/update_note", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xjob: {
                get() {
                    return this.$store.state.patient.job
                },
                set(val) {
                    this.$store.commit("patient/update_job", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xnik: {
                get() {
                    return this.$store.state.patient.nik
                },
                set(val) {
                    this.$store.commit("patient/update_nik", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xjabatan: {
                get() {
                    return this.$store.state.patient.jabatan
                },
                set(val) {
                    this.$store.commit("patient/update_jabatan", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xkedudukan: {
                get() {
                    return this.$store.state.patient.kedudukan
                },
                set(val) {
                    this.$store.commit("patient/update_kedudukan", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpj: {
                get() {
                    return this.$store.state.patient.pj
                },
                set(val) {
                    this.$store.commit("patient/update_pj", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xlocation: {
                get() {
                    return this.$store.state.patient.location
                },
                set(val) {
                    this.$store.commit("patient/update_location", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
        },
        methods: {
            changeNumberIDNew(event){
                console.log(event.target.value)
                var value = event.target.value
                this.$store.state.patient.errors = []
                var errors = this.$store.state.patient.errors
                let cxc = this.xkartuidentitas.code
                if(value && !_.isEmpty(this.xkartuidentitas) && cxc != 'Lainnya'){
                    let idType = cxc
                    let idnumberLength = value?value.length:0
                    let stringNIK = value
                    if(idType == 'NNIDN' && (value === '' || stringNIK.substr(0,16) == '0000000000000000')){
                        errors.push("identytynumber")
                    }
                    if(idType == 'NNIDN' && (idnumberLength < 16 )){
                        errors.push("identytynumber")
                    }
                    if(idType == 'NNIDN' && (idnumberLength > 19)){
                        errors.push("identytynumber")
                    }
                    if(idType == 'PPN' && ( value === '')){
                        errors.push("identytynumber")
                    }
                    if(idType == 'PPN' && ( idnumberLength < 8)){
                        errors.push("identytynumber")
                    }
                    if(idType == 'PPN' && ( idnumberLength > 16)){
                        errors.push("identytynumber")
                    }
                }
                else if(!value && !_.isEmpty(this.xkartuidentitas) && cxc != 'Lainnya'){
                    errors.push("identytynumber")
                }
                else if(_.isEmpty(this.xkartuidentitas)){
                    errors.push("identytynumber")
                }
                else{
                    errors = []
                }
            },
            validateEmail(){
                // console.log('value',this.xemail)
                const value = this.xemail;

                if (value.length > 0) {
                    const pattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                    // return pattern.test(value) || 'Invalid e-mail.';
                    if(!pattern.test(value)){
                        this.$store.commit("patient/update_emailvalidate","Email Tidak Valid")
                        console.log('not valid email')
                    } else{
                        this.$store.commit("patient/update_emailvalidate","")
                        console.log('valid email')
                    }
                }
            },
            changeSapaan(value){
                if(value.M_TitleGender == "male"){
                    this.$store.commit("patient/update_sexes", [{
                        M_DoctorGender:"male"
                    }])
                    
                } else {
                    this.$store.commit("patient/update_sexes", [{
                        M_DoctorGender:"female"
                    }])
                }
            },
            thr_search_wilayah: _.debounce( function () {
                console.log(this.search_wilayah)
                this.$store.dispatch("patient/searchwilayah",{
                    search:this.search_wilayah
                })
                
            },2000),
            update_photo () {
                this.$store.commit('photo/update_dialog_photo', true)
            },
            generate_card(){
                var xid = this.$store.state.patient.selected_patient.M_DoctorID
                this.rpt_card = "/birt/run?__report=report/one/fo/rpt_card.rptdesign&__format=pdf&username=admin%20&PID="+xid
                this.dialog_card = true
            },
            removeErrors(id){
                var errors = this.$store.state.patient.errors
                errors.forEach((index,value) => {
                    if(id === value){
                        errors.splice(index, 1)
                    }
                });
            },
            changeNumberID(event){
                console.log(event.target.value)
                var value = event.target.value
                this.$store.state.patient.errors = []
                var errors = this.$store.state.patient.errors
                let cxc = this.xkartuidentitas.M_IdTypeName
                if(value && !_.isEmpty(this.xkartuidentitas) && cxc != 'Lainnya'){
                    let idType = cxc
                    let idnumberLength = value?value.length:0
                    let stringNIK = value
                    if(idType == 'KTP' && (value === '' || stringNIK.substr(0,16) == '0000000000000000')){
                        errors.push("identytynumber")
                    }
                    if(idType == 'KTP' && (idnumberLength < 16 )){
                        errors.push("identytynumber")
                    }
                    if(idType == 'KTP' && (idnumberLength > 19)){
                        errors.push("identytynumber")
                    }
                    if(idType == 'Pasport' && ( value === '')){
                        errors.push("identytynumber")
                    }
                    if(idType == 'Pasport' && ( idnumberLength < 8)){
                        errors.push("identytynumber")
                    }
                    if(idType == 'Pasport' && ( idnumberLength > 16)){
                        errors.push("identytynumber")
                    }
                }
                else if(!value && !_.isEmpty(this.xkartuidentitas) && cxc != 'Lainnya'){
                    errors.push("identytynumber")
                }
                else if(_.isEmpty(this.xkartuidentitas)){
                    errors.push("identytynumber")
                }
                else{
                    errors = []
                }
              
                
        },
       changeNumberID_ByType(xvalue){
        console.log(xvalue)
        this.$store.state.patient.errors = []
                var errors = this.$store.state.patient.errors
                this.xnoidentitas = ""
            var value = this.xnoidentitas
            let cxc = xvalue
            if(value && !_.isEmpty(this.xkartuidentitas) && cxc != 'Lainnya'){
                let idType = cxc
                let idnumberLength = value?value.length:0
                let stringNIK = value
                if(idType == 'KTP' && (value === '' || stringNIK.substr(0,16) == '0000000000000000')){
                    errors.push("identytynumber")
                }
                if(idType == 'KTP' && (idnumberLength < 16 )){
                    errors.push("identytynumber")
                }
                if(idType == 'KTP' && (idnumberLength > 19)){
                    errors.push("identytynumber")
                }
                if(idType == 'Pasport' && ( value === '')){
                    errors.push("identytynumber")
                }
                if(idType == 'Pasport' && ( idnumberLength < 8)){
                    errors.push("identytynumber")
                }
                if(idType == 'Pasport' && ( idnumberLength > 16)){
                    errors.push("identytynumber")
                }
            }
            else if(!value && !_.isEmpty(this.xkartuidentitas) && cxc != 'Lainnya'){
                errors.push("identytynumber")
            }
            else if(_.isEmpty(this.xkartuidentitas)){
                errors.push("identytynumber")
            }
            else{
                errors = []
            }
            },
            calculateAge(event){
                // console.log(event.target.value)
                if(event.target.value !== ''){
                    const dob = event.target.value;
                    // const isValidDate = this.validateDateFormat(dob);
                    
                    // if (!isValidDate) {
                    //     this.ageYear = 0;
                    //     this.ageMonth = 0;
                    //     this.ageDay = 0;
                    //     return;
                    // }

                    const [day, month, year] = dob.split('-').map(Number);
                    const birthDate = new Date(year, month - 1, day);
                    const today = new Date();

                    let ageYear = today.getFullYear() - birthDate.getFullYear();
                    let ageMonth = today.getMonth() - birthDate.getMonth();
                    let ageDay = today.getDate() - birthDate.getDate();

                    if (ageDay < 0) {
                        ageMonth -= 1;
                        ageDay += new Date(year, month, 0).getDate();  // Get days in previous month
                    }

                    if (ageMonth < 0) {
                        ageYear -= 1;
                        ageMonth += 12;
                    }

                    // console.log('ageyear', ageYear)
                    // console.log('agemonth', ageMonth)
                    // console.log('ageday', ageDay)

                    this.ageYear = ageYear;
                    this.ageMonth = ageMonth;
                    this.ageDay = ageDay;
                }
            },
            changeAge(value){
                //console.log(value)
                if(value !== '' && value.length <= 2){
                    var xy = new Date().getFullYear() - value
                    var a = new Date(); 
                    var xm = ("0" + (a.getMonth() + 1)).slice(-2); 
                    var xd = ("0" + a.getDate()).slice(-2); 
                    this.xdob = xd+'-'+xm+'-'+xy
                }
                else
                    this.age = ''
            },
            checkError(value) {
                var errors = this.$store.state.patient.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            saveData(){
                if(!_.isEmpty(this.$store.state.patient.selected_patient)){
                    this.updatePatient()
                    // console.log('update baru')
                }else{
                    this.newPatient()
                    // console.log('add baru')
                }
            },

            updatePatient() {
                this.$store.commit("patient/update_errors", [])
                var errors = this.$store.state.patient.errors
                var aDOB = moment(this.xdob, 'DD-MM-YYYY', true)
                console.log(this.xdob)
                console.log(aDOB)
                var isValidDOB = aDOB.isValid()
                if (!isValidDOB) {
                    errors.push("wrongformatdob")
                }
                if (_.isEmpty(this.xpatientname)) {
                    errors.push("requirename")
                }
                // if (this.xdob === '') {
                //     errors.push("requiredob")
                // }
                if (_.isEmpty(this.xsex)) {
                    errors.push("requiresex")
                }
                // if (_.isEmpty(this.xtitle)) {
                //     errors.push("requiretitle")
                // }

                // if (_.isEmpty(this.province_address)) {
                //     errors.push("province")
                // }
                // if (_.isEmpty(this.city_address)) {
                //     errors.push("city")
                // }

                // if (_.isEmpty(this.district_address)) {
                //     errors.push("district")
                // }
                // if (_.isEmpty(this.kelurahan_address)) {
                //     errors.push("kelurahan")
                // }

                // if(_.isEmpty(this.$store.state.patient.selected_kartuidentitas)){
                //     errors.push("identity")
                // }

                // if(this.address === ''){
                //     errors.push("address")
                // }

                // variable start
                let M_DoctorID = 0;
                let M_DoctorM_TitleID = 0;
                let M_DoctorCode = "";
                let M_DoctorPrefix = "";
                let M_DoctorPrefix2 = "";
                let M_DoctorName = "";
                let M_DoctorSuffix = "";
                let M_DoctorSuffix2 = "";
                let M_DoctorGender = ""; // 'male' or 'female'
                let M_DoctorDOB = "0000-00-00";
                let M_DoctorReligionCode = "";
                let M_DoctorReligionSystem = "";
                let M_DoctorBloodTypeCode = "";
                let M_DoctorBloodTypeSystem = "";
                let M_DoctorBloodRhCode = "";
                let M_DoctorBloodRhSystem = "";
                let M_DoctorEducationCode = "";
                let M_DoctorEducationSystem = "";
                let M_DoctorCitizenship = ""; // 'WNI' or 'WNA'
                let M_DoctorEtnicCode = "";
                let M_DoctorEtnicSystem = "";
                let M_DoctorIdentifierCode = "";
                let M_DoctorIdentifierSystem = "";
                let M_DoctorIdentifierValue = "";
                let M_DoctorHp = "";
                let M_DoctorEmail = "";
                let M_DoctorM_SpecialistID = 0;
                let M_DoctorPhoto = "";
                let M_DoctorAddress = "";
                let M_DoctorAddressRegionalCd = "";
                let M_DoctorAddressRT = "";
                let M_DoctorAddressRW = "";
                let M_DoctorAddressCity = ""; // kabupaten / kota
                let M_DoctorAddressVillage = ""; // kelurahan / desa
                let M_DoctorAddressDistrict = ""; // kecamatan
                let M_DoctorAddressState = ""; // provinsi
                let M_DoctorAddressCountry = ""; // negara
                // variable end

                if (errors.length === 0) {
                    M_DoctorID = this.$store.state.patient.selected_patient.M_DoctorID
                    // M_DoctorM_TitleID = this.$store.state.patient.selected_title.M_TitleID

                    if(!_.isEmpty(this.$store.state.patient.selected_title.M_TitleID)){
                        M_DoctorM_TitleID = this.$store.state.patient.selected_title.M_TitleID
                    }

                    M_DoctorCode = "";
                    M_DoctorPrefix = this.xpatientprefix
                    M_DoctorPrefix2 = this.xpatientprefix2
                    M_DoctorName = this.xpatientname
                    M_DoctorSuffix = this.xpatientsuffix
                    M_DoctorSuffix2 = this.xpatientsuffix2
                    M_DoctorGender = this.xsex.M_DoctorGender; // 'male' or 'female'
                    // M_DoctorDOB = this.xdob

                    if(!_.isEmpty(this.xdob)){
                        M_DoctorDOB = this.xdob
                    }

                    // religion
                    if(!_.isEmpty(this.$store.state.patient.selected_religion)){
                        M_DoctorReligionCode = this.$store.state.patient.selected_religion.code
                        M_DoctorReligionSystem = this.$store.state.patient.selected_religion.code_system
                    }
                   
                    if(!_.isEmpty(this.$store.state.patient.selected_bloodtype)){
                        M_DoctorBloodTypeCode = this.$store.state.patient.selected_bloodtype.code;
                        M_DoctorBloodTypeSystem = this.$store.state.patient.selected_bloodtype.code_system;
                    }

                    if(!_.isEmpty(this.$store.state.patient.selected_bloodrh)){
                        M_DoctorBloodRhCode = this.$store.state.patient.selected_bloodrh.code;
                        M_DoctorBloodRhSystem = this.$store.state.patient.selected_bloodrh.code_system;
                    }

                    if(!_.isEmpty(this.$store.state.patient.selected_education)){
                        M_DoctorEducationCode = this.$store.state.patient.selected_education.code;
                        M_DoctorEducationSystem = this.$store.state.patient.selected_education.code_system;
                    }

                    M_DoctorCitizenship = this.xcitizenship.M_DoctorCitizenship; // 'WNI' or 'WNA'
                    
                    if(!_.isEmpty(this.$store.state.patient.selected_etnicity)){
                        M_DoctorEtnicCode = this.$store.state.patient.selected_etnicity.code;
                        M_DoctorEtnicSystem = this.$store.state.patient.selected_etnicity.code_system;
                    }

                    if(!_.isEmpty(this.$store.state.patient.selected_kartuidentitas)){
                        M_DoctorIdentifierCode = this.$store.state.patient.selected_kartuidentitas.code;
                        M_DoctorIdentifierSystem = this.$store.state.patient.selected_kartuidentitas.code_system;
                        M_DoctorIdentifierValue = this.xnoidentitas;
                    }

                    M_DoctorHp = this.$store.state.patient.hp;
                    M_DoctorEmail = this.xemail;

                    if(!_.isEmpty(this.$store.state.patient.selected_specialist)){
                        M_DoctorM_SpecialistID = this.$store.state.patient.selected_specialist.M_SpecialistID
                    }
                  
                    M_DoctorPhoto = "";
                    M_DoctorAddress = this.$store.state.patient.inp_CorporateAddress;

                    if(!_.isEmpty(this.$store.state.patient.selected_wilayahCb)){
                        M_DoctorAddressRegionalCd = this.selected_wilayahCb.regional_cd;
                    }
                   
                    M_DoctorAddressRT = this.$store.state.patient.inp_CorporateAddressRT;
                    M_DoctorAddressRW = this.$store.state.patient.inp_CorporateAddressRW;
                    M_DoctorAddressCity = this.$store.state.patient.inp_CorporateAddressCity; // kabupaten / kota
                    M_DoctorAddressVillage = this.$store.state.patient.inp_CorporateAddressVillage; // kelurahan / desa
                    M_DoctorAddressDistrict = this.$store.state.patient.inp_CorporateAddressDistrict; // kecamatan
                    M_DoctorAddressState = this.$store.state.patient.inp_CorporateAddressState; // provinsi

                    if(!_.isEmpty(this.$store.state.patient.selected_countryCb)){
                        M_DoctorAddressCountry = this.$store.state.patient.selected_countryCb.code; // negara
                    }

                    let prm = {
                        M_DoctorID: M_DoctorID,
                        M_DoctorM_TitleID: M_DoctorM_TitleID,
                        M_DoctorCode: M_DoctorCode,
                        M_DoctorPrefix: M_DoctorPrefix,
                        M_DoctorPrefix2: M_DoctorPrefix2,
                        M_DoctorName: M_DoctorName,
                        M_DoctorSuffix: M_DoctorSuffix,
                        M_DoctorSuffix2: M_DoctorSuffix2,
                        M_DoctorGender: M_DoctorGender,
                        M_DoctorDOB: M_DoctorDOB,
                        M_DoctorReligionCode: M_DoctorReligionCode,
                        M_DoctorReligionSystem: M_DoctorReligionSystem,
                        M_DoctorBloodTypeCode: M_DoctorBloodTypeCode,
                        M_DoctorBloodTypeSystem: M_DoctorBloodTypeSystem,
                        M_DoctorBloodRhCode: M_DoctorBloodRhCode,
                        M_DoctorBloodRhSystem: M_DoctorBloodRhSystem,
                        M_DoctorEducationCode: M_DoctorEducationCode,
                        M_DoctorEducationSystem: M_DoctorEducationSystem,
                        M_DoctorCitizenship: M_DoctorCitizenship,
                        M_DoctorEtnicCode: M_DoctorEtnicCode,
                        M_DoctorEtnicSystem: M_DoctorEtnicSystem,
                        M_DoctorIdentifierCode: M_DoctorIdentifierCode,
                        M_DoctorIdentifierSystem: M_DoctorIdentifierSystem,
                        M_DoctorIdentifierValue: M_DoctorIdentifierValue,
                        M_DoctorHp: M_DoctorHp,
                        M_DoctorEmail: M_DoctorEmail,
                        M_DoctorM_SpecialistID: M_DoctorM_SpecialistID,
                        M_DoctorPhoto: M_DoctorPhoto,
                        M_DoctorAddress: M_DoctorAddress,
                        M_DoctorAddressRegionalCd: M_DoctorAddressRegionalCd,
                        M_DoctorAddressRT: M_DoctorAddressRT,
                        M_DoctorAddressRW: M_DoctorAddressRW,
                        M_DoctorAddressCity: M_DoctorAddressCity, // kabupaten / kota
                        M_DoctorAddressVillage: M_DoctorAddressVillage, // kelurahan / desa
                        M_DoctorAddressDistrict: M_DoctorAddressDistrict, // kecamatan
                        M_DoctorAddressState: M_DoctorAddressState, // provinsi
                        M_DoctorAddressCountry: M_DoctorAddressCountry // negara
                    };

                    console.log('update data baru', prm)

                    this.$store.commit("patient/update_pgrs_save", true)
                    this.$store.dispatch("patient/save", prm)
                }
            },

            newPatient() {
                this.$store.commit("patient/update_errors", [])
                var errors = this.$store.state.patient.errors
                var aDOB = moment(this.xdob, 'DD-MM-YYYY', true)
                console.log(this.xdob)
                console.log(aDOB)
                var isValidDOB = aDOB.isValid()
                if(!_.isEmpty(this.dob)){
                    if (!isValidDOB) {
                        errors.push("wrongformatdob")
                    }
                }
                
                if (this.xpatientname === '') {
                    errors.push("requirename")
                }
                // if (this.xdob === '') {
                //     errors.push("requiredob")
                // }
                if (_.isEmpty(this.xsex)) {
                    errors.push("requiresex")
                }
                // if (_.isEmpty(this.xtitle)) {
                //     errors.push("requiretitle")
                // }

                // if (_.isEmpty(this.province_address)) {
                //     errors.push("province")
                // }
                // if (_.isEmpty(this.city_address)) {
                //     errors.push("city")
                // }

                // if (_.isEmpty(this.district_address)) {
                //     errors.push("district")
                // }
                // if (_.isEmpty(this.kelurahan_address)) {
                //     errors.push("kelurahan")
                // }

                // if(_.isEmpty(this.$store.state.patient.selected_kartuidentitas)){
                //     errors.push("identity")
                // }

                // if(this.address === ''){
                //     errors.push("address")
                // }

                // variable start
                let M_DoctorID = 0;
                let M_DoctorM_TitleID = 0;
                let M_DoctorCode = "";
                let M_DoctorPrefix = "";
                let M_DoctorPrefix2 = "";
                let M_DoctorName = "";
                let M_DoctorSuffix = "";
                let M_DoctorSuffix2 = "";
                let M_DoctorGender = ""; // 'male' or 'female'
                let M_DoctorDOB = "0000-00-00";
                let M_DoctorReligionCode = "";
                let M_DoctorReligionSystem = "";
                let M_DoctorBloodTypeCode = "";
                let M_DoctorBloodTypeSystem = "";
                let M_DoctorBloodRhCode = "";
                let M_DoctorBloodRhSystem = "";
                let M_DoctorEducationCode = "";
                let M_DoctorEducationSystem = "";
                let M_DoctorCitizenship = ""; // 'WNI' or 'WNA'
                let M_DoctorEtnicCode = "";
                let M_DoctorEtnicSystem = "";
                let M_DoctorIdentifierCode = "";
                let M_DoctorIdentifierSystem = "";
                let M_DoctorIdentifierValue = "";
                let M_DoctorHp = "";
                let M_DoctorEmail = "";
                let M_DoctorM_SpecialistID = 0;
                let M_DoctorPhoto = "";
                let M_DoctorAddress = "";
                let M_DoctorAddressRegionalCd = "";
                let M_DoctorAddressRT = "";
                let M_DoctorAddressRW = "";
                let M_DoctorAddressCity = ""; // kabupaten / kota
                let M_DoctorAddressVillage = ""; // kelurahan / desa
                let M_DoctorAddressDistrict = ""; // kecamatan
                let M_DoctorAddressState = ""; // provinsi
                let M_DoctorAddressCountry = ""; // negara
                // variable end

                if (errors.length === 0) {
                    // var prm = {}

                    M_DoctorID = 0;

                    if(!_.isEmpty(this.$store.state.patient.selected_title.M_TitleID)){
                        M_DoctorM_TitleID = this.$store.state.patient.selected_title.M_TitleID
                    }

                    M_DoctorCode = "";
                    M_DoctorPrefix = this.xpatientprefix
                    M_DoctorPrefix2 = this.xpatientprefix2
                    M_DoctorName = this.xpatientname
                    M_DoctorSuffix = this.xpatientsuffix
                    M_DoctorSuffix2 = this.xpatientsuffix2
                    M_DoctorGender = this.xsex.M_DoctorGender; // 'male' or 'female'
                    // M_DoctorDOB = this.xdob

                    if(!_.isEmpty(this.xdob)){
                        M_DoctorDOB = this.xdob
                    }

                    // religion
                    if(!_.isEmpty(this.$store.state.patient.selected_religion)){
                        M_DoctorReligionCode = this.$store.state.patient.selected_religion.code
                        M_DoctorReligionSystem = this.$store.state.patient.selected_religion.code_system
                    }
                   
                    if(!_.isEmpty(this.$store.state.patient.selected_bloodtype)){
                        M_DoctorBloodTypeCode = this.$store.state.patient.selected_bloodtype.code;
                        M_DoctorBloodTypeSystem = this.$store.state.patient.selected_bloodtype.code_system;
                    }

                    if(!_.isEmpty(this.$store.state.patient.selected_bloodrh)){
                        M_DoctorBloodRhCode = this.$store.state.patient.selected_bloodrh.code;
                        M_DoctorBloodRhSystem = this.$store.state.patient.selected_bloodrh.code_system;
                    }

                    if(!_.isEmpty(this.$store.state.patient.selected_education)){
                        M_DoctorEducationCode = this.$store.state.patient.selected_education.code;
                        M_DoctorEducationSystem = this.$store.state.patient.selected_education.code_system;
                    }

                    M_DoctorCitizenship = this.xcitizenship.M_DoctorCitizenship; // 'WNI' or 'WNA'
                    
                    if(!_.isEmpty(this.$store.state.patient.selected_etnicity)){
                        M_DoctorEtnicCode = this.$store.state.patient.selected_etnicity.code;
                        M_DoctorEtnicSystem = this.$store.state.patient.selected_etnicity.code_system;
                    }

                    if(!_.isEmpty(this.$store.state.patient.selected_kartuidentitas)){
                        M_DoctorIdentifierCode = this.$store.state.patient.selected_kartuidentitas.code;
                        M_DoctorIdentifierSystem = this.$store.state.patient.selected_kartuidentitas.code_system;
                        M_DoctorIdentifierValue = this.xnoidentitas;
                    }

                    M_DoctorHp = this.$store.state.patient.hp;
                    M_DoctorEmail = this.xemail;

                    if(!_.isEmpty(this.$store.state.patient.selected_specialist)){
                        M_DoctorM_SpecialistID = this.$store.state.patient.selected_specialist.M_SpecialistID
                    }
                  
                    M_DoctorPhoto = "";
                    M_DoctorAddress = this.$store.state.patient.inp_CorporateAddress;

                    if(!_.isEmpty(this.$store.state.patient.selected_wilayahCb)){
                        M_DoctorAddressRegionalCd = this.selected_wilayahCb.regional_cd;
                    }
                   
                    M_DoctorAddressRT = this.$store.state.patient.inp_CorporateAddressRT;
                    M_DoctorAddressRW = this.$store.state.patient.inp_CorporateAddressRW;
                    M_DoctorAddressCity = this.$store.state.patient.inp_CorporateAddressCity; // kabupaten / kota
                    M_DoctorAddressVillage = this.$store.state.patient.inp_CorporateAddressVillage; // kelurahan / desa
                    M_DoctorAddressDistrict = this.$store.state.patient.inp_CorporateAddressDistrict; // kecamatan
                    M_DoctorAddressState = this.$store.state.patient.inp_CorporateAddressState; // provinsi

                    if(!_.isEmpty(this.$store.state.patient.selected_countryCb)){
                        M_DoctorAddressCountry = this.$store.state.patient.selected_countryCb.code; // negara
                    }

                    let prm = {
                        M_DoctorID: M_DoctorID,
                        M_DoctorM_TitleID: M_DoctorM_TitleID,
                        M_DoctorCode: M_DoctorCode,
                        M_DoctorPrefix: M_DoctorPrefix,
                        M_DoctorPrefix2: M_DoctorPrefix2,
                        M_DoctorName: M_DoctorName,
                        M_DoctorSuffix: M_DoctorSuffix,
                        M_DoctorSuffix2: M_DoctorSuffix2,
                        M_DoctorGender: M_DoctorGender,
                        M_DoctorDOB: M_DoctorDOB,
                        M_DoctorReligionCode: M_DoctorReligionCode,
                        M_DoctorReligionSystem: M_DoctorReligionSystem,
                        M_DoctorBloodTypeCode: M_DoctorBloodTypeCode,
                        M_DoctorBloodTypeSystem: M_DoctorBloodTypeSystem,
                        M_DoctorBloodRhCode: M_DoctorBloodRhCode,
                        M_DoctorBloodRhSystem: M_DoctorBloodRhSystem,
                        M_DoctorEducationCode: M_DoctorEducationCode,
                        M_DoctorEducationSystem: M_DoctorEducationSystem,
                        M_DoctorCitizenship: M_DoctorCitizenship,
                        M_DoctorEtnicCode: M_DoctorEtnicCode,
                        M_DoctorEtnicSystem: M_DoctorEtnicSystem,
                        M_DoctorIdentifierCode: M_DoctorIdentifierCode,
                        M_DoctorIdentifierSystem: M_DoctorIdentifierSystem,
                        M_DoctorIdentifierValue: M_DoctorIdentifierValue,
                        M_DoctorHp: M_DoctorHp,
                        M_DoctorEmail: M_DoctorEmail,
                        M_DoctorM_SpecialistID: M_DoctorM_SpecialistID,
                        M_DoctorPhoto: M_DoctorPhoto,
                        M_DoctorAddress: M_DoctorAddress,
                        M_DoctorAddressRegionalCd: M_DoctorAddressRegionalCd,
                        M_DoctorAddressRT: M_DoctorAddressRT,
                        M_DoctorAddressRW: M_DoctorAddressRW,
                        M_DoctorAddressCity: M_DoctorAddressCity, // kabupaten / kota
                        M_DoctorAddressVillage: M_DoctorAddressVillage, // kelurahan / desa
                        M_DoctorAddressDistrict: M_DoctorAddressDistrict, // kecamatan
                        M_DoctorAddressState: M_DoctorAddressState, // provinsi
                        M_DoctorAddressCountry: M_DoctorAddressCountry // negara
                    };

                    // console.log('add data baru', prm)

                    this.$store.commit("patient/update_pgrs_save", true)
                    this.$store.dispatch("patient/newpatient", prm)
                }
            },
            deleteData() {
                let msg = "Yakin, akan menghapus data pasien " + this.xpatientname + " ?"
                this.$store.commit("patient/update_msg_confirmation_delete", msg)
                this.$store.commit("patient/update_dialog_confirmation_delete", true)
            },
            doDeleteData() {
                var prm = {}
                prm.M_DoctorID = this.$store.state.patient.selected_patient.M_DoctorID
                prm.M_DoctorName = this.xpatientname
                this.$store.commit("patient/update_pgrs_save", true)
                this.$store.dispatch("patient/delete", prm)
            }
        }
    }
</script>