fhir 0.0.5

Dart native js
Flutter Android iOS web

FHIR library of versions R4, STU3, DSTU2, and R5 (draft) for Dart & Flutter.

FHIR #

A Dart/Flutter package for working with FHIR resources.

It contains packages for the 3 released FHIR versions:

As well as the R5 Preview #1:

Say Hello! #

  • As all parts of this are new (FHIR, Flutter, using the two together), I'd love to hear from you if you're working in this space. You can email me at jgfaulkenberry@gmail.com.

How To Use #

In order to use this package in your app, you must include the following in your pubspec.yaml file under dependencies:

dependencies:
  fhir: ^0.0.5

Or if you want to include the most recent unreleased version from Github

fhir:
  git:
    url: git://github.com/Dokotela/fhir.git

Then, in any file where you're going to be using it, simply import it like this:

import 'package:fhir/r4.dart';

Or, you may need to rename the package, for instance, there are some variables FHIR uses that overlap with dart:core, or if you're going to be using more than oen version of FHIR in the same file:

import 'package:fhir/r4.dart' as r4;
import 'package:fhir/stu3.dart' as stu3;

And then just remember to append r4 or stu3 to any variables you use from the library.

Currently this package is really just for serializing/deserializing FHIR data, and being able to create FHIR resources.

To do something like create a patient, you can do the following::

var newPatient = Patient(
  resourceType: 'Patient',
  name: [
    HumanName(family: 'LastName', given: ['FirstName'])
  ],
  birthDate: Date('2020-01-01'),
  gender: PatientGender.female,
);

If you're instead trying to get data from a server (currently I haven't implemented SMART on FHIR so it would need to be an open server, HAPI for instance - make sure you choose the right version you're interested in), a very simple example of querying and then printing the result:

import 'dart:convert';

import 'package:fhir/r4.dart';
import 'package:http/http.dart';

Future main() async {
  var server = 'http://hapi.fhir.org/baseR4';
  var headers = {'Content-type': 'application/json'};
  var desiredResource = 'Patient';
  var response = await get('$server/$desiredResource', headers: headers);
  var searchSetBundle = Bundle.fromJson(json.decode(response.body));
  print(searchSetBundle.toJson());
}

All of the FHIR resources are immutable classes using the freezed package, which means you can take advantage of it's functionality for things like copying/updating:

  var changePatientName = newPatient.copyWith(name: [
    HumanName(family: 'NewLastName', given: ['SameFirstName'])
  ]);

And that's essentially all there is at this point. This is still very much a developing package, so there are likely to be breaking changes as I try and figure out how it should all work. I welcome any and all feedback, suggestions or pull requests.

Upcoming #

There are two big items I would really like to get to work to add functionality:

  1. Database - I'm working on a locally embedded, encrypted database using Sembast and SQFlite. Feel free to take a look, it's in the basic branch of my vigor repository.
  2. SMART - this one I could really use some help with. I think I understand the pieces, but I'm not sure the best way to try and implement it. But I do realize it's necessary to truly making this a useful package.

Validation #

R5 #

  • These are non-resource files that my package doesn't know how to read. From the sample files here: https://hl7.org/fhir/2020Feb/downloads.html, it won't properly serialize/deserialize package-min-ver.json, uml.json, hl7.fhir, hl7.fhir.r5.core.manifest.json, hl7.fhir.r5.expansions.manifest.json
  • It finds that the Id field is too long for questionnaireresponse-extensions-QuestionnaireResponse-item-subject.json
  • The padding in binary-example.json field renders it invalid

R4 #

  • All of the downloads here: https://www.hl7.org/fhir/examples-json.zip have been run through a tester to ensure proper serialization/deserialization using this FHIR package
  • I've compared each field from the input to the output and output to input as Maps. This should have revealed if any fields were created or deleted. It also avoids issues with fields in a different order from input to output.
  • Known problems:
  1. There is an ID field in questionnaireresponse-extensions-QuestionnaireResponse-item-subject.json in the examples seems to be too long
  2. There is a Base64Binary binary-example.json field that has padding which renders it invalid
  3. There's also this file, package-min-ver.json, that I have no idea what to do with.

Stu3 #

Dstu2 #

  • All of the DSTU2 HL7 Examples from https://hl7.org/fhir/dstu2/validation-min.json.zip
  • In https://www.hl7.org/fhir/DSTU2/searchparameter.html there is an issue with the SearchParameter: at least according to this website, it does appear that the field "base" and "description" should be required. However, many, many of the examples that are provided on the website do not have those fields, so I have not made them mandatory.
  • In https://www.hl7.org/fhir/DSTU2/elementdefinition.html#ElementDefinition, it seems that in the type field, "code" is required, but if "_code" is present, this does not seem to be the case in the examples. I have therefore removed the requirement from the code field.
  • There are private fields in this FHIR version that appear to correlate to the private Element fields in R4. I cannot find these specifically stated anywhere, so I'm going to assume all R4 private fields are valid as long as there is a corresponding public field. A few of these should actually be lists. But if they are not in the examples, then I do not know which. So there are likely some that should be lists that I have not implemented as such.
  • Known Problems, a number of files appear to have Ids that are too long, all observations: observation-genetics-cg-prf-1a-Observation-gene-amino-acid-change.json, observation-genetics-cg-prf-1a-Observation-chromosome-genomicstart.json, observation-genetics-cg-prf-1a-Observation-condition-gene-dnavariant.canonical.json, observation-genetics-cg-prf-1a-Observation-condition-gene-dnavariant.json, observation-genetics-cg-prf-1a-Observation-gene-amino-acid-change.canonical.json, observation-genetics-cg-prf-1a-Observation-chromosome-genomicstart.canonical.json.

First Package #

This is the first time I've ever created a package, feedback and pull requests are welcome. I've also been started to implement type checking using Freezed. But if you run into any issues with this, either incorrect validation, or frustrating to work with returned failures, please let me know.

Code Generation #

I think it's the new compiling. It's actually great though, json_serializable and freezed are used extensively throughout. Note that sometimes freezed will give a stack overflow error if you try to do all code generation for the entire package at the same time. Also note that for fields that can take any resource, they have to be manually assigned. Currently this is done by passing the json object to resourceList. The fromJson code has to be changed in the 'g.dart' file.

Formatting Notes #

  • Class names: upper camel case.
  • Variables: lower camel case.
  • File names: snake case.
  • FHIR nested classes (including enums) listed under the primary class
  • There are a number of FHIR fields that are reserved words in Dart. For these, I have added a '_' to the end of the field. (note that this does not change the json format, as when that happens the @JsonKey has been added to the field like so:
@JsonKey(name: 'extension') List<FhirExtension> extension_,

A couple special notes about DSTU2 #

  • Because Dstu2 is not formatted as well as the newer versions, a number of the names end up being extremely long. What I have decided to do is the following:
    • If the field/class id in the schema is a single word("id": "integer" or "id": "ValueSet"), that word is used as the field or class name.
    • If the id is more than a single word AND it is a primitive type ("id": "ValueSet.expansion.contains.display" which is a string), the last word is used as the type, in this case the field would be: String display
    • If the id is 2 words and is NOT a primitive type ("id": "ValueSet.expansion"), the type is the two words combined with upper camel case, and the field is the last word: ValueSetExpansion expansion
    • if the id is more than 2 words and NOT a primitive type ("id": "TestScript.setup.action.operation.requestHeader"), the type is the first, next to last and last word combined with upper camel case, and the field is the last word: TestScriptOperationRequestHeader requestHeader
  • Many of the element fields I have included because they are included as part of the test resources. I could not find a full list online, so there may still be some element fields that I have missed.

FHIR datatypes (these are R4 (which is what everyone should be using, but since EHR vendors are doing everything they can to not share data, I am also working on stu3 and dstu2 as well) #

PrimitiveTypesGeneralTypesMetadataTypesSpecialTypesDraftTypes
base64binaryaddresscontactDetaildosagepopulation
booleanagecontributorelementDefinitionproductedShelfLife
canonicalannotationdataRequirementextensionprodCharacteristic
codeattachmentparameterDefinitionmetamarketingStatus
datecodeableConceptrelatedArtifactnarrativesubstanceAmount
dateTimecodingtriggerDefinitionreference
decimalcontactPointusageContext
idcountrelatedArtifact
instantdistancetriggerDefinition
integerdurationusageContext
markdownhumanNameexpression
oididentifier
positiveIntmoney
stringmoneyQuantity
timeperiod
unsignedIntquantity
urirange
urlratio
sampledData
signature
simpleQuantity
timing
ResourceTypesby Category
Base
IndividualsEntities1Entities2WorkflowManagement
GroupEndpoingBiologicallyDerivedProductAppointmentEncounter
PatientHealthcareServiceDeviceAppointmentResponseEpisodeOfCare
PersonLocationDeviceMetricScheduleFlag
PractitionerOrganizationSubstanceSlotLibrary
PractitionerRoleOrganizationAffiliationVerificationResultList
RelatedPerson
Clinical
SummaryDiagnosticsMedicationsCareProvisionRequestAndResponse
AdverseEventBodyStructureImmunizationCarePlanCommunication
AllergyIntoleranceDiagnosticReportImmunizationEvaluationCareTeamCommunicationRequest
ClinicalImpressionImagingStudyImmunizationRecommendationGoalDeviceRequest
DetectedIssueMediaMedicationNutritionOrderDeviceUseStatement
FamilyMemberHistoryMolecularSequenceMedicationAdministrationRequestGroupGuidanceResponse
ProcedureObservationMedicationDispenseRiskAssessmentSupplyDelivery
QuestionnaireResponseMedicationKnowledgeVisionPrescriptionSupplyRequest
SpecimenMedicationRequest
MedicationStatement
Financial
SupportBillingPaymentGeneral
CoverageClaimPaymentNoticeAccount
CoverageEligibilityRequestClaimResponsePaymentReconciliationChargeItem
CoverageEligibilityResponseInvoiceChargeItemDefinition
EnrollmentRequestContract
EnrollmentResponseExplanationOfBenefits
InsurancePlan
Foundation
ConformanceTerminologySecurityDocumentsOther
CapabilityStatementCodeSystemAuditEventCatalogEntryBasic
CompartmentDefinitionConceptMapConsentCompositionBinary
ExampleScenarioNamingSystemProvenanceDocumentManifestBundle
GraphDefinitionTerminologyCapabilitiesDocumentReferenceLinkage
ImplementationGuideValueSetMessageHeader
MessageDefinitionOperationOutcome
OperationDefinitionParameters
SearchParameterSubscription
StructureDefinition
StructureMap
Specialized
Public Health And ResearchDefinitional ArtifactsEvidence Based MedicineQuality Reporting And TestingMedication Definition
ResearchStudyActivityDefinitionEffectEvidenceSynthesisMeasureMedicinalProduct
ResearchSubjectDeviceDefinitionEvidenceMeasureReportMedicinalProductAuthorization
EventDefinitionEvidenceVariableTestScriptMedicinalProductContraindication
ObservationDefinitionResearchDefinitionTestReportMedicinalProductIndication
PlanDefinitionResearchElementDefinitionMedicinalProductIngredient
QuesionnaireRiskEvidenceSynthesisMedicinalProductInteraction
SpecimenDefinitionMedicinalProductManufactured
MedicinalProductPackaged
MedicinalProductPharmaceutical
MedicinalProductUndesirableEffect
SubstanceNucleicAcid
SubstancePolymer
SubstanceProtein
SubstanceReferenceInformation
SubstanceSpecification
SubstanceSourceMaterial
5
likes
80
pub points
50%
popularity

Publisher

fhirdart.dev

FHIR library of versions R4, STU3, DSTU2, and R5 (draft) for Dart & Flutter.

Homepage
Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

dartz, freezed_annotation, json_annotation, string_validator

More

Packages that depend on fhir