Comments (3)
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.
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.
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)
- Can't run rake fhir:console HOT 3
- bundle exec rake fhir:console (error) HOT 11
- Unable to obtain Access Token from Authorization Code HOT 3
- unable to get AllergyIntolerence from FHIR for a patient HOT 1
- fhir::count task fails on R4 server HOT 1
- Is there any option to get patient information from NHS server HOT 2
- Can't modify frozen String
- Using with SMART on FHIR Integration HOT 3
- Confusing conditions in `parse_reply` method HOT 2
- Gem::InstallError: zeitwerk requires Ruby version >= 2.4.4.
- Client response body conversion to JSON
- NoMethodError: undefined method `has_key?' for nil:NilClass HOT 6
- SMART on FHIR
- OAuth2 access token is not passed to `client.client_credentials.get_token`
- oauth2 gem used by fhir_client is EOL
- set_tls_auth
- Search crashing instead of paginating
- Question: Underlying request details HOT 2
- Parser warning during search HOT 1
- Issues sifting through response from FHIR HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fhir_client.