Class: Provider
- Inherits:
-
Object
- Object
- Provider
- Includes:
- Mongoid::Attributes::Dynamic, Mongoid::Tree, Personable
- Defined in:
- lib/health-data-standards/models/provider.rb
Constant Summary collapse
- NPI_OID =
'2.16.840.1.113883.4.6'
- TAX_ID_OID =
'2.16.840.1.113883.4.2'
- CCN_OID =
'2.16.840.1.113883.4.336'.freeze
Class Method Summary collapse
- .luhn_checksum(num) ⇒ Object
-
.resolve_provider(provider_hash, patient = nil) ⇒ Object
When using the ProviderImporter class this method will be called if a parsed provider can not be found in the database if the parsed provider does not have an npi number associated with it.
-
.valid_npi?(npi) ⇒ Boolean
validate the NPI, should be 10 or 15 digits total with the final digit being a checksum using the Luhn algorithm with additional special handling as described in www.cms.gov/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf.
Instance Method Summary collapse
- #ccn ⇒ Object
- #ccn=(a_ccn) ⇒ Object
- #npi ⇒ Object
- #npi=(an_npi) ⇒ Object
- #records(effective_date = nil) ⇒ Object
- #tin ⇒ Object
- #tin=(a_tin) ⇒ Object
Methods included from Personable
Class Method Details
.luhn_checksum(num) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/health-data-standards/models/provider.rb', line 80 def self.luhn_checksum(num) double = {'0' => 0, '1' => 2, '2' => 4, '3' => 6, '4' => 8, '5' => 1, '6' => 3, '7' => 5, '8' => 7, '9' => 9} sum = 0 num.reverse! num.split("").each_with_index do |char, i| if (i%2)==0 sum+=double[char] else sum+=char.to_i end end sum = (9*sum)%10 return sum.to_s end |
.resolve_provider(provider_hash, patient = nil) ⇒ Object
When using the ProviderImporter class this method will be called if a parsed provider can not be found in the database if the parsed provider does not have an npi number associated with it. This allows applications to handle this how they see fit by redefining this method. The default implementation is to return an orphan parent (the singular provider without an NPI) if one exists. If this method call return nil an attempt will be made to discover the Provider by name matching and if that fails a Provider will be created in the db based on the information in the parsed hash.
104 105 106 |
# File 'lib/health-data-standards/models/provider.rb', line 104 def self.resolve_provider(provider_hash, patient=nil) Provider.where(:npi => nil).first end |
.valid_npi?(npi) ⇒ Boolean
validate the NPI, should be 10 or 15 digits total with the final digit being a checksum using the Luhn algorithm with additional special handling as described in www.cms.gov/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/health-data-standards/models/provider.rb', line 66 def self.valid_npi?(npi) return false unless npi return false if npi.length != 10 and npi.length != 15 return false if npi.gsub(/\d/, '').length > 0 # npi must be all digits return false if npi.length == 15 and (npi =~ /^80840/)==nil # 15 digit npi must start with 80840 # checksum is always calculated as if 80840 prefix is present if npi.length==10 npi = '80840'+npi end return luhn_checksum(npi[0,14])==npi[14] end |
Instance Method Details
#ccn ⇒ Object
54 55 56 57 |
# File 'lib/health-data-standards/models/provider.rb', line 54 def ccn cda_id_ccn = self.cda_identifiers.where(root: CCN_OID).first cda_id_ccn ? cda_id_ccn.extension : nil end |
#ccn=(a_ccn) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/health-data-standards/models/provider.rb', line 44 def ccn=(a_ccn) cda_id_ccn = self.cda_identifiers.where(root: CCN_OID).first if cda_id_ccn cda_id_ccn.extension = a_ccn cda_id_ccn.save! else self.cda_identifiers << CDAIdentifier.new(root: CCN_OID, extension: a_ccn) end end |
#npi ⇒ Object
30 31 32 33 |
# File 'lib/health-data-standards/models/provider.rb', line 30 def npi cda_id_npi = self.cda_identifiers.where(root: NPI_OID).first cda_id_npi ? cda_id_npi.extension : nil end |
#npi=(an_npi) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/health-data-standards/models/provider.rb', line 20 def npi=(an_npi) cda_id_npi = self.cda_identifiers.where(root: NPI_OID).first if cda_id_npi cda_id_npi.extension = an_npi cda_id_npi.save! else self.cda_identifiers << CDAIdentifier.new(root: NPI_OID, extension: an_npi) end end |
#records(effective_date = nil) ⇒ Object
59 60 61 |
# File 'lib/health-data-standards/models/provider.rb', line 59 def records(effective_date=nil) Record.by_provider(self, effective_date) end |
#tin ⇒ Object
39 40 41 42 |
# File 'lib/health-data-standards/models/provider.rb', line 39 def tin cda_id_tin = self.cda_identifiers.where(root: TAX_ID_OID).first cda_id_tin ? cda_id_tin.extension : nil end |
#tin=(a_tin) ⇒ Object
35 36 37 |
# File 'lib/health-data-standards/models/provider.rb', line 35 def tin=(a_tin) self.cda_identifiers << CDAIdentifier.new(root: TAX_ID_OID, extension: a_tin) end |