Stream: implementers
Topic: HAPI - Bundle Parsing
Calvin (Aug 23 2018 at 23:05):
I am trying to code an app using Java. I tried reading the HAPI docs and found reference to the Bundle class (which I receive data for) - http://hapifhir.io/apidocs-dstu3/org/hl7/fhir/dstu3/model/Bundle.html.
However, I am unable to find any strong documentation about how to consume data received...
Any inputs will be appreciated.
Grahame Grieve (Aug 23 2018 at 23:12):
what do you mean 'consume data'? what do you want to with the bundle? typically, it will be something like:
for (BundleEntryComponent be : bnd.getEntry()) { if (be.hasResource()) doSomething(be.getResource()) }
Calvin (Aug 23 2018 at 23:36):
Consume data would mean I want to save the patient claim information being received in this Bundle.
Calvin (Aug 23 2018 at 23:42):
https://pastebin.com/m1v5d3Xx
This contains the sample data. So, I am trying to read info about the claims and save them.... Like the amounts/ service start-end date etc. I am kind of lost on how to read through this using HAPI
Calvin (Aug 23 2018 at 23:42):
Hope this makes my query a little clear
Grahame Grieve (Aug 23 2018 at 23:48):
well, did my sample code help? if not, please ask a more specific question
Calvin (Aug 23 2018 at 23:52):
yes, it returned me something to this effect "org.hl7.fhir.dstu3.model.ExplanationOfBenefit@6379eb"
Calvin (Aug 23 2018 at 23:53):
I am still trying to learn Java overall.
This is what I am using:
for (BundleEntryComponent be : bundle.getEntry()) {
if (be.hasResource())
// System.out.println("Resource Found!");
System.out.println(be.getResource());
// be.getNamedProperty("billablePeriod");
// be.getChildByName("BillablePeriod");
}
Calvin (Aug 23 2018 at 23:55):
As an example,
If you check the pastebin, I am trying to retrieve info from lines 286-287-288 (ServicePeriod - start and end)
Grahame Grieve (Aug 23 2018 at 23:57):
sounds like you need some general java tutorials about polymorphism
Calvin (Aug 23 2018 at 23:57):
if (be.hasResource())
// System.out.println("Resource Found!");
System.out.println(be.getNamedProperty("servicedPeriod"));
Calvin (Aug 23 2018 at 23:57):
So, this is returning "null"
Calvin (Aug 23 2018 at 23:59):
sounds like you need some general java tutorials about polymorphism
Yup, thats true. I am not denying that.
Grahame Grieve (Aug 24 2018 at 00:00):
for (BundleEntryComponent be : bnd.getEntry()) { if (be.hasResource() && be.getResource() instanceof ExplanationOfBenefit) { ExplanationOfBenefit eob = (ExplanationOfBenefit) be.getResource(); System.out.println(eob.getBillablePeriod().start()); } }
Calvin (Aug 24 2018 at 00:09):
for (BundleEntryComponent be : bnd.getEntry()) { if (be.hasResource() && be.getResource() instanceof ExplanationOfBenefit) { ExplanationOfBenefit eob = (ExplanationOfBenefit) be.getResource(); System.out.println(eob.getBillablePeriod().start()); } }
Wow, tweaking this, worked (getStart() is the method) ! I think I am seeing where this is going...
Thank you so much. Now I need to explore ExplainationOfBenefit methods!
Calvin (Aug 24 2018 at 00:12):
I am sure going to come back later with more questions (hopefully more intelligent ones) :joy:
Grahame Grieve (Aug 24 2018 at 00:13):
your questions are not unusual for a person who is used to dynamically typed languages running into polymorphism in a strictly typed language for the first time. So I guess that's the case
Calvin (Aug 24 2018 at 00:15):
your questions are not unusual for a person who is used to dynamically typed languages running into polymorphism in a strictly typed language for the first time. So I guess that's the case
Yeh, tbh, I usually code using "code generators" like Pentahoe. So, my knowledge for core java is limited, but building up slowly.
Calvin (Aug 24 2018 at 00:17):
also, there are lots of custom data points provided in my sample data (CMS provided) So, I hope I am able to pick them easily.
Calvin (Aug 24 2018 at 00:17):
but this is a good start.
Calvin (Aug 24 2018 at 00:17):
Thank you once again!
Calvin (Aug 24 2018 at 19:32):
I am trying to find the providers within an EOB bundle.
// Care Team Component for ( CareTeamComponent ctc : eob.getCareTeam()) { if(ctc.hasProvider()) { System.out.println("Provider Found"); System.out.println("Provider: " + ctc.getProvider()); } else { System.out.println("Provider NOT Found"); } }
But this is simply returning : Provider: org.hl7.fhir.dstu3.model.Reference@4b61d0c6
What is this and How can I retrieve the values? Thanks
Alex Neiva (Aug 24 2018 at 19:43):
Did you take a look on HAPI javadoc? http://hapifhir.io/apidocs-dstu3/index.html
Calvin (Aug 24 2018 at 20:29):
Did you take a look on HAPI javadoc? http://hapifhir.io/apidocs-dstu3/index.html
yea, I did. But, I feel I am still learning this framework.
Alex Neiva (Aug 24 2018 at 20:31):
At first can be a little difficult... just need to practice. And on the HAPI you can found many examples. What is the resource and value that you want to extract?
Calvin (Aug 24 2018 at 20:35):
"provider": { "identifier": { "system": "http://hl7.org/fhir/sid/us-npi", "value": "999999999999" } }, "responsible": true, "role": { "coding": [ { "system": "http://hl7.org/fhir/claimcareteamrole", "code": "primary" } ] },
Trying to fetch the Responsible Provider NPI/ Primary Provider.
Alex Neiva (Aug 24 2018 at 20:43):
So you want the "999999999"? And what is the resource name?
Calvin (Aug 25 2018 at 00:21):
ExplanationOfBenefits resource
So you want the "999999999"? And what is the resource name?
Alex Neiva (Aug 25 2018 at 11:33):
After search on FHIR spec site for that specific resource (https://www.hl7.org/fhir/explanationofbenefit.html) i can see that for provider or careTeam->provider the expected child should be reference and not the resource it self.
Should be something like "careTeam": [
{
"sequence": 1,
"provider": {
"reference": "Practitioner/example"
}
}
],
see the FHIR example provided: https://www.hl7.org/fhir/explanationofbenefit-example.json.html
Calvin (Aug 27 2018 at 12:49):
After search on FHIR spec site for that specific resource (https://www.hl7.org/fhir/explanationofbenefit.html) i can see that for provider or careTeam->provider the expected child should be reference and not the resource it self.
Should be something like "careTeam": [
{
"sequence": 1,
"provider": {
"reference": "Practitioner/example"
}
}
],
see the FHIR example provided: https://www.hl7.org/fhir/explanationofbenefit-example.json.html
I think I spoke too fast.
Here is a sample of the Bundle Resource which I am trying to get data from:
Any suggestions appreciated. Thank you.
Alex Neiva (Aug 27 2018 at 14:33):
Use this:
// Care Team Component for ( CareTeamComponent ctc : eob.getCareTeam()) { if(ctc.hasProvider()) { System.out.println("Provider Found"); System.out.println("Provider: " + ctc.getProvider().getIdentifier().getValue()); } else { System.out.println("Provider NOT Found"); } }
.getIdentifier().getValue()
Calvin (Aug 27 2018 at 15:35):
Ohh, so near. Thank you so much.
Can I ask something here? For my learning...
When I did a getProvider(), I did not find any info on how to get the Identifier/ value..
http://hapifhir.io/apidocs-dstu3/org/hl7/fhir/dstu3/model/ExplanationOfBenefit.CareTeamComponent.html#getProvider--
Now, is there anyplace else I need to look to find out that there are 2 other methods which I need to call?
This change what you made, I to pull several other values, and I am simply trying to understand.
But, thanks! This code change worked!
Alex Neiva (Aug 27 2018 at 16:01):
The getProvider() return a Reference model (http://hapifhir.io/apidocs-dstu3/org/hl7/fhir/dstu3/model/Reference.html). If you check the Reference model you will see all the available methods, example getIdentifier() which return a Identifier model (hapifhir.io/apidocs-dstu3/org/hl7/fhir/dstu3/model/Identifier.html), and inside Identifier you have the method getValue() or any other method.
Calvin (Sep 04 2018 at 23:07):
One of the major places I am stuck with the hapi, is getting the values within extensions.
If you see the below example, this is a Bundle of type ExplainationOfBenefit. Within that, there is a "contained" entry. Within contained, there are "extension". I could not find any method on how to read the extension information within the contained... Specifically the "valueCoding" section properties (system/ code/ display).
Any help is appreciated.
Sample:
{ "total": 32, "entry": [ { "resource": { "status": "active", "id": "carrier-21856079985", "contained": [ { "status": "completed", "requester": { "agent": { "identifier": { "system": "http://hl7.org/fhir/sid/us-npi", "value": "999999999999" } } }, "recipient": [ { "identifier": { "system": "http://hl7.org/fhir/sid/us-npi", "value": "999999999999" } } ], "subject": { "reference": "Patient/20140000008325" }, "id": "1", "resourceType": "ReferralRequest" } ], "careTeam": [ { "provider": { "identifier": { "system": "http://hl7.org/fhir/sid/us-npi", "value": "999999999999" } }, "qualification": { "coding": [ { "system": "https://bluebutton.cms.gov/resources/variables/prvdr_spclty", "code": "999" } ] }, "sequence": 2, "responsible": true, "extension": [ { "valueCoding": { "system": "https://bluebutton.cms.gov/resources/variables/carr_line_prvdr_type_cd", "code": "1" }, "url": "https://bluebutton.cms.gov/resources/variables/carr_line_prvdr_type_cd" }, { "valueCoding": { "system": "https://bluebutton.cms.gov/resources/variables/prtcptng_ind_cd", "code": "1", "display": "Participating" }, "url": "https://bluebutton.cms.gov/resources/variables/prtcptng_ind_cd" } ], "role": { "coding": [ { "system": "http://hl7.org/fhir/claimcareteamrole", "code": "primary", "display": "Primary provider" } ] } } ], "resourceType": "ExplanationOfBenefit" }, "fullUrl": "https://sandbox.bluebutton.cms.gov/v1/fhir/ExplanationOfBenefit/carrier-21856079985" } ], "type": "searchset", "resourceType": "Bundle", "id": "f68aeb94-ae6a-4003-881c-240526667b00" }
Lloyd McKenzie (Sep 04 2018 at 23:23):
@James Agnew ?
Patrick Werner (Sep 05 2018 at 07:24):
after getting the contained resource you can use the getExtensions() and similar Methods. Documented here: http://hapifhir.io/doc_extensions.html
It is similar for R4.
Calvin (Sep 05 2018 at 11:28):
Thank you. But I end up with reference to the extension while looping in. To fetch valueCoding array, what is the method to use? Thanks
after getting the contained resource you can use the getExtensions() and similar Methods. Documented here: http://hapifhir.io/doc_extensions.html
It is similar for R4.
Calvin (Sep 05 2018 at 12:28):
after getting the contained resource you can use the getExtensions() and similar Methods. Documented here: http://hapifhir.io/doc_extensions.html
It is similar for R4.
This is what I have:
List<Extension> resourceExts = eob_ctc.getExtension(); System.out.println("Size: " + resourceExts.size()); // returns correct size for (Extension re : resourceExts) { System.out.println("My Ext Info: " + re.getValue()); // Not sure how to get the valueCoding... } the Forloop shows: My Ext Info: org.hl7.fhir.dstu3.model.Coding@3270d194 My Ext Info: org.hl7.fhir.dstu3.model.Coding@14cd1699 My Ext Info: org.hl7.fhir.dstu3.model.Coding@34123d65 My Ext Info: org.hl7.fhir.dstu3.model.Coding@78691363 My Ext Info: org.hl7.fhir.dstu3.model.Coding@639c2c1d My Ext Info: org.hl7.fhir.dstu3.model.Coding@618b19ad My Ext Info: org.hl7.fhir.dstu3.model.Coding@6b2ea799 My Ext Info: org.hl7.fhir.dstu3.model.Coding@13c9d689
Not sure if I am doing this correctly.
Any help is appreciated.
Alex Neiva (Sep 05 2018 at 12:54):
Now, inside the for loop, the "re" is a "Coding" model type... so in HAPI dcumentation just find the Coding model and use the methods getSystem(), getDisplay() , getCode(), etc to get the String value.
re.getSystem() / re.getDisplay() / re.getCode()
Calvin (Sep 05 2018 at 13:19):
Now, inside the for loop, the "re" is a "Coding" model type... so in HAPI dcumentation just find the Coding model and use the methods getSystem(), getDisplay() , getCode(), etc to get the String value.
re.getSystem() / re.getDisplay() / re.getCode()
Yes, Thats correct. However, I am a little unsure on the syntax to convert this Extension to Coding model.
Is this correct?
List<Extension> resourceExts = eob_ctc.getExtension(); System.out.println("Size: " + resourceExts.size()); for (Extension re : resourceExts) { System.out.println("My Ext Display: " + re.getValue().castToCoding(re).getDisplay().toString()); }
Alex Neiva (Sep 05 2018 at 13:34):
But if you just put re.getDisplay()
what is showing to you?
Calvin (Sep 05 2018 at 13:42):
But if you just put
re.getDisplay()
what is showing to you?
The method getDisplay() is undefined for the type Extension. So, I was trying to cast it to Coding earlier. But, not working...
Alex Neiva (Sep 05 2018 at 13:56):
castToCoding() works?
Calvin (Sep 05 2018 at 13:57):
castToCoding() works?
no, did not.
I see this:
System.out.println("My Ext Display: " + re.getValue().castToCoding(re).getDisplay().toString()); >>> org.hl7.fhir.exceptions.FHIRException: Unable to convert a org.hl7.fhir.dstu3.model.Extension to a Coding
Patrick Werner (Sep 05 2018 at 14:10):
re.getValue().castToCoding(re.getValue)
works. You could also do:
(Coding) re.getValue()
Calvin (Sep 05 2018 at 14:53):
re.getValue().castToCoding(re.getValue)
works. You could also do:
(Coding) re.getValue()
Ahh, I see . This works, Excellent! Thank you.
Last updated: Apr 12 2022 at 19:14 UTC