nuva 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/Code_pb.rb +17 -0
- data/lib/Disease_pb.rb +27 -0
- data/lib/InjectionMethod_pb.rb +21 -0
- data/lib/NuvaDatabase_pb.rb +27 -0
- data/lib/Vaccine_pb.rb +32 -0
- data/lib/Valence_pb.rb +28 -0
- data/lib/VersionInfo_pb.rb +18 -0
- data/lib/nuva.rb +75 -0
- data/lib/queries.rb +247 -0
- data/lib/repositories/disease_repository.rb +4 -0
- data/lib/repositories/vaccine_repository.rb +4 -0
- data/lib/repositories/valence_repository.rb +26 -0
- data/lib/repository.rb +35 -0
- data/lib/version.rb +3 -0
- data/nuva.gemspec +16 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e148630bce72f2f69b968c056be4d444aace8d18315310357a05f6f4caff9c6
|
4
|
+
data.tar.gz: '07290eea14dcd22ba6fd882d5b76bca612cb31c8a7d323561bd694d61179742b'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edb17bf2804b877d575416e27c59bc2833e5f78a13b3521815a3b4de2f6112d741ea45f58578b35955bb09c51dfc3a745578ace6fb245b870fd4dc1bd8b7f02e
|
7
|
+
data.tar.gz: be3a3e224cc7900e34d9add113e7989058e22db563fc81645707d101fde200baffb8ba40e491d1ac0fb73148af0bcd1e27d42750044f7a59fd283f40476454cf
|
data/lib/Code_pb.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: Code.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("Code.proto", :syntax => :proto2) do
|
8
|
+
add_message "nuva.Code" do
|
9
|
+
required :nomenclature, :string, 1
|
10
|
+
required :value, :string, 2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Nuva
|
16
|
+
Code = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("nuva.Code").msgclass
|
17
|
+
end
|
data/lib/Disease_pb.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: Disease.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
require 'google/protobuf/timestamp_pb'
|
7
|
+
require_relative 'Code_pb'
|
8
|
+
|
9
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
10
|
+
add_file("Disease.proto", :syntax => :proto2) do
|
11
|
+
add_message "nuva.Disease" do
|
12
|
+
required :id, :string, 1
|
13
|
+
required :name, :string, 2
|
14
|
+
required :code, :uint32, 3
|
15
|
+
repeated :codes, :message, 4, "nuva.Code"
|
16
|
+
required :vaccinable, :bool, 5
|
17
|
+
required :screenable, :bool, 6
|
18
|
+
repeated :valence_ids, :string, 7
|
19
|
+
optional :created_at, :message, 16, "google.protobuf.Timestamp"
|
20
|
+
optional :updated_at, :message, 17, "google.protobuf.Timestamp"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Nuva
|
26
|
+
Disease = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("nuva.Disease").msgclass
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: InjectionMethod.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("InjectionMethod.proto", :syntax => :proto2) do
|
8
|
+
add_enum "nuva.InjectionMethod" do
|
9
|
+
value :UnspecifiedInjectionMethod, 0
|
10
|
+
value :Intramuscular, 1
|
11
|
+
value :Subcutaneous, 2
|
12
|
+
value :Oral, 3
|
13
|
+
value :Intranasal, 4
|
14
|
+
value :Intradermal, 5
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Nuva
|
20
|
+
InjectionMethod = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("nuva.InjectionMethod").enummodule
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: NuvaDatabase.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
require 'google/protobuf/timestamp_pb'
|
7
|
+
require_relative 'VersionInfo_pb'
|
8
|
+
require_relative 'Vaccine_pb'
|
9
|
+
require_relative 'Disease_pb'
|
10
|
+
require_relative 'Valence_pb'
|
11
|
+
|
12
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
13
|
+
add_file("NuvaDatabase.proto", :syntax => :proto2) do
|
14
|
+
add_message "nuva.NuvaDatabase" do
|
15
|
+
required :version, :message, 1, "nuva.VersionInfo"
|
16
|
+
required :generated_at, :message, 2, "google.protobuf.Timestamp"
|
17
|
+
required :locale, :string, 3
|
18
|
+
repeated :vaccines, :message, 4, "nuva.Vaccine"
|
19
|
+
repeated :diseases, :message, 5, "nuva.Disease"
|
20
|
+
repeated :valences, :message, 6, "nuva.Valence"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Nuva
|
26
|
+
NuvaDatabase = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("nuva.NuvaDatabase").msgclass
|
27
|
+
end
|
data/lib/Vaccine_pb.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: Vaccine.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
require 'google/protobuf/timestamp_pb'
|
7
|
+
require_relative 'InjectionMethod_pb'
|
8
|
+
require_relative 'Code_pb'
|
9
|
+
|
10
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
11
|
+
add_file("Vaccine.proto", :syntax => :proto2) do
|
12
|
+
add_message "nuva.Vaccine" do
|
13
|
+
required :id, :string, 1
|
14
|
+
required :name, :string, 2
|
15
|
+
required :short_description, :string, 3
|
16
|
+
required :description, :string, 4
|
17
|
+
repeated :injection_methods, :enum, 5, "nuva.InjectionMethod"
|
18
|
+
required :code, :uint32, 6
|
19
|
+
repeated :codes, :message, 7, "nuva.Code"
|
20
|
+
repeated :valence_ids, :string, 8
|
21
|
+
repeated :other_names, :string, 9
|
22
|
+
required :generic, :bool, 10
|
23
|
+
optional :replaced_by_id, :string, 11
|
24
|
+
required :created_at, :message, 16, "google.protobuf.Timestamp"
|
25
|
+
required :updated_at, :message, 17, "google.protobuf.Timestamp"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Nuva
|
31
|
+
Vaccine = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("nuva.Vaccine").msgclass
|
32
|
+
end
|
data/lib/Valence_pb.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: Valence.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
require 'google/protobuf/timestamp_pb'
|
7
|
+
|
8
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
|
+
add_file("Valence.proto", :syntax => :proto2) do
|
10
|
+
add_message "nuva.Valence" do
|
11
|
+
required :id, :string, 1
|
12
|
+
required :parent_id, :string, 2
|
13
|
+
required :code, :uint32, 3
|
14
|
+
required :name, :string, 4
|
15
|
+
required :abbreviation, :string, 5
|
16
|
+
optional :translated_abbreviation, :string, 6
|
17
|
+
repeated :disease_ids, :string, 7
|
18
|
+
repeated :vaccine_ids, :string, 8
|
19
|
+
optional :antigene_type, :string, 9
|
20
|
+
required :created_at, :message, 16, "google.protobuf.Timestamp"
|
21
|
+
required :updated_at, :message, 17, "google.protobuf.Timestamp"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Nuva
|
27
|
+
Valence = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("nuva.Valence").msgclass
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: VersionInfo.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("VersionInfo.proto", :syntax => :proto2) do
|
8
|
+
add_message "nuva.VersionInfo" do
|
9
|
+
required :major, :uint32, 1
|
10
|
+
required :minor, :uint32, 2
|
11
|
+
required :patch, :uint32, 3
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Nuva
|
17
|
+
VersionInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("nuva.VersionInfo").msgclass
|
18
|
+
end
|
data/lib/nuva.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative './version'
|
2
|
+
require_relative './NuvaDatabase_pb'
|
3
|
+
require_relative './repository'
|
4
|
+
require_relative './queries'
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
module Nuva
|
10
|
+
class Nuva
|
11
|
+
attr_reader :repositories
|
12
|
+
attr_reader :queries
|
13
|
+
|
14
|
+
def initialize(db)
|
15
|
+
@db = db
|
16
|
+
|
17
|
+
@repositories = OpenStruct.new
|
18
|
+
@repositories.vaccines = VaccineRepository.new db.vaccines
|
19
|
+
@repositories.valences = ValenceRepository.new db.valences
|
20
|
+
@repositories.diseases = DiseaseRepository.new db.diseases
|
21
|
+
@repositories.freeze
|
22
|
+
|
23
|
+
@queries = OpenStruct.new
|
24
|
+
@queries.valences_by_vaccine = ::Nuva::Queries::ValencesByVaccine.new @repositories
|
25
|
+
@queries.vaccines_by_valence = ::Nuva::Queries::VaccinesByValence.new @repositories
|
26
|
+
@queries.vaccines_by_disease = ::Nuva::Queries::VaccinesByDisease.new @repositories
|
27
|
+
@queries.valences_by_disease = ::Nuva::Queries::ValencesByDisease.new @repositories
|
28
|
+
@queries.diseases_by_vaccine = ::Nuva::Queries::DiseasesByVaccine.new @repositories
|
29
|
+
@queries.diseases_by_valence = ::Nuva::Queries::DiseasesByValence.new @repositories
|
30
|
+
@queries.vaccine_fuzzy_search = ::Nuva::Queries::VaccineFuzzySearch.new @repositories
|
31
|
+
@queries.lookup_vaccine_by_code = ::Nuva::Queries::LookupVaccineByCode.new @repositories
|
32
|
+
@queries.lookup_equivalent_vaccines = ::Nuva::Queries::LookupEquivalentVaccines.new @repositories
|
33
|
+
@queries.lookup_specialized_vaccines = ::Nuva::Queries::LookupSpecializedVaccines.new @repositories, @queries.valences_by_vaccine
|
34
|
+
@queries.lookup_generalized_vaccines = ::Nuva::Queries::LookupGeneralizedVaccines.new @repositories, @queries.valences_by_vaccine
|
35
|
+
@queries.all_nomenclatures = ::Nuva::Queries::AllNomenclatures.new @repositories
|
36
|
+
@queries.all_code_by_nomenclature = ::Nuva::Queries::AllCodeByNomenclature.new @repositories
|
37
|
+
@queries.freeze
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.load(lang = "en")
|
41
|
+
latest_version_uri = URI "https://nuva.fra1.cdn.digitaloceanspaces.com/versions/last.json"
|
42
|
+
|
43
|
+
::Net::HTTP.start(latest_version_uri.host, latest_version_uri.port,
|
44
|
+
:use_ssl => latest_version_uri.scheme == 'https') do |http|
|
45
|
+
|
46
|
+
# Fetch version manifest
|
47
|
+
req = ::Net::HTTP::Get.new latest_version_uri
|
48
|
+
|
49
|
+
res = http.request req
|
50
|
+
res.value
|
51
|
+
|
52
|
+
manifest = JSON::parse(res.body)
|
53
|
+
|
54
|
+
dump_hash = manifest['dump_hash']
|
55
|
+
|
56
|
+
# Fetch latest database
|
57
|
+
dump_uri = latest_version_uri.dup
|
58
|
+
dump_uri.path = "/proto/#{dump_hash}_#{lang}.db"
|
59
|
+
|
60
|
+
req = ::Net::HTTP::Get.new dump_uri
|
61
|
+
|
62
|
+
res = http.request req
|
63
|
+
res.value
|
64
|
+
|
65
|
+
# The return value of the block is returned by the start method
|
66
|
+
::Nuva::Nuva.new(::Nuva::NuvaDatabase.decode(res.body))
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.load_from_file(path)
|
72
|
+
Nuva.new(NuvaDatabase.decode(File.read(path)))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/queries.rb
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'fuzzy_match'
|
2
|
+
|
3
|
+
module Nuva
|
4
|
+
module Queries
|
5
|
+
class ValencesByVaccine
|
6
|
+
def initialize(repositories)
|
7
|
+
h = Hash.new { |h, k| h[k] = [] }
|
8
|
+
@valences_by_vaccine_id = repositories[:valences].all.reduce(h) do |acc, valence|
|
9
|
+
valence.vaccine_ids.each do |vaccine_id|
|
10
|
+
acc[vaccine_id] << valence
|
11
|
+
end
|
12
|
+
acc
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(vaccine)
|
17
|
+
@valences_by_vaccine_id[vaccine.id]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class VaccinesByValence
|
22
|
+
def initialize(repositories)
|
23
|
+
h = Hash.new { |h, k| h[k] = [] }
|
24
|
+
@vaccines_by_valence_id = repositories[:vaccines].all.reduce(h) do |acc, vaccine|
|
25
|
+
vaccine.valence_ids.each do |valence_id|
|
26
|
+
acc[valence_id] << vaccine
|
27
|
+
end
|
28
|
+
acc
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(valence)
|
33
|
+
@vaccines_by_valence_id[valence.id]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class VaccinesByDisease
|
38
|
+
def initialize(repositories)
|
39
|
+
h = Hash.new { |h, k| h[k] = [] }
|
40
|
+
@vaccines_by_disease_id = repositories[:valences].all.reduce(h) do |acc, valence|
|
41
|
+
valence.disease_ids.each do |disease_id|
|
42
|
+
valence.vaccine_ids.each do |vaccine_id|
|
43
|
+
acc[disease_id] << repositories[:vaccines].find(vaccine_id)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
acc
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def call(disease)
|
51
|
+
@vaccines_by_disease_id[disease.id]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class ValencesByDisease
|
56
|
+
def initialize(repositories)
|
57
|
+
h = Hash.new { |h, k| h[k] = [] }
|
58
|
+
@valences_by_disease_id = repositories[:valences].all.reduce(h) do |acc, valence|
|
59
|
+
valence.disease_ids.each do |disease_id|
|
60
|
+
acc[disease_id] << valence
|
61
|
+
end
|
62
|
+
acc
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def call(disease)
|
67
|
+
@valences_by_disease_id[disease.id]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class DiseasesByVaccine
|
72
|
+
def initialize(repositories)
|
73
|
+
h = Hash.new { |h, k| h[k] = [] }
|
74
|
+
@diseases_by_vaccine_id = repositories[:valences].all.reduce(h) do |acc, valence|
|
75
|
+
valence.vaccine_ids.each do |vaccine_id|
|
76
|
+
valence.disease_ids.each do |disease_id|
|
77
|
+
acc[vaccine_id] << repositories[:diseases].find(disease_id)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
acc
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def call(vaccine)
|
85
|
+
@diseases_by_vaccine_id[vaccine.id]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class DiseasesByValence
|
90
|
+
def initialize(repositories)
|
91
|
+
h = Hash.new { |h, k| h[k] = [] }
|
92
|
+
@diseases_by_valence_id = repositories[:diseases].all.reduce(h) do |acc, disease|
|
93
|
+
disease.valence_ids.each do |valence_id|
|
94
|
+
acc[valence_id] << disease
|
95
|
+
end
|
96
|
+
acc
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def call(valence)
|
101
|
+
@diseases_by_valence_id[valence.id]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class VaccineFuzzySearch
|
106
|
+
def initialize(repositories)
|
107
|
+
@engine = FuzzyMatch.new(repositories.vaccines.all, :read => ->(v) {
|
108
|
+
return v.name
|
109
|
+
})
|
110
|
+
end
|
111
|
+
|
112
|
+
def call(pattern)
|
113
|
+
@engine.find_all(pattern)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# lookupVaccineByCode(code: string): Vaccine | undefined;
|
118
|
+
# lookupEquivalentVaccines(vaccine: Vaccine): Vaccine[];
|
119
|
+
# lookupSpecializedVaccines(vaccine: Vaccine): Vaccine[];
|
120
|
+
# lookupGeneralizedVaccines(vaccine: Vaccine): Vaccine[];
|
121
|
+
# allNomenclatures(): string[];
|
122
|
+
# allCodeByNomenclature(): {
|
123
|
+
# [nomenclature: string]: Code[];
|
124
|
+
# };
|
125
|
+
|
126
|
+
class LookupVaccineByCode
|
127
|
+
def initialize(repositories)
|
128
|
+
@vaccines = repositories.vaccines
|
129
|
+
end
|
130
|
+
|
131
|
+
def call(code)
|
132
|
+
@vaccines.all.find do |vac|
|
133
|
+
"NUVA-#{vac.code}" == code || vac.codes.any? do |x| x.value == code end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class LookupEquivalentVaccines
|
139
|
+
def initialize(repositories)
|
140
|
+
@vaccines = repositories.vaccines
|
141
|
+
end
|
142
|
+
|
143
|
+
def call(vaccine)
|
144
|
+
vids = vaccine.valence_ids.sort
|
145
|
+
@vaccines.all.filter do |v|
|
146
|
+
v.valence_ids.length == vids.length && v.id != vaccine.id && vids == v.valence_ids.sort
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class LookupSpecializedVaccines
|
152
|
+
def initialize(repositories, valencesByVaccine)
|
153
|
+
@vaccines = repositories.vaccines
|
154
|
+
@valences = repositories.valences
|
155
|
+
@valencesByVaccine = valencesByVaccine
|
156
|
+
end
|
157
|
+
|
158
|
+
def call(vaccine)
|
159
|
+
targetValences = @valencesByVaccine.(vaccine)
|
160
|
+
list = @vaccines.all.filter do |candidate|
|
161
|
+
candidate.id != vaccine.id && targetValences.all? do |targetValence|
|
162
|
+
@valencesByVaccine.(candidate).any? do |candidateValence|
|
163
|
+
child_of? candidateValence, targetValence
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
list.sort_by do |v| @valencesByVaccine.(v).length end
|
168
|
+
end
|
169
|
+
|
170
|
+
private def child_of?(valence, parent)
|
171
|
+
unless valence.nil?
|
172
|
+
return true if valence.id == parent.id
|
173
|
+
valence = @valences.find valence.parent_id
|
174
|
+
end
|
175
|
+
|
176
|
+
false
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
class LookupGeneralizedVaccines
|
182
|
+
def initialize(repositories, valencesByVaccine)
|
183
|
+
@vaccines = repositories.vaccines
|
184
|
+
@valences = repositories.valences
|
185
|
+
@valencesByVaccine = valencesByVaccine
|
186
|
+
end
|
187
|
+
|
188
|
+
def call(vaccine)
|
189
|
+
targetValences = @valencesByVaccine.(vaccine)
|
190
|
+
list = @vaccines.all.filter do |candidate|
|
191
|
+
candidate.id != vaccine.id && targetValences.all? do |targetValence|
|
192
|
+
@valencesByVaccine.(candidate).any? do |candidateValence|
|
193
|
+
child_of? candidateValence, targetValence
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
list.sort_by do |v| @valencesByVaccine.(v).length end
|
198
|
+
end
|
199
|
+
|
200
|
+
private def parent_of?(valence, parent)
|
201
|
+
child_of? parent, valence
|
202
|
+
end
|
203
|
+
|
204
|
+
private def child_of?(valence, parent)
|
205
|
+
unless valence.nil?
|
206
|
+
return true if valence.id == parent.id
|
207
|
+
valence = @valences.find valence.parent_id
|
208
|
+
end
|
209
|
+
|
210
|
+
false
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
class AllNomenclatures
|
215
|
+
def initialize(repositories)
|
216
|
+
@vaccines = repositories.vaccines
|
217
|
+
end
|
218
|
+
|
219
|
+
def call
|
220
|
+
(@vaccines.all.flat_map do |v|
|
221
|
+
v.codes.map(&:nomenclature)
|
222
|
+
end).uniq
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
class AllCodeByNomenclature
|
227
|
+
def initialize(repositories)
|
228
|
+
@vaccines = repositories.vaccines
|
229
|
+
end
|
230
|
+
|
231
|
+
def call()
|
232
|
+
@vaccines
|
233
|
+
.all
|
234
|
+
.flat_map(&:codes)
|
235
|
+
.reduce(Hash.new { |hash, key| hash[key] = [] }) {
|
236
|
+
|hash, code|
|
237
|
+
|
238
|
+
hash[code.nomenclature] << code.value
|
239
|
+
hash
|
240
|
+
}
|
241
|
+
.map { |key, value| [key, value.uniq] }
|
242
|
+
.to_h
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Nuva
|
3
|
+
class ValenceRepository < Repository
|
4
|
+
def initialize(data)
|
5
|
+
super data
|
6
|
+
@ancestor_ids_by_id = {}
|
7
|
+
@data.each_value do |valence|
|
8
|
+
# Build hash of ancestor IDs for valence
|
9
|
+
@ancestor_ids_by_id[valence.id] = lookup_ancestors(valence).uniq
|
10
|
+
end
|
11
|
+
@ancestor_ids_by_id.freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_ancestor_ids(valence_id)
|
15
|
+
@ancestor_ids_by_id[valence_id]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def lookup_ancestors(valence)
|
21
|
+
return [] if valence.nil?
|
22
|
+
|
23
|
+
lookup_ancestors(find(valence.parent_id)) << valence.parent_id
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/repository.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Nuva
|
2
|
+
class Repository
|
3
|
+
attr_reader :data
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@data = index_array_by_id(data)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find(id)
|
10
|
+
@data[id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
@data.values
|
15
|
+
end
|
16
|
+
|
17
|
+
def by_ids(ids)
|
18
|
+
ids.map { |x| find x }.compact
|
19
|
+
end
|
20
|
+
|
21
|
+
# def by_ids(ids)
|
22
|
+
# @data.select { |k, _v| ids.include?(k) }.values
|
23
|
+
# end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def index_array_by_id(array)
|
28
|
+
array.each_with_object({}) { |item, acc| acc[item.id] = item }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
require_relative 'repositories/disease_repository'
|
34
|
+
require_relative 'repositories/vaccine_repository'
|
35
|
+
require_relative 'repositories/valence_repository'
|
data/lib/version.rb
ADDED
data/nuva.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "lib/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'nuva'
|
5
|
+
s.version = Nuva::VERSION
|
6
|
+
s.licenses = ['MIT']
|
7
|
+
s.summary = "NUVA"
|
8
|
+
s.description = "nuva library aims to simplify working and interacting with the NUVA nomenclature through queries and repositories"
|
9
|
+
s.authors = ["Syadem"]
|
10
|
+
s.email = ''
|
11
|
+
s.files = Dir.chdir(File.expand_path(__dir__)) {
|
12
|
+
`find . -type f -name '*.rb' -print0`.split("\0").concat %w[nuva.gemspec]
|
13
|
+
}
|
14
|
+
s.add_dependency 'google-protobuf', '~> 3.25', '>= 3.25.3'
|
15
|
+
s.add_dependency 'fuzzy_match', '~> 2.1'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nuva
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Syadem
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-protobuf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.25'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.25.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.25'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.25.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: fuzzy_match
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.1'
|
47
|
+
description: nuva library aims to simplify working and interacting with the NUVA nomenclature
|
48
|
+
through queries and repositories
|
49
|
+
email: ''
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- "./lib/Code_pb.rb"
|
55
|
+
- "./lib/Disease_pb.rb"
|
56
|
+
- "./lib/InjectionMethod_pb.rb"
|
57
|
+
- "./lib/NuvaDatabase_pb.rb"
|
58
|
+
- "./lib/Vaccine_pb.rb"
|
59
|
+
- "./lib/Valence_pb.rb"
|
60
|
+
- "./lib/VersionInfo_pb.rb"
|
61
|
+
- "./lib/nuva.rb"
|
62
|
+
- "./lib/queries.rb"
|
63
|
+
- "./lib/repositories/disease_repository.rb"
|
64
|
+
- "./lib/repositories/vaccine_repository.rb"
|
65
|
+
- "./lib/repositories/valence_repository.rb"
|
66
|
+
- "./lib/repository.rb"
|
67
|
+
- "./lib/version.rb"
|
68
|
+
- nuva.gemspec
|
69
|
+
homepage:
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.5.3
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: NUVA
|
92
|
+
test_files: []
|