nhi-validator 0.1.0
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/.gitignore +8 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nhi_validator.rb +57 -0
- data/lib/nhi_validator/version.rb +3 -0
- data/nhi_validator.gemspec +36 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b45ff678c45fe33622f4355de416f07e0b38325fe84c18056107729ed46d59fa
|
4
|
+
data.tar.gz: dce34e1274982d07e97bef1a664ab16f0f6e7f9739461af3aa8caf5382757b90
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f57ffa71783100cc092c62c8313628d3b85878277c729cacfe8edd543789191bfbcf9d094a2b8b3a58150545466c024f4404a80571d7b05562e6b521c74f2ddd
|
7
|
+
data.tar.gz: 71ea7c16d4fa28e560178af00d896146c761e9564962b428e4617b8d62aa118004bac054108f7bc7817fe3b5cf52b8ada0bc1148204c3ba588cc370403f9b259
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nhi-validator (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.2)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.4)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 2.0)
|
30
|
+
nhi-validator!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.2)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Merrin Macleod
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# NZ National Health Index Validator
|
2
|
+
|
3
|
+
The National Health Index (NHI) number is the unique person identifier used within the New Zealand health system. It uses a checksum for validation. This is a library to do that validation.
|
4
|
+
|
5
|
+
References:
|
6
|
+
|
7
|
+
[Document from health.govt.nz](https://www.health.govt.nz/system/files/documents/pages/nhi_validation_routine_march_2017.doc)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'nhi-validator'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install nhi-validator
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
To check if an NHI number is valid: `NHIValidator.valid?(nhi_number)`
|
28
|
+
|
29
|
+
That's it! That's the whole thing.
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mermop/nhi-validator.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'nhi-validator'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'nhi-validator/version'
|
2
|
+
|
3
|
+
# From https://www.health.govt.nz/system/files/documents/pages/nhi_validation_routine_march_2017.doc:
|
4
|
+
|
5
|
+
# The National Health Index (NHI) number is used by many national and local
|
6
|
+
# systems to provide a safe and secure reference key for patient data.
|
7
|
+
# Because of its importance, the NHI number has a built-in validation routine
|
8
|
+
# that has been designed to allow systems to minimise typographical errors
|
9
|
+
# as NHI numbers are keyed in.
|
10
|
+
# NHI number structure
|
11
|
+
# The NHI number is a unique 7-character identifier
|
12
|
+
# (3 alphabetical characters followed by 4 numeric characters)
|
13
|
+
# assigned to a healthcare user by the NHI.
|
14
|
+
# The first 3 characters of an NHI number must be alphabetic,
|
15
|
+
# but not 'I' or 'O', to avoid confusion with one and zero.
|
16
|
+
# The 4th to 6th characters must be numeric.
|
17
|
+
# The 7th character is also numeric, and is a check digit based on modulus 11.
|
18
|
+
class NHIValidator
|
19
|
+
class Error < StandardError; end
|
20
|
+
class << self
|
21
|
+
PATTERN = /[a-hj-np-zA-HJ-NP-Z]{3}[0-9]{4}/ # alphabet without I and O
|
22
|
+
ALPHABET_OMITTING_I_AND_O = 'abcdefghjklmnpqrstuvwxyz'.freeze
|
23
|
+
|
24
|
+
def valid?(nhi)
|
25
|
+
return false unless nhi =~ PATTERN # steps 1-2
|
26
|
+
|
27
|
+
cs = checksum(nhi[0..5]) # steps 3-10
|
28
|
+
return false if cs.zero? # step 11
|
29
|
+
|
30
|
+
cs = 11 - cs # step 12
|
31
|
+
cs = 0 if cs == 10 # step 13
|
32
|
+
|
33
|
+
nhi[6].to_i == cs
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def checksum(characters)
|
39
|
+
total = 0
|
40
|
+
characters.each_char.with_index do |character, index|
|
41
|
+
total += multiply(character, index)
|
42
|
+
end
|
43
|
+
total % 11
|
44
|
+
end
|
45
|
+
|
46
|
+
def position_in_alphabet(character)
|
47
|
+
ALPHABET_OMITTING_I_AND_O.index(character.downcase) + 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def multiply(character, position)
|
51
|
+
multiplier = (7 - position)
|
52
|
+
return character.to_i * multiplier if character =~ /[0-9]/
|
53
|
+
|
54
|
+
position_in_alphabet(character) * multiplier
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'nhi_validator/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'nhi-validator'
|
7
|
+
spec.version = NHIValidator::VERSION
|
8
|
+
spec.authors = ['Merrin Macleod']
|
9
|
+
spec.email = ['merrin.macleod@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A validator for the New Zealand National Health Index.'
|
12
|
+
spec.description = 'A validator for the New Zealand National Health Index.'
|
13
|
+
spec.homepage = 'https://github.com/mermop/nz-health-index-validator'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/mermop/nhi-validator'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have
|
23
|
+
# been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nhi-validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Merrin Macleod
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: A validator for the New Zealand National Health Index.
|
56
|
+
email:
|
57
|
+
- merrin.macleod@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/nhi_validator.rb
|
71
|
+
- lib/nhi_validator/version.rb
|
72
|
+
- nhi_validator.gemspec
|
73
|
+
homepage: https://github.com/mermop/nz-health-index-validator
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata:
|
77
|
+
allowed_push_host: https://rubygems.org
|
78
|
+
homepage_uri: https://github.com/mermop/nz-health-index-validator
|
79
|
+
source_code_uri: https://github.com/mermop/nhi-validator
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.7.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: A validator for the New Zealand National Health Index.
|
100
|
+
test_files: []
|