Skip to main content

fhir_migrate 0.1.0 copy "fhir_migrate: ^0.1.0" to clipboard
fhir_migrate: ^0.1.0 copied to clipboard

Moves a Dart or Flutter app from the old `fhir` and `fhir_at_rest` packages (0.12) to `fhir_r4` and `fhir_r4_at_rest`.

fhir_migrate #

Moves a Dart or Flutter app from the old fhir and fhir_at_rest packages (0.12) to fhir_r4 and fhir_r4_at_rest.

dart pub global activate fhir_migrate
cd my_app
git commit -am "before fhir_r4"      # so the changes are a diff you can read
fhir_migrate .

It edits the app in place. It refuses to start when git shows uncommitted changes (pass --allow-dirty to override). --offline runs pub get offline.

What it does #

  1. In pubspec.yaml, fhir becomes fhir_r4: ^0.14.1 and fhir_at_rest becomes fhir_r4_at_rest: ^0.15.0, on the same lines. Overrides of either are dropped. Imports of package:fhir/... and package:fhir_at_rest/... point at the new packages.
  2. It runs the Dart analyzer over the app, fixes every error whose shape it knows, and repeats until a round changes nothing:
    • fhirId is id.
    • A String going into a FHIR field gets .toFhirString (and the same for int, double, bool, DateTime, Uri and lists of them). A FHIR value read back as a String gets .valueString (or valueInt, valueDouble, valueBoolean, valueDateTime, valueUri).
    • FhirCode(...) where the field now has its own code type becomes that type: gender: FhirCode('male') is gender: AdministrativeGender('male'). FhirCode.asConst is gone.
    • The old Dart enums whose type was renamed (HumanNameUse is NameUse, and 13 others).
    • FhirDateTime(dateTime) is FhirDateTime.fromDateTime(dateTime); with a String it is FhirDateTime.fromString. The same for FhirDate and FhirInstant.
    • valueString:, valueReference: and the other value[x] parameters are valueX:. resourceType: is no longer a parameter.
    • Extension.url is a FhirString.
  3. Requests: FhirRequest.search(...) and the other four become FhirSearchRequest(...), FhirReadRequest(...) and so on, and request.request(headers: h) becomes sendForResource(request), with the headers moved into the request. sendForResource and restfulParameters are written to lib/fhir_rest_compat.dart. sendForResource behaves as the old request() did: it returns the answer as a Resource, or an OperationOutcome on any failure, and never throws.
  4. Reads through dynamic, which the analyzer cannot check: data.resource.fhirId is data.resource.id, and .field.value is the getter for that field (client.fhirUri.value is client.fhirUri.valueUri).
  5. A value from decoded JSON passed straight into a FHIR field (HumanName(family: json['family'])) compiles with both packages and fails when run. With strict-casts turned on for one pass, these become (json['family'] as String?)?.toFhirString.
  6. Comparisons that compile and give a different answer: 'a' == FhirString('a') is false (while FhirString('a') == 'a' is true), and expect(name.family, 'Smith') fails. The FHIR side is read back: expect(name.family?.valueString, 'Smith').

What is left is printed, one error per line, for a person to decide. In the apps it was tested on, these were a Bundle built without a type (now required), a ternary mixing a FHIR value with a String, and a const that can no longer be const. Commented-out code is not changed.

What it cannot see #

  • Other comparisons through Object (list.contains('Smith') on a list that now holds FhirStrings, a map keyed by a FHIR value).
  • A FHIR value read through dynamic other than the reads in step 4 fails only when run.
  • The old FhirDateTime(null) gave the current time, marked invalid. The migration writes x?.toFhirDateTime, which leaves the field empty when x is null.

Checked on #

App Errors after switching packages Left after fhir_migrate
HL7 Physical Activity patient app 1,281 0
HL7 Physical Activity provider app 1,245 14, all there before the switch (a file missing from that repo)
Bahmni Connect2 51 6

For the patient app, nine of its Observation builders give the same JSON before and after, and its own patient search and Observation upload give the same results against a HAPI FHIR server. Bahmni's own tests give the same results before and after (31 pass, 1 skipped, 1 fails on time zone both times) once the 6 left are fixed by hand. RESULTS.md has the detail.

0
likes
150
points
109
downloads

Documentation

API reference

Publisher

verified publisherfhirfli.dev

Weekly Downloads

Moves a Dart or Flutter app from the old `fhir` and `fhir_at_rest` packages (0.12) to `fhir_r4` and `fhir_r4_at_rest`.

Homepage
Repository (GitHub)
View/report issues

Topics

#fhir #healthcare #migration #hl7

License

MIT (license)

Dependencies

analyzer, path, yaml, yaml_edit

More

Packages that depend on fhir_migrate