<commit_before>require 'ostruct'
# require_relative './clinic_finder/gestation_helper'
# require_relative 'clinic_finder/affordability_helper'

# Use as follows:
# pt = Patient.find('123');
# finder = ClinicFinder::Locator.new(
#   Clinic.all,
#   gestational_age: pt.gestational_age, # in days
#   naf_only: true, # Limit results to NAF clinics
#   medicaid_only: true # Limit results to Medicaid clinics
# )
# finder.locate_nearest_clinics pt.zip, limit: 5
# finder.locate_cheapest_clinics limit: 5
module ClinicFinder
  # Core class for accessing stuff. The good stuff is:
  # * ClinicFinder::Locator#locate_nearest_clinics
  # * ClinicFinder::Locator#locate_cheapest_clinics
  class Locator
    include ClinicFinder::Modules::Geocoder

    attr_accessor :clinics
    attr_accessor :patient_context # no reason to not assign this to an obj lvl
    attr_accessor :geocoder

    def initialize(clinics, gestational_age: 0,
                   naf_only: false, medicaid_only: false)
      @clinics = filter_by_params clinics,
                                  gestational_age,
                                  naf_only,
                                  medicaid_only

      @clinic_structs = build_clinic_structs
      @patient_context = OpenStruct.new
      @geocoder = set_geocoder
    end

    # Return a set of the closest clinics as structs and their attributes,
    # distance included, to a patient's zipcode.
    def locate_nearest_clinics(zipcode, limit: 5)
      @patient_context.location = patient_coordinates_from_zip zipcode
      add_distances_to_clinic_openstructs

      @clinic_structs.sort_by(&:distance).take(limit)
    end

    # Return a set of the cheapest clinics and their attributes.<commit_msg>correct test failure in clinic_finders test<commit_after>require 'ostruct'
# require_relative './clinic_finder/gestation_helper'
# require_relative 'clinic_finder/affordability_helper'

# Use as follows:
# pt = Patient.find('123');
# finder = ClinicFinder::Locator.new(
#   Clinic.all,
#   gestational_age: pt.gestational_age, # in days
#   naf_only: true, # Limit results to NAF clinics
#   medicaid_only: true # Limit results to Medicaid clinics
# )
# finder.locate_nearest_clinics pt.zip, limit: 5
# finder.locate_cheapest_clinics limit: 5
module ClinicFinder
  # Core class for accessing stuff. The good stuff is:
  # * ClinicFinder::Locator#locate_nearest_clinics
  # * ClinicFinder::Locator#locate_cheapest_clinics
  class Locator
    include ClinicFinder::Modules::Geocoder

    attr_accessor :clinics
    attr_accessor :clinic_structs
    attr_accessor :patient_context # no reason to not assign this to an obj lvl
    attr_accessor :geocoder

    def initialize(clinics, gestational_age: 0,
                   naf_only: false, medicaid_only: false)
      @clinics = filter_by_params clinics,
                                  gestational_age,
                                  naf_only,
                                  medicaid_only

      @clinic_structs = build_clinic_structs
      @patient_context = OpenStruct.new
      @geocoder = set_geocoder
    end

    # Return a set of the closest clinics as structs and their attributes,
    # distance included, to a patient's zipcode.
    def locate_nearest_clinics(zipcode, limit: 5)
      @patient_context.location = patient_coordinates_from_zip zipcode
      add_distances_to_clinic_openstructs

      @clinic_structs.sort_by(&:distance).take(limit)
    end

    # Return a set of the cheapest clinics and their attributes.
{'fraction_non_alphanumeric': 0.06930975470621792, 'fraction_numerical': 0.003993154592127781, 'mean_word_length': 3.215144230769231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7541489', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1047, 'n_words': 268}