Coder Social home page Coder Social logo

swift-fhir's Introduction

FHIR Swift Classes

These are Swift classes representing data models of 🔥 FHIR elements and resources, compatible with iOS 11 and OS X 10.13 and later.

This work is Apache licensed. FHIR® is the registered trademark of HL7 and is used with the permission of HL7.

Versioning

Due to the complications of combining two volatile technologies, here's an overview of which version numbers use which Swift and FHIR versions.

  • The master branch should always compile and is on (point releases of) these main versions.
  • The develop branch should be on versions corresponding to the latest freezes.
  • The feature/latest-ci branch is updated from time to time with the latest and greatest.

See tags/releases.

Version Swift FHIR  
4.2 5.0 Packages 4.0.0-a53ec6ee1b R4
4.1 5.0 4.0.0-a53ec6ee1b R4
4.0 4.2 4.0.0-a53ec6ee1b R4
3.1 3.2 3.0.0.11832 STU 3
3.0 3.0 3.0.0.11832 STU 3
2.10 3.0 1.8.0.10521 STU 3 Freeze, Jan 2017
2.9 3.0 1.6.0.9663 STU 3 Ballot, Sep 2016
2.8 3.0 1.0.2.7202 DSTU 2 (+ technical errata)
2.4 2.2 1.6.0.9663 STU 3 Ballot, Sept 2016
2.3 2.3 1.0.2.7202 DSTU 2 (+ technical errata)
2.2.3 2.2 1.0.2.7202 DSTU 2 (+ technical errata)
2.2 2.0-2.2 1.0.2.7202 DSTU 2 (+ technical errata)
2.1 2.0-2.2 1.0.1.7108 DSTU 2
2.0 2.0-2.2 0.5.0.5149 DSTU 2 Ballot, May 2015
1.0 1.2 0.5.0.5149 DSTU 2 Ballot, May 2015
0.2 1.1 0.5.0.5149 DSTU 2 Ballot, May 2015
0.1 1.0 0.0.81.2382 DSTU 1

SMART on FHIR

The Swift-SMART framework utilizes these classes.

Progress

Here's a rough list of what still needs to be done.

[ ] Remove _isSummaryResource workaround to STU-3's nMin/isSummary errors
[ ] More convenience methods to working with resources in code
[ ] Nice support for simple PATCH operations
[ ] Separate resource models from base models; needs untangling of
    _owningResource, _owningBundle (easy), _resolved etc.
[ ] Handle resource versions nicely
[ ] Create a default behavior when a modifierExtension is detected
[ ] Update/modernize FHIRSearch
[ ] Search: report search parameters that the server ignored

Working, at least to some extent:

  • Classes generated for FHIR's base resources
    • Use custom structs for primitive types
    • Use custom Date/Time/DateTime/Instant structs
    • Generate enums for many closed ValueSets
  • Create elements and resources programmatically
  • Use a FHIR server protocol for REST interactions with a server
  • Deserialize from JSON
    • Tells you which mandatory properties were missing,
    • which properties were not expected or
    • which were of a wrong type
  • Serialize to JSON
    • Refuses to serialize incomplete elements
  • Resolve contained/bundled/relative/absolute resource references
  • Contain resources
  • Create enums for code type properties
  • Construct searches with NoSQL-like statements (cf. fhir.js)
  • Perform operations
  • Use example resources for auto-created class unit tests
    • Tests deserialization from file
    • Tests serialization from deserialized instances

Naming Convention

Standard Swift naming conventions apply. Tabs are used for indentation and spaces for alignment – the best of both worlds. Classes representing FHIR resources do not have a prefix. Custom classes and protocols start with FHIR to not make them clash with element or resource classes and make them easily distinguishable.

FHIR Data Models

Classes are generated from FHIR resource definitions with our Python FHIR parser.

Verbousness

Swift is statically typed and introspection is very limited at the time. Therefore the generator needs to be a bit more verbose and create class-level serializers/deserializers, rather than looking at class properties at runtime and figure out how to serialize/deserialize.

Cardinality

Some data models have properties with a cardinality of a minimum of 1. While these can be enforced to never be nil in Swift by not making them Optionals, they are still optional to enable uniform initializers that only take a JSON dictionary. For classes representing models with non-optional properties, a convenience initializer is supplied to reflect the need to set those properties without enforcing it.

Contained Resources

FHIR makes use of contained resources. An extension on the Reference class is included that adds method to handle reference resolving.

To resolve resource references, call resolve(ModelClass) { resource in } on a reference property, which will return an instance of the referenced type in the callback if resolved successfully. To contain a resource and receive a Reference instance, call parent.containResource(contained)

// create a prescription with a contained medication
let order = MedicationRequest()
let medication = Medication()
medication.id = "med"
do {
    order.medicationReference = try order.containResource(medication)
}
catch let error {
    // failed to contain, either because no id or containing itself
}

// resolve the contained medication
order.medication?.resolve(Medication.self) { medication in
	if let medication = medication {
		// successfully resolved
	}
}

Search

The client supports the NoSQL-like approach proposed and used by fhir.js.

Compartments

Search can be restricted to compartments, these however are not yet supported in the SMART server nor in these classes.

[ ] Patient/23/procedure?date=>2010-01-01&date=<2011-12-31

Referenced (not yet implemented)

If search is restricted to a reference property, this applies:

  • If the search token is merely an id, i.e. it does not contain a forward slash, a type restricted search is constructed based on which instance method is called: GET {base-url}/Thing?referenced:InstanceType={id}
  • If the search token does contain a forward slash it is assumed to be an absolute reference and no :InstanceType will be appended:
    GET {base-url}/Thing?referenced={uri}

Packaging

The full build of the framework will include all FHIR resources, which will result in a rather large binary. Take a look at the package.py script: provide one or more resource names when invoking the script from command line and it will output all the elements and resources that are needed for the desired resources. You may then be able to remove unnecessary resources, which unfortunately is a tedious task and requires fumbling with the factory.

There is an experimental SwiftFHIRMin-iOS build target which only includes a minimal set of resources. The problem here is that the factory is excluded and hence dereferencing, bundles and contained resources won't be properly instantiated.

swift-fhir's People

Contributors

drdavec avatar gravicle avatar heimb avatar jeffreytaylor avatar namalu avatar p2 avatar xmlmodeling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-fhir's Issues

Duplicate case Quantity in FHIRAbstractBase+Factory.swift

In 4.0.0 build, generator produces duplicate case statements for Quantity in FHIRAbstractBase+Factory.swift. Removed duplicate case before commit to eliminate compiler warning. Adding this Issue to track resolution.

case "ProvenanceEntity":
	if let res = ProvenanceEntity(json: json, owner: owner, context: &context) as? T { return res }
case "Quantity":
	if let res = Quantity(json: json, owner: owner, context: &context) as? T { return res }
case "Quantity":
	if let res = Quantity(json: json, owner: owner, context: &context) as? T { return res }
case "Questionnaire":
	if let res = Questionnaire(json: json, owner: owner, context: &context) as? T { return res }

use empty Arrays to express emptiness

Most models objects have optional arrays (e.g. Patient.name, Patient.identifier) which leads to two different ways to express emptiness: the array is nil, or the array is empty.

It would be simpler if clients didn't have to check for both types of emptiness, and make the arrays non-optional.

Are there any barriers to making this change?

btw, I'm at the FHIR dev days conference. Are you around?

Could not find remote branch 2.2 to clone

pod install:
Error:
[!] Error installing FHIR
[!] /usr/bin/git clone https://github.com/smart-on-fhir/Swift-FHIR.git /var/folders/mq/b_s7ht696vd3xkr6m5qz13ww00134y/T/d20161121-51618-1ey3k3n --single-branch --depth 1 --branch 2.2

warning: Could not find remote branch 2.2 to clone.
fatal: Remote branch 2.2 not found in upstream origin

My Podfile looks like:

pod 'AFNetworking', '> 2.2'
pod 'AFNetworking-RACExtensions', '
> 0.1'
pod 'BlocksKit', '> 2.2'
pod 'Classy'
pod 'CRToast', '
> 0.0'
pod 'iCarousel', '> 1.8.1'
pod 'JSONModel'
pod 'MMPReactiveStompClient', '
> 0.2'
pod 'PDKeychainBindingsController', '> 0.0'
pod 'SocketRocket', '
> 0.4'

use_frameworks!
pod 'FHIR', '2.2'
pod 'Alamofire', '> 3.0'
pod 'Charts', '
> 2.2'
pod 'JWTDecode', '> 1.0'
pod 'ObjectMapper', '1.1.5'
pod 'Starscream', '
> 1.1'

target :CertifyHLTests do
pod 'BlocksKit', '~> 2.2'
end

versioning errors when using swift-fhir as a package.swift dependency

I am using swift-fhir in IBM Bluemix which runs swift on Ubuntu. In my package.swift file, I am specifying the swift fhir dependency for my app like this:

.Package(url: "https://github.com/smart-on-fhir/Swift-FHIR.git", majorVersion: 2, minor: 9)

Then, during the build phase, while trying to clone the swift fhir repository, I get this error:

swift-build: error: The dependency graph could not be satisfied. The package (https://github.com/smart-on-fhir/Swift-FHIR.git) with version tag in range (2.9.0..<2.9.9223372036854775807) is not found. Found tags ([2.2.1, 2.2.2, 2.2.3, 2.2.4])

If I instead change the swift fhir dependency to this:

.Package(url: "https://github.com/smart-on-fhir/Swift-FHIR.git", versions: Version(2, 0, 0)..<Version(2, 9, 0) )

then it will resolve, but only to version 2.2.4

Any ideas? Is there a more correct way to specify the version(s) for swift-fhir ?

Thanks.

Cannot inherit from non-open class 'List' outside of its defining module

In Swift 3 there are two new access levels on classes and functions. Public classes (as all these are) are not allowed to be subclassed outside of the defining module.

I was hoping to subclass some of the classes provided in this repository and am unable to do this. I have noticed that the develop branch has changes for this. Do you have a timeframe as to when this may become available on the master branch?

Thanks for your assistance.

Use of `_summary=true` for `/metadata` will not return OAuth uris

The SWIFT FHIR client uses summary listing for the capability statement:

https://github.com/smart-on-fhir/Swift-FHIR/blob/master/Sources/Client/FHIROpenServer.swift#L78

Servers are not required or expected to return extensions in summary results. Only HAPI based implementations include these extensions in summary listings (and it appears only in capability statement) at the moment.

According to: http://hl7.org/fhir/search.html#summary

"There is some question about the inclusion of extensions in the summary. Additional rules may be made around this in the future", so there is at least ambiguity about whether a server will return these extensions and it is clear that it is not required too.

Consequently summary listing is unreliable as a way to obtain the OAuth URIs.

Canonical URL

Canonical URL:

A URI that refers to a resource by its canonical URL (resources with a url property). The canonical type differs from a uri in that it has special meaning in this specification, and in that it may have a version appended, separated by a vertical bar (|). Note that the type canonical is not used for the actual canonical URLs that are the target of these references, but for the URIs that refer to them, and may have the version suffix in them. Like other URIs, elements of type canonical may also have #fragment references

The canonical URIs in R4 aren't being handled in FHIRURL. Swift's URL does not accept a vertical bar.

Hence, a uri like http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire|3.5.0 fails.

Possibly two approaches we can take

  1. Add a let version: String? to FHIRURL, catch the vertical bars on initialization, reassign to version
  2. Entirely new class? This is perhaps unnecessary.

Any suggestions?

Question: Is it possible to access "_primitive" fields using SwiftFHIR?

Hi,

I'm using Swift-FHIR version 2.8 to parse FHIR models in our project. I've come across an API that uses this technique (as described here http://hl7.org/fhir/DSTU2/json.html#primitive) for passing additional data for a primitive type.

More specifically, I've access to Dstu2 FHIR 1.0 "MedicationStatement.status" which is an Optional String type. However, the API also exposes "MedicationStatement._status" which contains an extension with additional data.

I was wondering, if there was any way to access this field using SwiftFHIR.

Many thanks,
Nishadh

Use of unresolved identifier 'translations' in ValueSet+Localization.swift when XCode upgraded to Swift 3.1

I made the mistake of updating my macOS and XCode versions today and now I'm getting a problem while trying to build my project.

It appears it doesn't understand the translations object in the extension of Array where Element == ValueSetComposeIncludedConceptDesignation

Perhaps I don't really know how to set it to compile with Swift 3.0 or it's not that easy, so I'm kinda stuck at this point.

Hopefully you see the same thing and can help fix this problem :)

Thanks so much for your help!

Converting Apple Watch's ECG Data to a FHIR Observation

Hello Ladies and Gentlemen,

I am currently working on a project which takes raw ECG data (ECGs were taken on the Apple Watch) from an Apple Health export and sends that data to a VONK server. The workflow looks like this:

Export health data from health app --> Receive data via share extension --> Unzip data --> Read in CSVs --> Create an observation with Swift-FHIR --> Send observation (or resource) to server with Swift-SMART

Steps 1-4 are already implemented. However, I'm having trouble understanding how to create an observation from the CSVs with the ECG's data. More specifically:

  1. What is the required format for data for an ECG observation?
  2. How do I pass the data from the CSV into the observation?

Code examples would be much appreciated. Here is a gist with a sample CSV of one of the ECGs taken.

I'm sorry if this is trivial. I'm new to Swift and FHIR and appreciate your help in advance.

Regards

Question: Is it possible to have a project that references Swift-FHIR 3.0 AND Swift-FHIR 2.8?

We are trying to develop an app that needs to be able to point at different FHIR servers that may also be serving up different versions of the FHIR spec. We'd like to be able to handle parsing a FHIR response from a FHIR DSTU 2 and/or a FHIR DSTU3 server.

Is this possible with Swift-FHIR? I currently use cocoapods to use the 3.0 version of Swift-FHIR and realize maybe this can't be done with cocoapods but I wanted to ask here if it's technically possible to have the same app able to parse multiple versions of a FHIR response based on what version the FHIR server is.

Thanks so much for your input, it is much appreciated!

Trying to deploy Swift-FHIR to IBM Bluemix.

Hi there. I am interested in using these swift models for a swift api I am creating on the IBM Bluemix platform. Bluemix runs Swift on Ubuntu Linux, and I figured out while trying to deploy swift-fhir to my bluemix app, and getting lots of compile errors, that certain swift functionality and classes on MacOSX are not compatible with Swift on Linux (the most errors seemed to be in DateAndTime.swift). I did some research and found out: "Swift programs running on Linux with the Swift Core Libraries use a version of Foundation natively written in Swift, without an Objective-C runtime to bridge to. Since Swift does not interoperate with Objective-C on Linux, there is no support for bridging conversions such as string as NSString or value as AnyObject" (quote is from https://developer.apple.com/swift/blog/). I am wondering if you have any plans to make Swift-FHIR work on Ubuntu?

CocoaPods

I think it would be handy to create a cocoapod for this library. In order to do so the code will need the following changes:

  • Needs a license file.
  • Needs a git tag with the same name as the version. In this case you'd need a tag called 0.0.82.2943.
  • Cocoapods for Swift is only supported on iOS 8 and above. The readme currently lists support as iOS7 and above

If you're interested, I'd be glad to submit a pull request with a valid podspec once these issues are cleared up.

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.