medcon 0.2.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c89c66ad2c4d25dfcc82041490bc2af5d43e06ccfcb2f6f4110d129bbd0c0e72
4
+ data.tar.gz: 5309f4438737d95c51b9c4136128baf9720c3eed86c5d4f458dfbf330558ee3a
5
+ SHA512:
6
+ metadata.gz: 4cff5781fe5d2a8435ba23f130ac446b9c727ecec95e441333d1041715649dae83138e4a7ad885bd42447a9914850c4f4291a3142454f8165e496d201ebcd670
7
+ data.tar.gz: c2e823e97f51620bc0500d12db1e14fe7adc9d010796473a9acdf7945583bb63644254c71c3c0582b60cd61729caab23ae50bc0fe83fb3116d08a11e31931e4e
@@ -0,0 +1,22 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/ruby
3
+ {
4
+ "name": "medcon-ruby",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ "image": "mcr.microsoft.com/devcontainers/ruby:1-3.3-bullseye"
7
+
8
+ // Features to add to the dev container. More info: https://containers.dev/features.
9
+ // "features": {},
10
+
11
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
12
+ // "forwardPorts": [],
13
+
14
+ // Use 'postCreateCommand' to run commands after the container is created.
15
+ // "postCreateCommand": "ruby --version",
16
+
17
+ // Configure tool-specific properties.
18
+ // "customizations": {},
19
+
20
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
21
+ // "remoteUser": "root"
22
+ }
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,116 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 3.3
6
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
7
+ # to ignore them, so only the ones explicitly set in this file are enabled.
8
+ DisabledByDefault: true
9
+ Exclude:
10
+ - "**/vendor/**/*"
11
+ - "**/*_pb.rb"
12
+
13
+ # Prefer &&/|| over and/or.
14
+ Style/AndOr:
15
+ Enabled: true
16
+
17
+ Layout:
18
+ Enabled: false
19
+
20
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
21
+ Style/HashSyntax:
22
+ Enabled: true
23
+
24
+ Style/DefWithParentheses:
25
+ Enabled: true
26
+
27
+ # Defining a method with parameters needs parentheses.
28
+ Style/MethodDefParentheses:
29
+ Enabled: true
30
+
31
+ Style/FrozenStringLiteralComment:
32
+ Enabled: true
33
+ EnforcedStyle: always
34
+
35
+ Layout/EmptyLineAfterMagicComment:
36
+ Enabled: true
37
+
38
+ Style/RedundantFreeze:
39
+ Enabled: true
40
+
41
+ # Use quotes for string literals when they are enough.
42
+ Style/RedundantPercentQ:
43
+ Enabled: true
44
+
45
+ Style/StringLiterals:
46
+ Enabled: false
47
+
48
+ Lint/AmbiguousOperator:
49
+ Enabled: true
50
+
51
+ Lint/AmbiguousRegexpLiteral:
52
+ Enabled: true
53
+
54
+ Lint/ErbNewArguments:
55
+ Enabled: true
56
+
57
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
58
+ Lint/RequireParentheses:
59
+ Enabled: true
60
+
61
+ Lint/ShadowingOuterLocalVariable:
62
+ Enabled: true
63
+
64
+ Lint/RedundantStringCoercion:
65
+ Enabled: true
66
+
67
+ Lint/UriEscapeUnescape:
68
+ Enabled: true
69
+
70
+ Lint/UselessAssignment:
71
+ Enabled: true
72
+
73
+ Lint/DeprecatedClassMethods:
74
+ Enabled: true
75
+
76
+ Style/ParenthesesAroundCondition:
77
+ Enabled: true
78
+
79
+ Style/RedundantBegin:
80
+ Enabled: false
81
+
82
+ Style/RedundantReturn:
83
+ Enabled: true
84
+ AllowMultipleReturnValues: true
85
+
86
+ Style/Semicolon:
87
+ Enabled: true
88
+ AllowAsExpressionSeparator: true
89
+
90
+ # Prefer Foo.method over Foo::method
91
+ Style/ColonMethodCall:
92
+ Enabled: true
93
+
94
+ Style/TrivialAccessors:
95
+ Enabled: true
96
+
97
+ Performance/FlatMap:
98
+ Enabled: true
99
+
100
+ Performance/RedundantMerge:
101
+ Enabled: true
102
+
103
+ Performance/StartWith:
104
+ Enabled: true
105
+
106
+ Performance/EndWith:
107
+ Enabled: true
108
+
109
+ Performance/RegexpMatch:
110
+ Enabled: true
111
+
112
+ Performance/ReverseEach:
113
+ Enabled: true
114
+
115
+ Performance/UnfreezeString:
116
+ Enabled: true
data/Changelog.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2025-01-21
9
+
10
+ ### Added
11
+
12
+ - Add new methods `Medcon.load` and `Medcon.fetch_latest_version_hash`
13
+ - Implement `Medcon#inspect`
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/gen_proto.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ find ../schemas -type f -name '*.proto' -exec basename {} \; | xargs protoc --ruby_out=./lib/medcon -I ../schemas
4
+
5
+ if [ `uname` = 'Darwin' ]; then
6
+ sed -i '' -E "s/^require '([a-zA-Z_]+)'/require_relative '\1'/" ./lib/medcon/*_pb.rb
7
+ else
8
+ sed -i -E "s/^require '([a-zA-Z_]+)'/require_relative '\1'/" ./lib/medcon/*_pb.rb
9
+ fi
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: ConditionGroup.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("ConditionGroup.proto", :syntax => :proto3) do
8
+ add_message "medcon.ConditionGroup" do
9
+ optional :id, :string, 1
10
+ optional :label, :string, 2
11
+ optional :parent_id, :string, 3
12
+ repeated :condition_ids, :string, 4
13
+ end
14
+ end
15
+ end
16
+
17
+ module Medcon
18
+ ConditionGroup = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("medcon.ConditionGroup").msgclass
19
+ end
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: ConditionType.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("ConditionType.proto", :syntax => :proto3) do
8
+ add_enum "medcon.ConditionType" do
9
+ value :BOOLEAN, 0
10
+ value :DATE, 1
11
+ value :FLOAT, 2
12
+ value :INTEGER, 3
13
+ end
14
+ end
15
+ end
16
+
17
+ module Medcon
18
+ ConditionType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("medcon.ConditionType").enummodule
19
+ end
@@ -0,0 +1,29 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: Condition.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require_relative 'ConditionType_pb'
7
+ require 'google/protobuf/wrappers_pb'
8
+
9
+ Google::Protobuf::DescriptorPool.generated_pool.build do
10
+ add_file("Condition.proto", :syntax => :proto3) do
11
+ add_message "medcon.Code" do
12
+ optional :nomenclature, :string, 1
13
+ optional :code, :string, 2
14
+ end
15
+ add_message "medcon.Condition" do
16
+ optional :id, :int32, 1
17
+ optional :label, :string, 2
18
+ optional :description, :string, 3
19
+ optional :type, :enum, 4, "medcon.ConditionType"
20
+ repeated :tags, :string, 5
21
+ repeated :codes, :message, 6, "medcon.Code"
22
+ end
23
+ end
24
+ end
25
+
26
+ module Medcon
27
+ Code = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("medcon.Code").msgclass
28
+ Condition = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("medcon.Condition").msgclass
29
+ end
@@ -0,0 +1,23 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: VaccinationProfileDatabase.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/timestamp_pb'
7
+ require_relative 'Version_pb'
8
+ require_relative 'Condition_pb'
9
+
10
+ Google::Protobuf::DescriptorPool.generated_pool.build do
11
+ add_file("VaccinationProfileDatabase.proto", :syntax => :proto3) do
12
+ add_message "medcon.VaccinationProfileDatabase" do
13
+ optional :version, :message, 1, "medcon.Version"
14
+ optional :generated_at, :message, 2, "google.protobuf.Timestamp"
15
+ optional :locale, :string, 3
16
+ repeated :conditions, :message, 4, "medcon.Condition"
17
+ end
18
+ end
19
+ end
20
+
21
+ module Medcon
22
+ VaccinationProfileDatabase = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("medcon.VaccinationProfileDatabase").msgclass
23
+ end
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: Version.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("Version.proto", :syntax => :proto3) do
8
+ add_message "medcon.Version" do
9
+ optional :major, :uint32, 1
10
+ optional :minor, :uint32, 2
11
+ optional :patch, :uint32, 3
12
+ end
13
+ end
14
+ end
15
+
16
+ module Medcon
17
+ Version = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("medcon.Version").msgclass
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Medcon
4
+ module Repositories
5
+ class ConditionRepository < Repository
6
+ protected
7
+
8
+ def index_keys(item)
9
+ code_keys = item.codes.flat_map do |entry|
10
+ [entry.code, "#{entry.nomenclature}:#{entry.code}"]
11
+ end
12
+
13
+ [item.id, *code_keys]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Medcon
4
+ class Repository
5
+ attr_reader :all
6
+
7
+ def initialize(data)
8
+ @all = data
9
+ @index = {}
10
+ data.each do |item|
11
+ index_keys(item).each do |key|
12
+ @index[normalize_key(key)] = item
13
+ end
14
+ end
15
+ end
16
+
17
+ def find(id)
18
+ @index[normalize_key(id)]
19
+ end
20
+
21
+ def by_ids(ids)
22
+ ids.map { |x| find x }.compact
23
+ end
24
+
25
+ def inspect
26
+ "#<#{self.class} count=#{all.count}>"
27
+ end
28
+
29
+ protected
30
+
31
+ def index_keys(item)
32
+ [item.id]
33
+ end
34
+
35
+ def normalize_key(key)
36
+ key.to_s
37
+ end
38
+ end
39
+ end
40
+
41
+ require_relative "repositories/condition_repository"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Medcon
4
+ VERSION = "0.2.1"
5
+ end
data/lib/medcon.rb ADDED
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "medcon/version"
4
+ require_relative "medcon/VaccinationProfileDatabase_pb"
5
+ require_relative "medcon/repository"
6
+ require "net/http"
7
+ require "json"
8
+ require "ostruct"
9
+
10
+ module Medcon
11
+ class Medcon
12
+ attr_reader :repositories
13
+ attr_reader :queries
14
+
15
+ def initialize(db)
16
+ @db = db
17
+
18
+ @repositories = OpenStruct.new
19
+ @repositories.conditions =
20
+ Repositories::ConditionRepository.new db.conditions
21
+ @repositories.freeze
22
+ end
23
+
24
+ def version
25
+ @db.version
26
+ end
27
+
28
+ def inspect
29
+ "#<Medcon::Medcon version=#{version.major}.#{version.minor}.#{version.patch} condition_count=#{repositories.conditions.all.count}>"
30
+ end
31
+
32
+ def generated_at
33
+ @db.generated_at
34
+ end
35
+
36
+ class << self
37
+ DEFAULT_CDN_URI = URI("https://nuva.svc.edge.scw.cloud")
38
+
39
+ def load(cdn_uri: DEFAULT_CDN_URI, lang: "en", hash: nil)
40
+ init_http(cdn_uri) do |http|
41
+ # Fetch version manifest if necessary
42
+ hash ||= fetch_latest_version_hash(http:)
43
+
44
+ response = http.get("/conditions/#{hash}_#{lang}.db")
45
+ Medcon.new(::Medcon::VaccinationProfileDatabase.decode(response.body))
46
+ end
47
+ end
48
+
49
+ def fetch_latest_version_hash(cdn_uri: DEFAULT_CDN_URI, http: nil)
50
+ if http.nil?
51
+ http = init_http(cdn_uri)
52
+ passed_http = false
53
+ end
54
+ response = http.get("/versions/last.json")
55
+ hash = JSON.parse(response.body)["dump_hash"]
56
+ http.finish unless passed_http
57
+ hash
58
+ end
59
+
60
+ def load_from_file(path)
61
+ Medcon.new(::Medcon::VaccinationProfileDatabase.decode(File.read(path)))
62
+ end
63
+
64
+ private
65
+
66
+ def init_http(cdn_uri, &block)
67
+ Net::HTTP.start(
68
+ cdn_uri.host,
69
+ cdn_uri.port,
70
+ use_ssl: cdn_uri.scheme == "https",
71
+ &block
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
data/medcon.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/medcon/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "medcon"
7
+ spec.version = Medcon::VERSION
8
+ spec.authors = ["Syadem"]
9
+ spec.email = ["developers@mesvaccins.net"]
10
+
11
+ spec.summary = "Medical Conditions for SADV"
12
+ spec.description = "syadem vaccination profile gem"
13
+ spec.homepage = "https://docs.nuva.mesvaccins.net"
14
+ spec.required_ruby_version = ">= 3.0.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .gitlab-ci.yml appveyor Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency 'google-protobuf', '~> 3.25', '>= 3.25.3'
33
+ spec.add_dependency 'ostruct'
34
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: medcon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Syadem
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-05-29 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: ostruct
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: syadem vaccination profile gem
48
+ email:
49
+ - developers@mesvaccins.net
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".devcontainer/devcontainer.json"
55
+ - ".rspec"
56
+ - ".rubocop.yml"
57
+ - Changelog.md
58
+ - Rakefile
59
+ - gen_proto.sh
60
+ - lib/medcon.rb
61
+ - lib/medcon/ConditionGroup_pb.rb
62
+ - lib/medcon/ConditionType_pb.rb
63
+ - lib/medcon/Condition_pb.rb
64
+ - lib/medcon/VaccinationProfileDatabase_pb.rb
65
+ - lib/medcon/Version_pb.rb
66
+ - lib/medcon/repositories/condition_repository.rb
67
+ - lib/medcon/repository.rb
68
+ - lib/medcon/version.rb
69
+ - medcon.gemspec
70
+ homepage: https://docs.nuva.mesvaccins.net
71
+ licenses: []
72
+ metadata:
73
+ homepage_uri: https://docs.nuva.mesvaccins.net
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.5.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Medical Conditions for SADV
93
+ test_files: []