dcarbone / php-fhir-generated

Pre-generated classes from dcarbone/php-fhir
Apache License 2.0
36 stars 11 forks source link

Fhir response parsing error #9

Closed chkm8 closed 4 years ago

chkm8 commented 4 years ago

Hi, I tried to use the library in parsing fhir response but I got "UnexpectedValueException: Unable parse provided input object of type "stdClass" error. I checked the PHPFHIRResponseParser (DCarbone\PHPFHIRGenerated\R4\PHPFHIRResponseParser) class and found the exception in parseObjectInput function. Seems that the class is expecting an instance of PHPFHIRTypeInterface but the fhir response is in object/class type. I followed the sample response parsing in https://github.com/dcarbone/php-fhir. Did I miss some setup to make it work? Btw, we are using Azure Fhir Server vR4.

Sample fhir response: "resourceType": "Patient", "id": "uuid-1234", "meta": { "versionId": "4", "lastUpdated": "2020-08-17T02:49:33.943+00:00" }, "active": true, "name": [ { "use": "official", "family": "try", "given": [ "Mike" ] } ],

dcarbone commented 4 years ago

@chkm8: this should work if you feed it either the raw JSON string or an associative array via $decoded = json_decode($json, true).

Let me know if either of those approaches does not work.

chkm8 commented 4 years ago

Cool, its now working, I encoded the object and passed it in the parser. Big Thanks! $object = $parser->parse(json_encode($fhir_respoonse));

dcarbone commented 4 years ago

sure thing. question though: how are you retrieving the data in the first place? something must be unmarshalling the response from a raw json string into the stdClass object. are you using Guzzle, or some other common PHP http client?

chkm8 commented 4 years ago

Yes I'm using guzzle. Seems that I did converted the response using json_decode before I passed it into the parser class. I removed it already and used the parse as it is.

dcarbone commented 4 years ago

Alright, great. Let me know if you run into any other problems.

chkm8 commented 4 years ago

Another question btw, is there a way I could override or update the value of the class? I wanted to override the FHIRBundleEntry->fullUrl into our custom url instead of the azure fhir server url. I tried to update the code in FHIRBundleEntry and add str_replace before its being converted to FHIRUri object. I wanted to know if there's a way like passing a config key in PHPFHIRResponseParserConfig class or I'll have to copy all of the class inside vendor/dcarbone/php-fhir-generated/src/DCarbone/PHPFHIRGenerated/R4 and add them into may project?