diff --git a/lib/fhir_client/ext/reference.rb b/lib/fhir_client/ext/reference.rb index 344ea736..f79287ae 100644 --- a/lib/fhir_client/ext/reference.rb +++ b/lib/fhir_client/ext/reference.rb @@ -82,7 +82,7 @@ class Reference include FHIR::ReferenceExtras def resource_class - FHIR.const_get(resource_type) unless contained? + FHIR.const_get(resource_type) unless contained? || resource_type.nil? end end end @@ -101,7 +101,7 @@ def resource_class module FHIR module STU3 - class Reference + class Reference include FHIR::ReferenceExtras def resource_class diff --git a/test/unit/reference_extras_test.rb b/test/unit/reference_extras_test.rb index 76b2a659..419080e9 100644 --- a/test/unit/reference_extras_test.rb +++ b/test/unit/reference_extras_test.rb @@ -62,6 +62,11 @@ def test_reference_klass_dstu2 assert r.resource_class == FHIR::DSTU2::Patient end + def test_reference_klass_empty + r = FHIR::Reference.new({'display': 'abc'}) + assert r.resource_class.nil? + end + def test_relative r = FHIR::Reference.new({'reference': 'Patient/foo'}) assert r.relative?