dde_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +37 -0
- data/Rakefile +12 -0
- data/app/assets/config/dde_client_manifest.js +1 -0
- data/app/assets/stylesheets/dde_client/application.css +15 -0
- data/app/controllers/dde_client/api/v1/dde_controller.rb +92 -0
- data/app/controllers/dde_client/api/v1/rollback_controller.rb +25 -0
- data/app/controllers/dde_client/application_controller.rb +4 -0
- data/app/helpers/dde/application_helper.rb +4 -0
- data/app/jobs/dde/application_job.rb +4 -0
- data/app/mailers/dde/application_mailer.rb +6 -0
- data/app/models/dde/application_record.rb +5 -0
- data/app/services/dde_client/dde_client.rb +162 -0
- data/app/services/dde_client/dde_service.rb +643 -0
- data/app/services/dde_client/matcher.rb +92 -0
- data/app/services/dde_client/merging_service.rb +769 -0
- data/app/services/dde_client/rollback_service.rb +320 -0
- data/app/services/merge_audit_service.rb +56 -0
- data/app/utils/model_utils.rb +62 -0
- data/app/views/layouts/dde/application.html.erb +15 -0
- data/config/routes.rb +14 -0
- data/lib/dde_client/client_error.rb +3 -0
- data/lib/dde_client/engine.rb +5 -0
- data/lib/dde_client/version.rb +5 -0
- data/lib/dde_client.rb +9 -0
- metadata +100 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DdeService
|
4
|
+
##
|
5
|
+
# Matches local and remote (Dde) people.
|
6
|
+
#
|
7
|
+
# TODO: Move module to own file
|
8
|
+
module Matcher
|
9
|
+
class << self
|
10
|
+
def find_differences(local_person, remote_person)
|
11
|
+
FIELDS_TO_MATCH
|
12
|
+
.map { |field| [field, diff_field(field, local_person, remote_person)] }
|
13
|
+
.reject { |_field, diff| diff.nil? }
|
14
|
+
.each_with_object({}) { |sub_diff, diff| diff[sub_diff[0]] = sub_diff[1] }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
FIELDS_TO_MATCH = %w[given_name family_name birthdate birthdate_estimated gender
|
20
|
+
current_village current_traditional_authority current_district
|
21
|
+
home_village home_traditional_authority home_district
|
22
|
+
npid].freeze
|
23
|
+
|
24
|
+
LOCATION_FIELDS = %w[current_village current_traditional_authority current_district
|
25
|
+
home_village home_traditional_authority home_district].freeze
|
26
|
+
|
27
|
+
def diff_field(field, local_person, remote_person)
|
28
|
+
return diff_location(field, local_person, remote_person) if LOCATION_FIELDS.include?(field)
|
29
|
+
|
30
|
+
send("diff_#{field}", local_person, remote_person)
|
31
|
+
end
|
32
|
+
|
33
|
+
def diff_given_name(local_person, remote_person)
|
34
|
+
local_name = PersonName.find_by_person_id(local_person.person_id)
|
35
|
+
|
36
|
+
return nil if local_name&.given_name&.casecmp?(remote_person['given_name'])
|
37
|
+
|
38
|
+
{ local: local_name.given_name, remote: remote_person['given_name'] }
|
39
|
+
end
|
40
|
+
|
41
|
+
def diff_family_name(local_person, remote_person)
|
42
|
+
local_name = PersonName.find_by_person_id(local_person.person_id)
|
43
|
+
|
44
|
+
return nil if local_name&.family_name&.casecmp?(remote_person['family_name'])
|
45
|
+
|
46
|
+
{ local: local_name.family_name, remote: remote_person['family_name'] }
|
47
|
+
end
|
48
|
+
|
49
|
+
def diff_birthdate(local_person, remote_person)
|
50
|
+
return nil if local_person.birthdate&.to_date == remote_person['birthdate'].to_date
|
51
|
+
|
52
|
+
{ local: local_person.birthdate, remote: remote_person['birthdate'] }
|
53
|
+
end
|
54
|
+
|
55
|
+
def diff_birthdate_estimated(local_person, remote_person)
|
56
|
+
birthdate_estimated = local_person.birthdate_estimated.positive?
|
57
|
+
|
58
|
+
return nil if birthdate_estimated == remote_person['birthdate_estimated']
|
59
|
+
|
60
|
+
{ local: birthdate_estimated, remote: remote_person['birthdate_estimated'] }
|
61
|
+
end
|
62
|
+
|
63
|
+
def diff_gender(local_person, remote_person)
|
64
|
+
return nil if local_person.gender.first.casecmp?(remote_person['gender'].first)
|
65
|
+
|
66
|
+
{ local: local_person.gender, remote: remote_person['gender'] }
|
67
|
+
end
|
68
|
+
|
69
|
+
def diff_npid(local_person, remote_person)
|
70
|
+
npid_type = PatientIdentifierType.where(name: 'National id')
|
71
|
+
local_npid = PatientIdentifier.find_by(patient_id: local_person.person_id, identifier_type: npid_type)&.identifier
|
72
|
+
|
73
|
+
return nil if local_npid&.casecmp?(remote_person['npid'])
|
74
|
+
|
75
|
+
{ local: local_npid, remote: remote_person['npid'] }
|
76
|
+
end
|
77
|
+
|
78
|
+
def diff_location(field, local_person, remote_person)
|
79
|
+
local_address = PersonAddress.find_by_person_id(local_person.person_id)
|
80
|
+
remote_address = remote_person['attributes']
|
81
|
+
|
82
|
+
return nil if local_address.send(field).casecmp?(remote_address[field])
|
83
|
+
{ local: local_address.send(field), remote: remote_address[field] }
|
84
|
+
end
|
85
|
+
|
86
|
+
def current_location_id
|
87
|
+
Location.current_health_center.location_id
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|