Git Product home page Git Product logo

Comments (3)

EtienneDepaulis avatar EtienneDepaulis commented on June 1, 2024 2

Here you go:

> patient_data = {resourceType: "Patient", id: "123"}
=> {:resourceType=>"Patient", :id=>"123"}
> patient = FHIR.from_contents(patient_data.to_json)
=> #<FHIR::Patient:0x00007f9a10f20ba0
 @active=nil,
 @address=[],
 @animal=nil,
 @birthDate=nil,
 @communication=[],
 @contact=[],
 @contained=[],
 @deceasedBoolean=nil,
 @deceasedDateTime=nil,
 @extension=[],
 @gender=nil,
 @generalPractitioner=[],
 @id="123",
 @identifier=[],
 @implicitRules=nil,
 @language=nil,
 @link=[],
 @managingOrganization=nil,
 @maritalStatus=nil,
 @meta=nil,
 @modifierExtension=[],
 @multipleBirthBoolean=nil,
 @multipleBirthInteger=nil,
 @name=[],
 @photo=[],
 @telecom=[],
 @text=nil>
> patient.id
=> "123"

More examples here: https://github.com/fhir-crucible/fhir_models

from fhir_client.

bopritchard avatar bopritchard commented on June 1, 2024

I really appreciate the help. On a similar note, I'd like to be able to trap when an attempt to instantiate invalid data is made.
For instance, FHIR.from_contents '{"asdf":"asdf"}' returns the following ERROR -- : Failed to deserialize JSON:

But it doesn't raise an rescuable exception. Is there a way I can handle this? I might just be looking at it wrong. Thanks again

begin 
   FHIR.from_contents '{"asdf":"asdf"}'
rescue
   puts "error"
end

this doesn't rescue

from fhir_client.

arscan avatar arscan commented on June 1, 2024

The current API does not raise exceptions on parse errors. Instead, it will return nil.

asdf_resource = FHIR.from_contents '{"asdf": "asdf"}'

puts 'parse problem' if asdf_resource.nil?

If you would like it to behave that way, you could do something like this:

begin
   asdf_resource = FHIR.from_contents('{"asdf": "asdf"}') || raise
rescue
   puts 'error'
end

I think raising exceptions on invalid resources by default instead of returning nil would probably make more sense, and it would probably fix a whole class of problems in some of our test tools, but that's not how it is done right now.

from fhir_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.