diff --git a/README.md b/README.md index 334c884e3..10f096778 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ The StructureDefinitions, XML Schemas, and examples are reused from the [HL7 FHI ### Getting Started ``` $ bundle install -$ bundle exec rake fhir:generate $ bundle exec rake fhir:console ``` @@ -19,9 +18,62 @@ $ bundle exec rake fhir:console - Primitive Extensions - FHIR Comments +### Resource Basics + + Using XML... + ```ruby + xml = File.read('patient-example.xml') + patient = FHIR.from_contents(xml) + puts patient.to_xml + ``` + Using JSON... + ```ruby + json = File.read('patient-example.json') + patient = FHIR.from_contents(json) + puts patient.to_json + ``` + + Creating an `Observation` by hand... + ```ruby + obs = FHIR::Observation.new( + 'status' => 'final', + 'code' => { + 'coding' => [{ 'system' => 'http://loinc.org', 'code' => '3141-9', 'display' => 'Weight Measured' }], + 'text' => 'Weight Measured' + }, + 'category' => { + 'coding' => [{ 'system' => 'http://hl7.org/fhir/observation-category', 'code' => 'vital-signs' }] + }, + 'subject' => { 'reference' => 'Patient/example' }, + 'context' => { 'reference' => 'Encounter/example' } + ) + obs.valueQuantity = FHIR::Quantity.new( + 'value' => 185, + 'unit' => 'lbs', + 'code' => '[lb_av]', + 'system' => 'http://unitsofmeasure.org' + ) + ``` + + ### Validation + + Using built in validation... + ```ruby + patient.valid? # returns true or false + patient.validate # returns Hash of errors, empty if valid + ``` + + Using a profile or structure definition... + ```ruby + sd = FHIR::Definitions.resource_definition('Patient') + sd.validates_resource?(patient) # passing in FHIR::DSTU2::Patient + # Validation failed? Get the errors and warnings... + puts sd.errors + puts sd.warnings + ``` # License -Copyright 2014-2016 The MITRE Corporation +Copyright 2014-2018 The MITRE Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Rakefile b/Rakefile index a43ceb0d3..0ae6678b3 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ require 'bundler/gem_tasks' require 'rake/testtask' require 'rspec/core/rake_task' require 'rubocop/rake_task' +require 'pry' Dir['lib/fhir_models/tasks/**/*.rake'].each do |file| load file diff --git a/bin/console b/bin/console index f706c5f9e..2ae216c1f 100755 --- a/bin/console +++ b/bin/console @@ -7,8 +7,8 @@ require 'fhir_models' # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) -# require "pry" -# Pry.start +require 'pry' +Pry.start -require 'irb' -IRB.start +# require 'irb' +# IRB.start diff --git a/fhir_models.gemspec b/fhir_models.gemspec index fd46b952a..d8b54a2a8 100644 --- a/fhir_models.gemspec +++ b/fhir_models.gemspec @@ -20,10 +20,10 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'nokogiri', '>= 1.6' + spec.add_dependency 'nokogiri', '>= 1.8' spec.add_dependency 'date_time_precision', '>= 0.8' spec.add_dependency 'bcp47', '>= 0.3' - spec.add_dependency 'mime-types', '>= 1.16' + spec.add_dependency 'mime-types', '>= 1.16', '< 3' spec.add_development_dependency 'bundler' spec.add_development_dependency 'rake' @@ -32,7 +32,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'nokogiri-diff' - spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'rubocop', '0.49' spec.add_development_dependency 'codeclimate-test-reporter' spec.add_development_dependency 'guard-rspec' spec.add_development_dependency 'guard-test'