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
- In
pubspec.yaml,fhirbecomesfhir_r4: ^0.14.1andfhir_at_restbecomesfhir_r4_at_rest: ^0.15.0, on the same lines. Overrides of either are dropped. Imports ofpackage:fhir/...andpackage:fhir_at_rest/...point at the new packages. - It runs the Dart analyzer over the app, fixes every error whose shape it
knows, and repeats until a round changes nothing:
fhirIdisid.- A
Stringgoing into a FHIR field gets.toFhirString(and the same forint,double,bool,DateTime,Uriand lists of them). A FHIR value read back as aStringgets.valueString(orvalueInt,valueDouble,valueBoolean,valueDateTime,valueUri). FhirCode(...)where the field now has its own code type becomes that type:gender: FhirCode('male')isgender: AdministrativeGender('male').FhirCode.asConstis gone.- The old Dart enums whose type was renamed (
HumanNameUseisNameUse, and 13 others). FhirDateTime(dateTime)isFhirDateTime.fromDateTime(dateTime); with a String it isFhirDateTime.fromString. The same forFhirDateandFhirInstant.valueString:,valueReference:and the other valuexparameters arevalueX:.resourceType:is no longer a parameter.Extension.urlis aFhirString.
- Requests:
FhirRequest.search(...)and the other four becomeFhirSearchRequest(...),FhirReadRequest(...)and so on, andrequest.request(headers: h)becomessendForResource(request), with the headers moved into the request.sendForResourceandrestfulParametersare written tolib/fhir_rest_compat.dart.sendForResourcebehaves as the oldrequest()did: it returns the answer as a Resource, or an OperationOutcome on any failure, and never throws. - Reads through
dynamic, which the analyzer cannot check:data.resource.fhirIdisdata.resource.id, and.field.valueis the getter for that field (client.fhirUri.valueisclient.fhirUri.valueUri). - A value from decoded JSON passed straight into a FHIR field
(
HumanName(family: json['family'])) compiles with both packages and fails when run. Withstrict-caststurned on for one pass, these become(json['family'] as String?)?.toFhirString. - Comparisons that compile and give a different answer.
FhirString('a') == 'a'is true, but'a' == FhirString('a')is false, and so is every lookup made from the String's side or by hash. The FHIR side is read back inexpect(name.family, 'Smith'),'Smith' == name.family, aswitch (name.family)with String cases, andcontains,remove,containsKey,containsValueand[]on a collection of Dart values: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 does not fix
- A
SetorMapthat now holds FHIR values, looked up with a Dart value (families.contains('Smith')), never matches. These are listed with the errors left; the fix belongs where the collection is built. AListthat holds FHIR values does match, becausecontainscalls the FHIR value's==. - A FHIR value that reaches a comparison through
Objectordynamic. - A FHIR value read through
dynamicother than the reads in step 4 fails only when run. - The old
FhirDateTime(null)gave the current time, marked invalid. The migration writesx?.toFhirDateTime, which leaves the field empty whenxis 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.
Libraries
- fhir_migrate
- Moves a Dart or Flutter app from
fhirandfhir_at_rest0.12 tofhir_r4andfhir_r4_at_rest.