Class: DdeClient::RollbackService

Inherits:
Object
  • Object
show all
Defined in:
app/services/dde_client/rollback_service.rb

Overview

this class will basically handle rolling back patients that were merged rubocop:disable Metrics/ClassLength

Constant Summary collapse

Dde_CONFIG_PATH =
'config/application.yml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#merge_typeObject

Returns the value of attribute merge_type.



6
7
8
# File 'app/services/dde_client/rollback_service.rb', line 6

def merge_type
  @merge_type
end

#primary_patientObject

Returns the value of attribute primary_patient.



6
7
8
# File 'app/services/dde_client/rollback_service.rb', line 6

def primary_patient
  @primary_patient
end

#secondary_patientObject

Returns the value of attribute secondary_patient.



6
7
8
# File 'app/services/dde_client/rollback_service.rb', line 6

def secondary_patient
  @secondary_patient
end

#visit_typeObject

Returns the value of attribute visit_type.



6
7
8
# File 'app/services/dde_client/rollback_service.rb', line 6

def visit_type
  @visit_type
end

Instance Method Details

#rollback_merged_patient(patient_id, visit_type_id) ⇒ Object

rubocop:disable Metrics/MethodLength



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/dde_client/rollback_service.rb', line 11

def rollback_merged_patient(patient_id, visit_type_id)
  @visit_type = VisitType.find(visit_type_id)
  tree = DdeClient::MergeAuditService.new.fetch_merge_audit(patient_id)
  ActiveRecord::Base.transaction do
    tree.each do |record|
      @primary_patient = record['primary_id']
      @secondary_patient = record['secondary_id']
      @merge_type = record['merge_type']
      Rails.logger.debug("Processing rollback for patients: #{primary_patient} <=> #{secondary_patient}")
      process_rollback
      MergeAudit.find(record['id']).void("Rolling back to #{secondary_patient}")
      @common_void_reason = nil
    end
  end
  Patient.find(patient_id)
end