<commit_before>require_dependency "renalware/hd"

module Renalware
  module HD
    class SessionFactory
      attr_reader :patient, :user

      def initialize(patient:, user:)
        @patient = patient
        @user = user
      end

      def build
        session = Session.new(
          performed_on: Time.zone.today,
          signed_on_by: user,
          start_time: Time.zone.now.change(min: (Time.zone.now.min/5)*5)
        )
        Profile.for_patient(patient).first.tap do |profile|
          session.hospital_unit = profile.hospital_unit
          session.document.info.hd_type = profile.document.dialysis.hd_type
        end

        session
      end
    end
  end
end<commit_msg>Get the access information from the current access profile<commit_after>require_dependency "renalware/hd"

module Renalware
  module HD
    class SessionFactory
      attr_reader :patient, :user

      def initialize(patient:, user:)
        @patient = patient
        @user = user
      end

      def build
        session = Session.new(
          performed_on: Time.zone.today,
          signed_on_by: user,
          start_time: Time.zone.now.change(min: (Time.zone.now.min/5)*5)
        )
        Profile.for_patient(patient).first.tap do |profile|
          if profile
            session.hospital_unit = profile.hospital_unit
            session.document.info.hd_type = profile.document.dialysis.hd_type
          end
        end

        Accesses::Profile.current_for_patient(patient).tap do |profile|
          if profile
            session.document.info.access_type = profile.type.name
            session.document.info.access_site = profile.site.name
            session.document.info.access_side = profile.side
          end
        end

        session
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07984366275823562, 'fraction_numerical': 0.002233389168062535, 'mean_word_length': 2.0632478632478635, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1202980', 'n_tokens_mistral': 523, 'n_tokens_neox': 502, 'n_words': 109}