Lifen

Lifen is a Ruby client for Lifen FHIR API (over JSON).

Installation

Add this line to your application's Gemfile:

gem 'lifen_fhir'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lifen_fhir

Usage

Configuration

Lifen can be configured (ideally inside an initializer) like so:

LifenFhir.configure do |config|
  config.site                      = "https://demo.lifen.fr/"
  config.application_access_token  = "application_access_token"

  # optionnal
  config.proxy_url                 = "http://my.proxy.fr/"
  config.logger                    = Logger.new
end

Optionnal configuration:

  • proxy_url: route all your requests via a proxy
  • logger: log all requests to a custom logger (on Rails, Rails.logger is selected automatically)

Managing errors

LifenFhir::Error provides a context that can be passed to your issue manager in order to have a better understanding of what is going wrong when an error happens. Here is an example with Sentry:

begin
  # some code using the gem
rescue LifenFhir::Error => e
  Raven.capture_exception(e)
  Raven.extra_context(lifen: e.context)
end

Managing a Binary

binary = LifenFhir::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")
binary.download

Managing Communication Requests

sender = LifenFhir::Practitioner.find_by_rpps("899900018483")

recipient = LifenFhir::Practitioner.find_by_rpps("899900018484")
channel = recipient.channels.first

binary = LifenFhir::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")

communication_request = LifenFhir::CommunicationRequest.new(sender: sender, recipient: recipient, channel: channel, binary: binary, patient: patient, category: category)

communication_request.send

communication_request = LifenFhir::CommunicationRequest.find_by_uuid("b77d-ae67-1b9e-951c-af54")

Communication Request with multiple recipients

sender = LifenFhir::Practitioner.find_by_rpps("899900018483")

recipient = LifenFhir::Practitioner.find_by_rpps("899900018484")
medium = LifenFhir::Medium(uuid: recipient.channels.first.uuid)

other_recipient = LifenFhir::Practitioner.find_by_rpps("899900018484")
other_medium = LifenFhir::Medium(uuid: other_recipient.channels.first.uuid)

binary = LifenFhir::Binary.new(uuid: "b7c7dae671b93e951ce6a4f530736276")

communication_request = LifenFhir::CommunicationRequest.new(sender: sender, recipients: [recipient, other_recipient], medium: [medium, other_medium], binary: binary, patient: patient, category: category)

communication_request_request.send

Managing Communications


#To load communications based on a communication_request
communication_request = LifenFhir::CommunicationRequest.new(uuid:"uuid")

communications = communication_request.communications

#To find communication by uuid
communication = LifenFhir::Communication.find_by_uuid("communication_uuid")

Custom Channels management

recipient = LifenFhir::Practitioner.new(uuid: "valid-user-uuid")

# To create a new mailing address channel
channel = recipient.create_address(type: "address", lines: ["39 rue Aboukir"], city: "Paris", postal_code: "75002", country: "France")

# To create a new telecom channel fax
channel = recipient.create_telecom(type: "telecom", system: "fax", value: "+33102030405")

Managing Patients

# To create a new patient
address = LifenFhir::Address.new(lines: ["39 rue d'Aboukir"], city: "Paris", postal_code: "75002")

patient = LifenFhir::Patient.create(first_name: ["Jean", "Charles"], last_name: "Dupond", birth_date: Date.new(1974, 12, 25), address: address)
patient = LifenFhir::Patient.create(first_name: "Jean", last_name: "Dupond", birth_date: Date.new(1974, 12, 25), address: address)

# To find a patient
patient = LifenFhir::Patient.find_by_uuid("c3f96278-3bfe-4933-96e7-171ebca7489f")

# To set the patient as a recipient in a CommunicationRequest
communication_request = LifenFhir::CommunicationRequest.new(sender: sender, recipients: [patient],  binary: binary, category: category)

Deploying to Rubygems

Once the new version is validated, the deployment follows those steps :

  1. update lib/lifen/version.rb
  2. run bundle install to update Gemfile.lock
  3. update CHANGELOG.md with the additional features of the new version
  4. commit changes to Github
  5. build the gem using gem build lifen_fhir.gemspec
  6. publish the gem using gem publish lifen_fhir-X.X.X.gem
  7. run bundle update lifen in related projects :)

Contributing

TBD

License

The MIT License (MIT)

Copyright (c) 2016-2017 Honestica

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.