Almost done with this. The basic bits are complete and I'm now cleaning up code and testing some more things.
I've started to post information on the approach here https://www.linkedin.com/pulse/connecting-ios-your-emr-using-healthkit-cda-part-one-eric-whitley. More posts coming over the next few days and I hope to release the code to github for initial critique early next week.
It's a pretty direct port of the CCDA and C32 import/export functionality from the Ruby Health-Data-Standards project. I'm not yet touching QRDA1, but that would be reasonably straight-forward to wire up (minus all of the HQMF measure references, etc. - not touching that). The only sections/entries/templates that I built in are the ones currently in use by that project.
Re: HealthKit <-> CDA vocabulary linking, I got the expert input from a physician who is a super savvy informaticist, so that was incredibly helpful. I wound up having to build in bi-direction concept mapping hooks, so you can say "oh, an X term from SNOMED CT is a HealthKit heart rate sample type" for import, but then say "but when you export, use the following LOINC term." That kind of thing. All of those maps can be changed at runtime in case you don't agree with my educated guesses or your personal CDAs use nonstandard vocabularies or alternative terms.
I wired up some rudimentary (and horribly bad) unit string parsing and handling, but set that bit up so you can inject a closure and just say "I definitely know better" and supply your own logic. I need to test it completely, but I think I also successfully provided the ability for an app to consume a user's HKHealthStore unit preferences (preferredUnitsForQuantityTypes) from a the app would supply. That's optional.
This is more or less my first attempt at doing anything in Swift and iOS, so I expect the code to garner some feedback (EX: "you have memory leaks" etc.).