Giter VIP home page Giter VIP logo

Comments (7)

Dokotela avatar Dokotela commented on July 21, 2024

Do you have an example of what you're trying to parse?

I have tried to stick to the original FHIR requirements in all of these resources. And if you look at the Observation for version 4b, you'll notice that the 'code' field is one of the required fields.

The error you've highlited is linked to code that is found here: https://github.com/MayJuun/fhir/blob/main/fhir/lib/r4/resource_types/clinical/diagnostics/diagnostics.dart#L3828

You'll notice that the 'code' field is required here as well. This makes it different than most of the fields in the class which are Nullable (meaning they don't use the 'required' keyword, and have the '?' after the type in the definition). So at least for this value, the generated files will not allow the file to be Null (which is required by the FHIR definition), and will throw an error if the resource that you are trying to parse has a null instead of a value for that code.

As far as I can tell from what you've posted, I believe the code is performing as desired. Please let me know if any of my explanation doesn't make sense, and feel free to post what you're trying to parse that is giving you the error.

from fhir.

binismaharjan avatar binismaharjan commented on July 21, 2024

Thanks for the detailed reply. There may have been issue in json from the test servers.

There is actually a new problem. The app force closes without giving any errors.
Here is the json file https://drive.google.com/file/d/1brtZenjVp6sdxSHs1Hec5pON82keGCPd/view?usp=sharing
Screenshot 2023-04-07 at 2 32 32 PM

The app force closes at r4.Bundle response = r4.Bundle.fromJson(jsonDecode(r));

from fhir.

Dokotela avatar Dokotela commented on July 21, 2024

Hmmmm, I'm afraid I haven't been able to reproduce your issue exactly. This is what I've tried.

Dart Program:

void main() {
  final bundle1 = Bundle.fromJson(bundleMap);
  print(bundle1.toJson());
  final bundle2 = Bundle.fromJson(jsonDecode(bundleString));
  print(bundle2.toJson());
}

No issues here. bundleMap is the json from your file as a map. bundleString is the json file saved as a String. I will say that Dart did not like the escaped double quotes in the text.div fields of some of the resources in the bundle. This was not an issue when I saved it as a map. When I saved it as a string it did throw this errror:

Unhandled exception:
FormatException: Unexpected character (at line 25, character 28)
              "<div xmlns="http://www.w3.org/1999/xhtml"><table class="hapi...

This can be avoided by loading a raw string instead of just a string. That is, instead of loading it like this:

final bundleString = '''
{
  "resourceType": "Bundle",
  "id": "034e77b3-3aa5-4928-9ffb-7dbbf3b4c1a5",
  "meta": {"lastUpdated": "2023-04-07T08:34:43.884+00:00"},
...

You can load it like this:

final bundleString = r'''
{
  "resourceType": "Bundle",
  "id": "034e77b3-3aa5-4928-9ffb-7dbbf3b4c1a5",
  "meta": {"lastUpdated": "2023-04-07T08:34:43.884+00:00"},

That fixed that issue and it loaded it fine. OK, so it works in Dart, but how about in Flutter? I tried to mirror what you have above. I created an Asset folder called "asset" which is in the primary project directory and I included the file in pubspec.yaml like so:

flutter:
  assets:
    - assets/bundle.json

If any of this is not how you've set it up, let me know, and I can try and mirror you and reproduce the error. I made a simple Assets class:

class Assets {
  static const jsonResponse = 'assets/bundle.json';
}

Then I called my function to read the file:

  final r = await rootBundle.loadString(Assets.jsonResponse);

  log('Json String $r');

  try {
    final Bundle response =
        Bundle.fromJson(jsonDecode(r) as Map<String, dynamic>);

    log('Bundle response ${response.toJson()}');
  } catch (e, s) {
    print('Error: $e, Stack: $s');
  }

Seems to work fine. A couple of things to mention just in case.

  1. Mine wouldn't even run unless I cast the jsonDecode(r) as Map<String, dynamic>, otherwise it complained that it couldn't pass an Object to the fromJson constructor. Are you using an analysis_options.yaml file in your project? It helps catch some of these problems. Although actually I went back and removed that file, which then didn't require casting, and the function still seemed to work.
  2. I almost always recommend using the .toJson() method anytime you're going to print or log something. If you don't, it includes all of the null values for all of the fields. If you use the .toJson() method, it only shows you fields that have values.

Hopefully some of that is helpful? If it is, great! Just let me know what the problem was and I can close this. If not, also let me know, and we can try to keep trouble shooting.

from fhir.

binismaharjan avatar binismaharjan commented on July 21, 2024

Thanks for the detailed reply.
It appears that the same code is working correctly on your end but failing for mine.
Here is a link to the demonstration video.
Link to video

from fhir.

Dokotela avatar Dokotela commented on July 21, 2024

Is it still giving you the same error message? And it says that's the part of the code that's causing it to crash? Because in the print out that you show, both the log for Json String and Bundle Response appear to show the correct json. Which would seem to indicate that it's reading the file correctly from assets.

from fhir.

binismaharjan avatar binismaharjan commented on July 21, 2024

It is not giving me any error. The app just force closes after parsing and printing the response.
The issue exist only for flutter and not for dart.
Just tested for android, iOS, mac and web. The issue exist for all the platform except web.
Yes, both the log for Json String and Bundle Response appear to show correct json and it may not have been the cause for the app to crash. However there is no error log and the app closes right after parsing and printing the response.

Can you please clone this repo and check if the issue exist for you.

from fhir.

binismaharjan avatar binismaharjan commented on July 21, 2024

Found the problem and solution.
Problem was incompatible flutter and dart version used in the project.
I was using
environment: sdk: '>=2.19.2 <3.0.0'
Solution was to change min dart version from 2.19.2 to 2.19.6
environment: sdk: '>=2.19.6 <3.0.0'
I also upgraded flutter to latest stable version

Thanks again. Closing the issue

from fhir.

Related Issues (6)

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.