You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: prescription_details.rb
    path of file: ./repos/vets-api/app/models
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

class PrescriptionDetails < Prescription
  attribute :cmop_division_phone, Stri
    
  def sorted_dispensed_date
    has_refills = try(:rx_rf_records).present?
    last_refill_date = Date.new(0)

    if has_refills
      refills = rx_rf_records[0][1]

      refills.each do |r|
        last_dispensed = r.try(:[], :dispensed_date)
        next if last_dispensed.nil?

        refill_date = Date.parse(r.try(:[], :dispensed_date))
        last_refill_date = refill_date if refill_date.present? && refill_date > last_refill_date
      end
    end