Skip to content

Commit

Permalink
parent d4a9363
Browse files Browse the repository at this point in the history
author 360dgries <[email protected]> 1727189567 -0400
committer 360dgries <[email protected]> 1727360442 -0400

First rebase

update fhir_models

Update rubocop

add generated files

add one readme file

add excluded_files

add readme files

update generator

add tgz

add expansion file

add one readme file

add readme files

First rebase

Fix r5 Model

remove redundant file

Add basic unit tests for R5

Add Unit tests and version from_contents

update fhir_models

Update rubocop

add generated files

add one readme file

add excluded_files

add readme files

update generator

add tgz

add expansion file

Fix r5 Model

remove redundant file

Add basic unit tests for R5

Add Unit tests and version from_contents
  • Loading branch information
360dgries committed Sep 26, 2024
1 parent d4a9363 commit 64ef50f
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 66 deletions.
22 changes: 13 additions & 9 deletions lib/fhir_models/fhir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
require 'uri'

module FHIR
module ClassMethods
def from_contents(contents)
doc = Nokogiri::XML(contents)
if doc.errors.empty?
versioned_fhir_module::Xml.from_xml(contents)
else
versioned_fhir_module::Json.from_json(contents)
end
end
end
include ClassMethods
extend ClassMethods

def self.logger
@logger || default_logger
end
Expand All @@ -15,15 +28,6 @@ def self.default_logger
@default_logger ||= Logger.new(ENV['FHIR_LOGGER'] || $stdout)
end

def self.from_contents(contents)
doc = Nokogiri::XML(contents)
if doc.errors.empty?
FHIR::Xml.from_xml(contents)
else
FHIR::Json.from_json(contents)
end
end

# TODO: pull regexes from metadata
def self.primitive?(datatype:, value:)
# Remaining data types: handle special cases before checking type StructureDefinitions
Expand Down
1 change: 1 addition & 0 deletions lib/fhir_models/r4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

module FHIR
module R4
extend FHIR
extend self

def fhir_version_string
Expand Down
1 change: 1 addition & 0 deletions lib/fhir_models/r4b.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

module FHIR
module R4B
extend FHIR
extend self

def fhir_version_string
Expand Down
23 changes: 19 additions & 4 deletions lib/fhir_models/r5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
require file
end

# Require the fhir_ext code
Dir.glob(File.join(root, 'fhir_models', 'fhir_ext', '*.rb')).sort.each do |file|
require file
end

Dir.glob(File.join(root, 'fhir_models', 'r5', 'bootstrap', '*.rb')).sort.each do |file|
require file
end
Expand All @@ -34,11 +39,21 @@
require file
end

# Require the fhir_ext code
Dir.glob(File.join(root, 'fhir_models', 'fhir_ext', '*.rb')).sort.each do |file|
Dir.glob(File.join(root, 'fhir_models', 'r5', 'fhir_ext', '*.rb')).sort.each do |file|
require file
end

Dir.glob(File.join(root, 'fhir_models', 'r5', 'fhir_ext', '*.rb')).sort.each do |file|
require file
module FHIR
module R5
extend FHIR
extend self

def fhir_version_string
'R5'
end

def versioned_fhir_module
FHIR::R5
end
end
end
9 changes: 1 addition & 8 deletions lib/fhir_models/r5/bootstrap/definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ module FHIR
module R5
class Definitions
include CommonDefinitions
extend FHIR::R5
@ig_file_name = File.join(Dir.pwd, 'lib', 'fhir_models', 'igs', 'hl7.fhir.r5.core.tgz')

load_igs(@ig_file_name)

def self.fhir_version_string
'R5'
end

def self.versioned_fhir_module
FHIR::R5
end
end
end
end
9 changes: 9 additions & 0 deletions lib/fhir_models/r5/bootstrap/json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module FHIR
module R5
module Json
extend FHIR::R5
extend FHIR::ClassJson
include FHIR::InstanceJson
end
end
end
8 changes: 1 addition & 7 deletions lib/fhir_models/r5/bootstrap/model.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
module FHIR
module R5
class Model < FHIR::Model
def fhir_version_string
'R5'
end

def versioned_fhir_module
FHIR::R5
end
include FHIR::R5
end
end
end
9 changes: 9 additions & 0 deletions lib/fhir_models/r5/bootstrap/xml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module FHIR
module R5
module Xml
extend FHIR::R5
extend FHIR::ClassXml
include FHIR::InstanceXml
end
end
end
15 changes: 0 additions & 15 deletions lib/fhir_models/r5/fhir_ext/element_definition.rb

This file was deleted.

15 changes: 0 additions & 15 deletions lib/fhir_models/r5/fhir_ext/structure_definition.rb

This file was deleted.

8 changes: 0 additions & 8 deletions lib/fhir_models/r5/fhir_ext/structure_definition_compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ module FHIR
module R5
class StructureDefinitionCompare
include CommonStructureDefinitionCompare

def self.fhir_version_string
'R5'
end

def self.versioned_fhir_module
FHIR::R5
end
end
end
end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class StructureDefinition < Model
include FHIR::Hashable
include FHIR::Json
include FHIR::Xml
include FHIR::CommonStructureDefinition

MULTIPLE_TYPES = {
'versionAlgorithm' => ['string', 'Coding']
Expand Down
1 change: 1 addition & 0 deletions lib/fhir_models/r5/generated/types/ElementDefinition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ElementDefinition < Model
include FHIR::Hashable
include FHIR::Json
include FHIR::Xml
include FHIR::CommonElementDefinition

MULTIPLE_TYPES = {
'defaultValue' => ['base64Binary', 'boolean', 'canonical', 'code', 'date', 'dateTime', 'decimal', 'id', 'instant', 'integer', 'integer64', 'markdown', 'oid', 'positiveInt', 'string', 'time', 'unsignedInt', 'uri', 'url', 'uuid', 'Address', 'Age', 'Annotation', 'Attachment', 'CodeableConcept', 'CodeableReference', 'Coding', 'ContactPoint', 'Count', 'Distance', 'Duration', 'HumanName', 'Identifier', 'Money', 'Period', 'Quantity', 'Range', 'Ratio', 'RatioRange', 'Reference', 'SampledData', 'Signature', 'Timing', 'ContactDetail', 'DataRequirement', 'Expression', 'ParameterDefinition', 'RelatedArtifact', 'TriggerDefinition', 'UsageContext', 'Availability', 'ExtendedContactDetail', 'Dosage', 'Meta'],
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/fhir_models/r5/definition_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require_relative '../../../../lib/fhir_models/r5/bootstrap/definitions'

RSpec.describe FHIR::R5::Definitions do
describe '#resource_definition' do
it 'returns R5 resource definition' do
result = FHIR::R5::Definitions.resource_definition('Patient')
expect(result.id).to eq('Patient')
expect(result.version).to eq('5.0.0')
end
end
end
37 changes: 37 additions & 0 deletions test/unit/contents_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,41 @@ def test_negative_xml_contents
nothing = FHIR.from_contents('<?xml version="1.0" encoding="UTF-8"?><Nothing/>')
assert nothing.nil?, 'From contents should have returned nil.'
end

def test_versioned_from_contents
xml = File.read(EXAMPLE_XML)
json = File.read(EXAMPLE_JSON)

# infer XML
patient_xml= FHIR.from_contents(xml)
assert !patient_xml.nil?, 'From contents did not succeed with XML.'
assert patient_xml.id == 'example', 'Patient did not deserialize correctly.'
assert patient_xml.versioned_fhir_module == FHIR::R4

patient_xml_r4b = FHIR::R4B.from_contents(xml)
assert !patient_xml_r4b.nil?, 'From contents did not succeed with XML.'
assert patient_xml_r4b.id == 'example', 'Patient did not deserialize correctly.'
assert patient_xml_r4b.versioned_fhir_module == FHIR::R4B

patient_xml_r5 = FHIR::R5.from_contents(xml)
assert !patient_xml_r5.nil?, 'From contents did not succeed with XML.'
assert patient_xml_r5.id == 'example', 'Patient did not deserialize correctly.'
assert patient_xml_r5.versioned_fhir_module == FHIR::R5

# infer json
patient_json= FHIR.from_contents(json)
assert !patient_json.nil?, 'From contents did not succeed with JSON.'
assert patient_json.id == 'example', 'Patient did not deserialize correctly.'
assert patient_json.versioned_fhir_module == FHIR::R4

patient_json_r4b = FHIR::R4B.from_contents(json)
assert !patient_json_r4b.nil?, 'From contents did not succeed with JSON.'
assert patient_json_r4b.id == 'example', 'Patient did not deserialize correctly.'
assert patient_json_r4b.versioned_fhir_module == FHIR::R4B

patient_json_r5 = FHIR::R5.from_contents(json)
assert !patient_json_r5.nil?, 'From contents did not succeed with JSON.'
assert patient_json_r5.id == 'example', 'Patient did not deserialize correctly.'
assert patient_json_r5.versioned_fhir_module == FHIR::R5
end
end

0 comments on commit 64ef50f

Please sign in to comment.