Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Reservation::DoctorReservationFormLogV210
- include ActiveModel::Model
- MALE = 'male'.freeze
- FEMALE = 'female'.freeze
- BPJS = 'bpjs'.freeze
- EMAIL_REGEX = /\A[\w\.-]+@([\w-]+\.)+[\w-]+\z/
- attr_accessor :id,
- :user_id,
- :key,
- :doctor_id,
- :hospital_id,
- :funnel_name,
- :price,
- :doctor_name,
- :doctor_speciality,
- :hospital_name,
- :reservation_date,
- :reservation_time,
- :user_name,
- :gender,
- :user_phone,
- :user_email,
- :user_birthday,
- :follow,
- :source,
- :schedule_id,
- :feedback_status,
- :confirmation_status,
- :bitrix_status,
- :last_bitrix_update,
- :bitrix_id,
- :booking_id,
- :is_new_patient,
- :id_number,
- :address,
- :payment_method,
- :occupation,
- :religion,
- :fit_to_fly_letter,
- :blood_type,
- :legal_guardian_name,
- :confirmation_url,
- :feedback_url,
- :confirmation_pdf_url,
- :reservation,
- :bitrix_schedule_date,
- :booking_version,
- :is_dashboard,
- :is_cancel_acknowledged,
- :queue_number,
- :form_2_rs_api_status,
- :update_booking_rs_api_status
- attr_reader :doctor_reservation
- # Validations
- validate :user_must_valid
- def valid?
- @doctor_reservation = build_doctor_reservation
- super
- end
- def save
- puts "==============ada di doctor reservation save==============="
- if valid?
- puts "==============lolos validasi==============="
- @doctor_reservation = build_doctor_reservation
- @doctor_reservation.set_created_at
- begin
- @doctor_reservation.save!
- true
- rescue => e
- puts e.inspect
- puts e.backtrace
- errors.add(:base, "Input data failed")
- @doctor_reservation.errors
- .full_messages
- .each{|error_message| errors.add(:base, error_message)}
- false
- end
- else
- @doctor_reservation.errors
- .full_messages
- .each{|error_message| errors.add(:base, error_message)}
- false
- end
- end
- def update
- begin
- @doctor_reservation = Reservation::DoctorReservationLog.find_by(booking_id: self.booking_id)
- @doctor_reservation.update_attributes!(
- last_bitrix_update: self.last_bitrix_update || @doctor_reservation.last_bitrix_update,
- confirmation_pdf_url: self.confirmation_pdf_url || @doctor_reservation.confirmation_pdf_url,
- feedback_status: self.feedback_status || @doctor_reservation.feedback_status,
- bitrix_status: self.bitrix_status || @doctor_reservation.bitrix_status,
- queue_number: self.queue_number || @doctor_reservation.queue_number,
- confirmation_status: self.confirmation_status || @doctor_reservation.confirmation_status)
- true
- rescue
- false
- end
- end
- def valid_reservation_additional?
- @doctor_reservation = Reservation::DoctorReservationLog.find_by(booking_id: self.booking_id)#, bitrix_status: 'pending')
- if @doctor_reservation.blank?
- errors.add(:base, "Booking ID harus valid")
- return false
- end
- if @doctor_reservation.bitrix_id.present? && @doctor_reservation.bitrix_status != 'pending'
- puts "Booking Sudah disimpan"
- errors.add(:base, "Booking Sudah disimpan")
- puts "end Booking Sudah disimpan"
- return false
- end
- puts "=============inilah isinya rs api status di valid additional: "
- puts self.form_2_rs_api_status
- @doctor_reservation[:form_2_rs_api_status] = self.form_2_rs_api_status
- prefilling_book_doctors = Reservation::PrefillingBookDoctor.where(show: true)
- prefilling_book_doctors.each do|prefilling_book_doctor|
- field_value = self.try(prefilling_book_doctor.field_name)
- @doctor_reservation[prefilling_book_doctor.field_name] = field_value
- if field_value.blank? && prefilling_book_doctor.mandatory
- errors.add(:base, "#{prefilling_book_doctor.field_placeholder} harus diisi")
- end
- end
- if errors.full_messages.length > 1
- puts "errors"
- puts errors.inspect
- errors.clear
- errors.add(:base, 'Mohon Lengkapi Data Pasien')
- end
- errors.full_messages.empty? && @doctor_reservation.valid?
- end
- private
- def booking_id_must_valid
- if self.booking_id.blank?
- errors.add(:base, "Booking ID harus valid")
- end
- end
- def doctor_id_must_not_empty
- if self.doctor_id.blank?
- errors.add(:base, "Doctor ID harus valid")
- end
- end
- def schedule_id_must_not_empty
- if self.schedule_id.blank?
- errors.add(:base, "Jadwal Konsultasi harus diisi")
- end
- end
- def reservation_date_must_valid
- if reservation_date.present?
- begin
- DateTime.strptime(reservation_date, '%d %b %Y')
- return
- rescue
- begin
- DateTime.strptime(reservation_date, '%-d %b %Y')
- return
- rescue
- begin
- DateTime.strptime(reservation_date, '%d/%m/%Y')
- return
- rescue
- begin
- DateTime.strptime(reservation_date, '%-d/%-m/%Y')
- return
- rescue
- begin
- DateTime.strptime(reservation_date, '%Y-%m-%d')
- return
- rescue
- begin
- DateTime.strptime(reservation_date, '%Y-%-m-%-d')
- return
- rescue
- errors.add(:base, 'Tanggal reservasi harus valid')
- end
- end
- end
- end
- end
- end
- else
- errors.add(:base, 'Tanggal reservasi harus valid')
- end
- end
- def user_birthday_must_valid
- if user_birthday.present?
- begin
- DateTime.strptime(user_birthday, '%d %b %Y')
- return
- rescue
- begin
- DateTime.strptime(user_birthday, '%-d %b %Y')
- return
- rescue
- begin
- DateTime.strptime(user_birthday, '%d/%m/%Y')
- return
- rescue
- begin
- DateTime.strptime(user_birthday, '%-d/%-m/%Y')
- return
- rescue
- begin
- DateTime.strptime(user_birthday, '%Y-%m-%d')
- return
- rescue
- begin
- DateTime.strptime(user_birthday, '%Y-%-m-%-d')
- return
- rescue
- errors.add(:base, 'Tanggal lahir harus valid')
- end
- end
- end
- end
- end
- end
- else
- errors.add(:base, 'Tanggal lahir harus valid')
- end
- end
- def email_must_valid
- if user_email.blank?
- errors.add(:base, 'Email harus diisi')
- elsif !(user_email =~ EMAIL_REGEX)
- errors.add(:base, 'Email harus valid')
- end
- end
- def phone_must_valid
- if user_phone.blank?
- errors.add(:base, 'Nomor Telepon harus diisi')
- elsif !(user_phone =~/^[0-9]{4,15}$/)
- errors.add(:base, 'Nomor Telepon harus valid')
- end
- end
- def user_must_valid
- errors.add(:base, 'Nama harus diisi') if self.user_name.blank?
- end
- def build_doctor_reservation
- Reservation::DoctorReservationLog.new(
- doctor_id: self.doctor_id,
- key:self.key,
- initial_doctor_id: self.doctor_id,
- doctor_name: self.doctor_name,
- initial_doctor_name: self.doctor_name,
- doctor_speciality: self.doctor_speciality,
- initial_doctor_speciality: self.doctor_speciality,
- hospital_id: self.hospital_id,
- funnel_name: self.funnel_name,
- patient_name: self.user_name,
- price: self.price,
- hospital_name: self.hospital_name,
- schedule_date: self.reservation_date,
- initial_schedule_date: self.reservation_date,
- initial_schedule_time: self.reservation_time,
- schedule_time: self.reservation_time,
- gender: self.gender,
- phone: self.user_phone,
- email: self.user_email,
- birthday: self.user_birthday,
- follow: self.follow,
- schedule_id: self.schedule_id,
- source: self.source,
- booking_version: self.booking_version,
- booking_id: self.booking_id,
- is_new_patient: self.is_new_patient,
- id_number: self.id_number,
- address: self.address,
- payment_method: self.payment_method,
- occupation: self.occupation,
- religion: self.religion,
- fit_to_fly_letter: self.fit_to_fly_letter,
- blood_type: self.blood_type,
- last_bitrix_update: self.last_bitrix_update,
- confirmation_url: self.confirmation_url,
- confirmation_pdf_url: self.confirmation_pdf_url,
- feedback_url: self.feedback_url,
- legal_guardian_name: self.legal_guardian_name,
- is_dashboard: self.is_dashboard,
- bitrix_status: self.bitrix_status,
- is_cancel_acknowledged: self.is_cancel_acknowledged,
- queue_number: self.queue_number,
- form_2_rs_api_status: self.form_2_rs_api_status,
- fullname_patient: fullname_patient,
- insurance_id: insurance_id,
- insurance_name: insurance_name,
- update_booking_rs_api_status: self.update_booking_rs_api_status
- )
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement