{"id":16352345,"url":"https://github.com/melbournedeveloper/fhir_client","last_synced_at":"2025-09-05T00:35:31.599Z","repository":{"id":234818256,"uuid":"789563109","full_name":"MelbourneDeveloper/fhir_client","owner":"MelbourneDeveloper","description":"Dart/Flutter library for consuming FHIR server APIs. Simple, stateless http extensions that make it easy to consume FHIR","archived":false,"fork":false,"pushed_at":"2024-06-06T21:36:28.000Z","size":7441,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T16:13:46.586Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/fhir_client","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MelbourneDeveloper.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-20T22:44:21.000Z","updated_at":"2024-12-21T01:55:37.000Z","dependencies_parsed_at":"2024-04-20T23:36:36.291Z","dependency_job_id":"52d7ada1-6f64-465b-a346-52814a0c5d23","html_url":"https://github.com/MelbourneDeveloper/fhir_client","commit_stats":null,"previous_names":["melbournedeveloper/fhir_client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MelbourneDeveloper%2Ffhir_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MelbourneDeveloper%2Ffhir_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MelbourneDeveloper%2Ffhir_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MelbourneDeveloper%2Ffhir_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MelbourneDeveloper","download_url":"https://codeload.github.com/MelbourneDeveloper/fhir_client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245043885,"owners_count":20551845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T01:25:49.088Z","updated_at":"2025-03-23T01:30:59.320Z","avatar_url":"https://github.com/MelbourneDeveloper.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fhir_client\n\n## Build Modern Healthcare Systems with Flutter and Dart\n\n`fhir_client` simplifies working with FHIR® data in Dart. It provides a user-friendly API for interacting with FHIR® servers and stands out for its non-destructive JSON handling. It uses the library [`Jayse`](https://github.com/MelbourneDeveloper/Jayse) to preserve the integrity of FHIR® data during the serialization and deserialization processes. This feature ensures that all data elements are accurately represented, enabling type-safe operations without data loss when working with FHIR® servers.\n\nThe source generator generates the resource model code from the FHIR® definitions, ensuring that the models match the FHIR® version. The current aim is R4, but importantly, the library is designed to work with any server version without causing data loss or corruption.\n\nIt offers straightforward methods for various FHIR operations such as searching for resources with a basic Dart `http` client. An extensive test suite proves the robustness so you can be sure that the library provides reliable and efficient development for interoperable healthcare applications. \n\n`fhir_client` goes further than just serializing and deserializing FHIR® messages. It provides resource metadata in the form of Field Definitions, which are used to validate the data. This allows you to receive any resource JSON, and validate it for a particular FHIR® version. It is also toolkit for working with, and improving FHIR® data quality.\n\n#### Disclaimer\n\n\u003csmall\u003eFHIR® is a registered trademark of Health Level Seven International (HL7®). This project is not affiliated with, endorsed, sponsored, or specifically approved by HL7® and does not purport to have any endorsement from HL7®. For more information, please visit https://www.hl7.org/fhir/. All copyrights © in FHIR® specifications are owned by HL7®.\u003c/small\u003e\n\n## Basics\n\nThis code searches for practitioner schedules. The code doesn't throw exceptions and you can guarantee it will return one of the two types you see here. When there is an error, the code will return an `OperationOutcome`.\n\n```dart\n//Search schedules and limit by count\nfinal searchSchedulesResult =\n    await client.searchSchedules(baseUri, count: 10);\n\n//Display the result\nprint('Schedules:');\nprint(\n  // The result can only be BundleEntries\u003cSchedule\u003e or\n  // OperationOutcome\u003cSchedule\u003e so this switch expression is exhaustive\n  switch (searchSchedulesResult) {\n    (final BundleEntries\u003cSchedule\u003e schedules) =\u003e\n      schedules.entries.map(formatSchedule),\n    (final OperationOutcome\u003cSchedule\u003e oo) =\u003e\n      'Error: ${oo.text!.status}\\n${oo.text?.div}',\n  },\n);\n```\n\n## What is FHIR®?\n\n[FHIR®](https://www.hl7.org/fhir/overview.html) stands for Fast Healthcare Interoperability Resources. It is a standard describing data formats and elements known as \"resources\" and an application programming interface (API) for exchanging electronic health records (EHR). The standard was created by the Health Level Seven International (HL7®) healthcare standards organization, and they own the trademark. \n\n## What is a FHIR Server?\n\nA [FHIR server](https://build.fhir.org/http.html) is a server that implements the FHIR standard as HTTP REST. It is a server that can store and retrieve FHIR resources. There are several open-source and commercial implementations of the server, and there are [freely available test servers](https://confluence.hl7.org/display/FHIR/Public+Test+Servers). The tests and examples in this repo use the [HAPI test server](https://hapifhir.io/). \n\n## Is it on-prem? Or Cloud?\n\nThe FHIR® server can be deployed on-prem or in the cloud. You can license a version of FHIR® Server, or you can use an open-source implementation such as [Microsoft's .NET one](https://github.com/microsoft/fhir-server). All the major cloud providers have an offering: \n\n- [Google Cloud Cloud Healthcare API](https://cloud.google.com/healthcare-api?hl=en) \n- [AWS HealthLake](https://aws.amazon.com/healthlake/), \n- [Azure Health Data Services](https://azure.microsoft.com/en-us/services/azure-api-for-fhir/)\n\nPrivacy and security are paramount in healthcare, so you should choose a provider that is compliant with the [Health Insurance Portability and Accountability Act (HIPAA)](https://www.hhs.gov/hipaa/index.html), [HITRUST®](https://hitrustalliance.net/) and the [General Data Protection Regulation (GDPR)](https://gdpr.eu/). All the major providers offer compliance so there's no need to spend time and effort implementing your own health compliance. \n\n## A Note on Modern Healthcare Systems\n\nHealth systems around the world are fragmented and aging. Many hospitals and doctors still use paper records. The systems that are digital are often old and not interoperable. This is changing rapidly. The FHIR® standard is the future of health systems, and health outcomes depend on the interoperability of health records.\n\nIf you're working on an aging system that doesn't implement FHIR®, you need to consider upgrading to a system that does, or at least implementing a FHIR® server that can act as a bridge between your system and other health systems. \n\nGovernments all over the world are mandating FHIR for record keeping and moving to FHIR® is a safe bet. This is [what they US government has to say](https://www.hhs.gov/about/news/2023/03/27/new-federal-health-strategy-sights-heathier-innovative-equitable-health-care-experience.html):\n\n\u003e Health IT is integral to how health care is delivered, how health is managed, and how the health of populations and communities is tracked. Thanks in part to the development of common standards, such as the United States Core Data for Interoperability (USCDI) and Health Level Seven International® (HL7®) Fast Healthcare Interoperability Resources® (FHIR®), health information has become more accessible and useful. \n\n## Getting Started\n\nJust install the this library in the usual way. The library adds several extension methods to the `http` package `Client` class and that's it. For example, this the example project searches for several different resources in parallel. It's safe to do this because each call will return a result instead of throwing an exception. \n\n```dart\nimport 'package:fhir_client/fhir_extensions.dart';\nimport 'package:fhir_client/models/basic_types/fixed_list.dart';\nimport 'package:fhir_client/models/codeable_concept.dart';\nimport 'package:fhir_client/models/reference.dart';\nimport 'package:fhir_client/models/resource.dart';\nimport 'package:fhir_client/models/value_sets/slot_status.dart';\nimport 'package:http/http.dart';\n\n//The base HAPI API URI\nconst baseUri = 'http://hapi.fhir.org/';\n\nFuture\u003cvoid\u003e main() async {\n  //Use any old HTTP Client and you can mock this\n  final client = Client();\n\n  final results = await Future.wait([\n    client.searchSlots(\n      baseUri,\n      count: 10,\n      status: SlotStatus.free,\n    ),\n    client.searchSchedules(baseUri, count: 10),\n    client.searchPractitionerRoles(baseUri, count: 10),\n  ]);\n\n  final formattedResult = results\n      .map(\n        (result) =\u003e switch (result) {\n          (final BundleEntries\u003cSchedule\u003e schedules) =\u003e\n            'Schedules:\\n\\n${schedules.formatResult(_formatSchedule)}',\n          (final BundleEntries\u003cSlot\u003e slots) =\u003e\n            'Slots:\\n\\n${slots.formatResult(_formatSlot)}',\n          (final BundleEntries\u003cPractitionerRole\u003e roles) =\u003e\n            'PractitionerRoles:\\n\\n'\n                '${roles.formatResult(_formatPractitionerRole)}',\n          (final OperationOutcome\u003cResource\u003e oo) when oo.text != null =\u003e\n            'Error: ${oo.text?.status}\\n'\n                '${oo.text?.div}',\n          _ =\u003e 'Unknown Result',\n        },\n      )\n      .join('\\n');\n\n  print(formattedResult);\n}\n```\n\nNotice that using pattern matching with the [`switch` expression](https://www.christianfindlay.com/blog/dart-switch-expressions) is a great way to handle the two possible outcomes of the search because it supports pattern matching.\n\n## Testing and Mocking\n\nThe library is designed to make testing easy. You can use the [`MockClient`](https://pub.dev/documentation/http/latest/http.testing/MockClient-class.html) class from the `http` package to mock the client. This is how you can mock the client, and you can find [this code](https://github.com/MelbourneDeveloper/fhir_client/blob/e72f37284b1bced7c82f9bef3f079581e4e7b61c/test/fhir_client_test.dart#L361) in the tests. Replace the file path with the path to a JSON file representing the response. This also works in widget tests. \n\n```dart\nMockClient _mockClient(String filePath) =\u003e MockClient(\n      (r) =\u003e Future.value(\n        Response(\n          File(filePath).readAsStringSync(),\n          200,\n        ),\n      ),\n    );\n```\n\nHere is an example of using the client extensions with a mocked client.\n\n```dart\ngroup('getResource API Call Tests', () {\n  /// A test function that can be called with a mocked client\n  /// or a real one\n  Future\u003cvoid\u003e readOrganization(Client client) async {\n    const path = 'baseR4/Organization/2640211';\n\n    final result =\n        await client.getResource\u003cOrganization\u003e(baseUri, path) as Organization;\n\n    expect(result.id, '2640211');\n    expect(result.identifier!.first.type!.text, 'SNO');\n  }\n  // ...\n});\n```\n### Step By Step Guide\n\n1. Use curl to get the JSON response from your FHIR server. For example:\n\n```bash\ncurl -X GET \"http://hapi.fhir.org/baseR4/Organization/2640211\" -H \"Content-Type: application/json\"\n```\n\n2. Save the JSON response to a file. For example [this file](test/responses/readorg.json). \n\n3. Create a `MockClient` in your test using the function above, and pass in the filename.\n\n4. Create a test that calls the extensions with the `MockClient` and the path to the file. For example:\n\n```dart\nfinal client = _mockClient('test/responses/readorg.json');\n\nfinal result = await client.getResource\u003cOrganization\u003e(baseUri, path) as Organization;\n```\n\n5. Make your assertions\n\nFor widget tests, just inject the `MockClient` at the base of your app instead of the standard `http` `Client`. You will be able to dynamically load JSON files based on the request URI path in the mock function.\n\n## Contributing\n\nThe repo is in its early stage. There is a source code generator that uses the FHIR® definitions to generate the models. The generator is in the `fhir_generator` folder. The generator is almost complete, and there are more resources being added all the time. Take a look at [this file](lib/models/resource.dart) to see what currently exists. The aim is to have a complete set of models for all the FHIR® resources. If you can help with this, please send a PR.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelbournedeveloper%2Ffhir_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmelbournedeveloper%2Ffhir_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelbournedeveloper%2Ffhir_client/lists"}