Ruby FHIR Client
Ruby FHIR client.
Supports:
$everything, $validate)$ bundle install
$ bundle exec rake fhir:consoleclient = FHIR::Client.new(url)This client supports two modes of operation: basic and advanced. The basic mode is useful for simple operations because it promotes an ActiveRecord-like style of interaction. The advanced mode is less developer-friendly, but is currently necessary if you would like to use the entire range of operations exposed by FHIR.
Associate the client with the model:
FHIR::Model.client = clientThe FHIR models can now be used to directly interact with a FHIR server.
# read an existing patient with an ID of 'example'
patient = FHIR::Patient.read('example')
# update a patient
patient.gender = 'female'
patient.update # saves the patient
# create a patient
patient = FHIR::Patient.create(name: {given: 'John', family: 'Doe'})
#create a patient with specific headers
patient = FHIR::Patient.new(name: {given: 'John', family: 'Doe'}).create({Prefer: "return=representation"})
# search patients
results = FHIR::Patient.search(given: 'John', family: 'Doe')
results.count # results in an enumeration
# delete the recently created patient
patient.destroyThe client defaults to R4 but can be switched to other versions. It can also attempt to autodetect the FHIR version based on the metadata endpoint.
…The client defaults to json representation of resources but can be switched to xml representations.
client = FHIR::Client.new(url)
# Tell the client to use xml
client.default_xml
# Tell the client to use json
client.default_jsonYou can specify additional properties for the client:
client.additional_headers = {Prefer: 'return=representation'}
client.proxy = 'https://your-proxy.com/'…# via GET
reply = client.search(FHIR::Patient, search: {parameters: {name: 'P'}})
# via POST
reply = client.search(FHIR::Patient, search: {body: {name: 'P'}})
bundle = reply.resource
patient = bundle&.entry&.first&.resourcereply = client.read_feed(FHIR::Patient) # fetch Bundle of Patients
bundle = reply.resource
bundle.entry.each do |entry|
patient = entry.resource
puts patient.name[0].text
end
puts reply.code # HTTP 200 (or whatever was returned)
puts reply.body # Raw XML or JSON…client = FHIR::Client.new(url)
client_id = 'example'
client_secret = 'secret'
options = client.get_oauth2_metadata_from_conformance
if options.empty?
puts 'This server does not support the expected OAuth2 extensions.'
else
client.set_oauth2_auth(client_id, client_secret, options[:authorize_url] ,options[:token_url], options[:site])
reply = client.read_feed(FHIR::Patient)
puts reply.body
endCopyright 2014-2022 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. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
No open issues yet, or sync has not completed.