class PatientImport
Constants
- CHANGESET_THRESHOLD
- PDS_MATCH_THRESHOLD
Public Instance Methods
Source
# File app/models/patient_import.rb, line 120 def commit_changesets(changesets) changesets_ids = changesets.ids changesets.update_all(status: :committing) changesets_ids.each_slice(100) do |batch_ids| CommitPatientChangesetsJob.perform_async(batch_ids) end end
Source
# File app/models/patient_import.rb, line 13 def count_column(patient, parents, parent_relationships) if patient.new_record? || parents.any?(&:new_record?) || parent_relationships.any?(&:new_record?) :new_record_count elsif patient.changed? || parents.any?(&:changed?) || parent_relationships.any?(&:changed?) :changed_record_count else :exact_duplicate_record_count end end
Source
# File app/models/patient_import.rb, line 138 def parent_relationship_consents(scope: parent_relationships) Consent .includes(patient: { parent_relationships: :parent }) .joins(patient: :parent_relationships) .merge(patients) .merge(scope) .where("consents.parent_id = parent_relationships.parent_id") .not_invalidated end
Source
# File app/models/patient_import.rb, line 70 def pds_match_rate return 0 if changesets.with_pds_match.count.zero? matched = changesets.with_pds_match.count.to_f attempted = changesets.with_pds_search_attempted.count (matched / attempted * 100).round(2) end
Source
# File app/models/patient_import.rb, line 37 def process! raise "'rows' are empty. Call parse_rows! before processing." if rows.nil? changesets = rows.each_with_index.map do |row, row_number| PatientChangeset.from_import_row(row:, import: self, row_number:) end if Flipper.enabled?(:pds) && Flipper.enabled?(:pds_search_during_import) process_no_postcode_changesets(self.changesets.without_postcode) if self.changesets.with_postcode.any? enqueue_pds_cascading_searches(self.changesets.with_postcode) return end end changesets.each(&:assign_patient_id) validate_changeset_uniqueness! return if changesets_are_invalid? enqueue_review_jobs(self.changesets) TeamCachedCounts.new(team).reset_import_issues! end
Source
# File app/models/patient_import.rb, line 33 def records_count changesets.from_file.count end
Source
# File app/models/patient_import.rb, line 129 def remaining_parent_relationships(remove_option:) if remove_option == "unconsented_only" parent_relationships - parent_relationship_consents.map(&:parent_relationship) else parent_relationships end end
Source
# File app/models/patient_import.rb, line 25 def show_approved_reviewers? (processed? || partially_processed?) && reviewed_by_user_ids.present? end
Source
# File app/models/patient_import.rb, line 29 def show_cancelled_reviewer? (cancelled? || partially_processed?) && reviewed_by_user_ids.present? end
Source
# File app/models/patient_import.rb, line 79 def validate_changeset_uniqueness! row_errors = {} nhs_duplicates = changesets .group_by(&:nhs_number) .select { |nhs, cs| nhs.present? && cs.size > 1 } nhs_duplicates.each do |nhs_number, changesets| changesets.each do |cs| other_rows_text = generate_other_rows_text(cs, changesets) row_errors["Row #{cs.csv_row_number}"] ||= [[]] row_errors["Row #{cs.csv_row_number}"][ 0 ] << "The details on this row match #{other_rows_text}. " \ "Mavis has found the NHS number #{nhs_number}." end end patient_duplicates = changesets .group_by(&:patient_id) .select { |pid, cs| pid.present? && cs.size > 1 } patient_duplicates.each_value do |changesets| changesets.each do |cs| other_rows_text = generate_other_rows_text(cs, changesets) row_errors["Row #{cs.csv_row_number}"] ||= [[]] row_errors["Row #{cs.csv_row_number}"][ 0 ] << "The record on this row appears to be a duplicate of #{other_rows_text}." end end if row_errors.any? update!(status: :changesets_are_invalid) update!(serialized_errors: row_errors) changesets.update_all(status: :import_invalid) end end
Source
# File app/models/patient_import.rb, line 63 def validate_pds_match_rate! return if valid_pds_match_rate? || changesets.count < CHANGESET_THRESHOLD update!(status: :low_pds_match_rate) changesets.update_all(status: :import_invalid) end