<template>
   <v-layout fil-height column>
      <v-card class="mb-2">
         <v-subheader>
            DATA PASIEN
         </v-subheader>
         <v-divider></v-divider>
         <v-layout row wrap>
            <v-flex xs12>
               <v-layout>
                  <v-flex xs3 pa-2>
                     <v-layout row wrap>
                        <v-flex xs12>
                           <v-img
                              src="https://www.sgm-inc.com/wp-content/uploads/2014/06/no-profile-male-img.gif"
                              aspect-ratio="1"
                              class="grey lighten-2 elevation-2"
                              >
                        </v-flex>
                  </v-flex>
                  <v-flex xs9>
                     <v-flex xs12>
                        <v-layout>
                           <v-flex xs7 pa-1>
                              <v-text-field
                                 label="Nama"
                                 placeholder=""
                                 :value="getField(patient.M_PatientName)"
                                 readonly
                                 ></v-text-field>
                           </v-flex>
                           <v-flex xs5 pa-1>
                              <v-text-field
                                 label="RM"
                                 placeholder=""
                                 :value="getField(patient.M_PatientNoReg)"
                                 readonly
                                 ></v-text-field>
                           </v-flex>
                        </v-layout>
                     </v-flex>
                     <v-flex xs12 pa-1>
                        <v-textarea
                           auto-grow
                           label="Alamat"
                           rows="2"
                           :value="getAddress(patient)"
                           readonly
                           ></v-textarea>
                     </v-flex>
                     <v-flex xs12>
                        <v-layout>
                           <v-flex xs7 pa-1>
                              <v-text-field
                                 label="Telephon / HP"
                                 placeholder=""
                                 :value="getField(patient.M_PatientHP)"
                                 readonly
                                 ></v-text-field>
                           </v-flex>
                           <v-flex xs5 pa-1>
                              <v-text-field
                                 label="Jenis Kelamin"
                                 placeholder=""
                                 :value="getField(patient.M_SexName)"
                                 readonly
                                 ></v-text-field>
                           </v-flex>
                        </v-layout>
                     </v-flex>
                     <v-flex xs12>
                        <v-layout>
                           <v-flex xs7 pa-1>
                              <v-text-field
                                 label="Tanggal Lahir"
                                 placeholder=""
                                 :value="getField(patient.M_PatientDOB)"
                                 readonly
                                 ></v-text-field>
                           </v-flex>

                           <v-flex xs5 pa-1>
                              <v-text-field
                                 label="Umur"
                                 placeholder=""
                                 :value="patient_age"
                                 readonly
                                 ></v-text-field>
                           </v-flex>
                        </v-layout>
                     </v-flex>
                  </v-flex>
               </v-layout>
            </v-flex>

            <v-layout row wrap>
               <v-flex xs6 pa-2 v-for="(vp,idx) in vpatient" :key="vp.id">
                  <one-field-verification-patient-doctor
                     :xdatalabel="vp.label"
                     :xdatacbx="vp.check"
                     :xdatatxt="vp.note"
                     @update-data-txt="(val) => updateDataTxtParentPatient(idx,val)"
                     @update-data-cbx="(val) => updateDataCbxParentPatient(idx,val)"
                  ></one-field-verification-patient-doctor>
               </v-flex>
            </v-layout>
      </v-card>

      <v-card >
         <v-subheader>
            DATA DOKTER
         </v-subheader>
         <v-divider></v-divider>
         <v-flex pt-2 xs12>
            <v-layout>
               <v-flex xs6 pl-5 pr-3>
                  <v-text-field
                     label="Nama"
                     placeholder=""
                     :value="getField(patient.M_DoctorName)"
                     readonly
                     ></v-text-field>
               </v-flex>
               <v-flex xs6 pl-5 pr-3>
                  <v-text-field
                     label="Alamat"
                     placeholder=""
                     :value="getField(patient.M_DoctorAddress)"
                     readonly
                     ></v-text-field>
               </v-flex>
            </v-layout>
         </v-flex>
         <v-flex xs12 >
            <v-layout row wrap>
               <v-flex xs6 pa-2 v-for="(vp,idx) in vdoctor" :key="vp.id">
                  <one-field-verification-patient-doctor
                     :xdatalabel="vp.label"
                     :xdatacbx="vp.check"
                     :xdatatxt="vp.note"
                     @update-data-txt="(val) => updateDataTxtParentDoctor(idx,val)"
                     @update-data-cbx="(val) => updateDataCbxParentDoctor(idx,val)"
                  ></one-field-verification-patient-doctor>
               </v-flex>
            </v-layout>
         </v-flex>
      </v-card>
   </v-layout>
</template>

<style scoped>
</style>

<script>
module.exports = {
   components : {
      'one-field-verification' : httpVueLoader('../../common/oneFieldVerification.1.vue'),
      'one-testing-component':httpVueLoader('../../common/oneTestingComponent.vue'),
      'one-field-verification-patient-doctor':httpVueLoader('../../common/oneFieldVerificationPatientDoctor.vue')
   },
   computed: {
      patient_age() {
         if ( this.patient == undefined) {
            return ''
         }
         return window.calculate_age(this.patient.M_PatientDOB)
      },
      patient() {
         return this.$store.state.patient.selected_patient
      },
      vpatient() {
         return this.$store.state.verification.verification_patient
      },
      vdoctor() {
         return this.$store.state.verificationdoctor.verification
      }
   },
   methods : {
      getAddress(patient) {
         if ( patient == undefined) {
            return ''
         }
         if (patient.address == undefined  ) return ''
         if (patient.address.length == 0) return ''
         return patient.address[0]
      },
      getField(inp) {
         if ( this.patient != undefined) {
            return inp
         }
         return ''
      },
      getError(inp) {
         if ( this.patient != undefined) {
            return inp
         }
         return ''
      },
      updateDataTxtParentPatient(idx, val) {
         var prm = {idx:idx,val:val}
         this.$store.commit("verification/update_testing_txt_parent_patient",prm)  
      },
      updateDataCbxParentPatient(idx, val) {
         var prm = {idx:idx,val:val}
         this.$store.commit("verification/update_testing_cbx_parent_patient",prm)  
      },
      updateDataTxtParentDoctor(idx, val) {
         var prm = {idx:idx,val:val}
         this.$store.commit("verification/update_testing_txt_parent_doctor",prm)  
      },
      updateDataCbxParentDoctor(idx, val) {
         var prm = {idx:idx,val:val}
         this.$store.commit("verification/update_testing_cbx_parent_doctor",prm)  
      }
   }
}
</script>
