Skip to content

Commit

Permalink
BREAKING: now has enums for many code-type properties
Browse files Browse the repository at this point in the history
  • Loading branch information
p2 committed Nov 5, 2016
1 parent 3edc762 commit d54866a
Show file tree
Hide file tree
Showing 270 changed files with 12,511 additions and 5,257 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
## x.x

- Change initializers: provide convenience initializers; initializers taking JSON may throw
- Generate enums for many closed ValueSets
- Much better model validation


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Working, at least to some extent:
- Classes generated for FHIR's base resources
+ Use Swift native types whenever possible
+ 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
Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/FHIROpenServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ open class FHIROpenServer: FHIRServer {
if nil == best {
best = rest
}
else if "client" == rest.mode {
else if .client == rest.mode {
best = rest
break
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/FHIROperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ open class FHIROperation: CustomStringConvertible {
continue
}

if "in" == param.use {
if .in == param.use {

// have the parameter, validate it
if nil != inParams?[param.name!] {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/FHIRServerDataResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ open class FHIRServerJSONResponse: FHIRServerDataResponse {
// inspect OperationOutcome if there was an error
if status >= 400 {
if let erritem = self.outcome?.issue?.first {
let errstr = "[\(erritem.severity ?? "unknown")] \(erritem.diagnostics ?? "unknown")"
let errstr = "[\(erritem.severity?.rawValue ?? "unknown")] \(erritem.diagnostics ?? "unknown")"
self.error = FHIRError.requestError(status, errstr)
}
else if let errstr = json?["error"] as? String {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Client/Patient+SMART.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ extension Patient {
}
var useName: HumanName?
for name in names {
if nil == useName || "usual" == name.use {
if nil == useName || .usual == name.use {
useName = name
}
else if let use = name.use, "usual" == use || "official" == use {
else if let use = name.use, .usual == use || .official == use {
useName = name
}
}
Expand Down
25 changes: 15 additions & 10 deletions Sources/Models/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// Account.swift
// SwiftFHIR
//
// Generated from FHIR 1.7.0.10104 (http://hl7.org/fhir/StructureDefinition/Account) on 2016-11-03.
// Generated from FHIR 1.7.0.10127 (http://hl7.org/fhir/StructureDefinition/Account) on 2016-11-04.
// 2016, SMART Health IT.
//

import Foundation


/**
* Tracks balance, charges, for patient or cost center.
*
* A financial tool for tracking value accrued for a particular purpose. In the healthcare field, used to track
* charges for a patient, cost centers, etc.
*/
Tracks balance, charges, for patient or cost center.

A financial tool for tracking value accrued for a particular purpose. In the healthcare field, used to track charges
for a patient, cost centers, etc.
*/
open class Account: DomainResource {
override open class var resourceType: String {
get { return "Account" }
Expand Down Expand Up @@ -47,8 +47,8 @@ open class Account: DomainResource {
/// Who is responsible?.
public var owner: Reference?

/// active | inactive | entered-in-error.
public var status: String?
/// Indicates whether the account is presently used/useable or not.
public var status: AccountStatus?

/// What is account tied to?.
public var subject: Reference?
Expand Down Expand Up @@ -178,7 +178,12 @@ open class Account: DomainResource {
if let exist = json["status"] {
presentKeys.insert("status")
if let val = exist as? String {
self.status = val
if let enumval = AccountStatus(rawValue: val) {
self.status = enumval
}
else {
errors.append(FHIRValidationError(key: "status", problem: "the value “\(val)” is not valid"))
}
}
else {
errors.append(FHIRValidationError(key: "status", wants: String.self, has: type(of: exist)))
Expand Down Expand Up @@ -246,7 +251,7 @@ open class Account: DomainResource {
json["owner"] = owner.asJSON(errors: &errors)
}
if let status = self.status {
json["status"] = status.asJSON()
json["status"] = status.rawValue
}
if let subject = self.subject {
json["subject"] = subject.asJSON(errors: &errors)
Expand Down
70 changes: 40 additions & 30 deletions Sources/Models/ActivityDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// ActivityDefinition.swift
// SwiftFHIR
//
// Generated from FHIR 1.7.0.10104 (http://hl7.org/fhir/StructureDefinition/ActivityDefinition) on 2016-11-03.
// Generated from FHIR 1.7.0.10127 (http://hl7.org/fhir/StructureDefinition/ActivityDefinition) on 2016-11-04.
// 2016, SMART Health IT.
//

import Foundation


/**
* The definition of a specific activity to be taken, independent of any particular patient or context.
*
* This resource allows for the definition of some activity to be performed, independent of a particular patient,
* practitioner, or other performance context.
*/
The definition of a specific activity to be taken, independent of any particular patient or context.

This resource allows for the definition of some activity to be performed, independent of a particular patient,
practitioner, or other performance context.
*/
open class ActivityDefinition: DomainResource {
override open class var resourceType: String {
get { return "ActivityDefinition" }
Expand All @@ -23,8 +23,8 @@ open class ActivityDefinition: DomainResource {
/// When activity definition approved by publisher.
public var approvalDate: FHIRDate?

/// communication | device | diagnostic | diet | drug | encounter | immunization | observation | procedure | referral | supply | vision | other.
public var category: String?
/// High-level categorization of the type of activity.
public var category: ActivityDefinitionCategory?

/// Detail type of activity.
public var code: CodeableConcept?
Expand Down Expand Up @@ -74,8 +74,8 @@ open class ActivityDefinition: DomainResource {
/// Name for this activity definition (Computer friendly).
public var name: String?

/// patient | practitioner | related-person.
public var participantType: [String]?
/// The type of participant in the action.
public var participantType: [PlanActionParticipantType]?

/// What's administered/supplied.
public var productCodeableConcept: CodeableConcept?
Expand All @@ -95,8 +95,8 @@ open class ActivityDefinition: DomainResource {
/// Related artifacts for the asset.
public var relatedArtifact: [RelatedArtifact]?

/// draft | active | retired.
public var status: String?
/// The status of this activity definition. Enables tracking the life-cycle of the content.
public var status: PublicationStatus?

/// When activity is to occur.
public var timingCodeableConcept: CodeableConcept?
Expand Down Expand Up @@ -127,7 +127,7 @@ open class ActivityDefinition: DomainResource {


/** Convenience initializer, taking all required properties as arguments. */
public convenience init(status: String) {
public convenience init(status: PublicationStatus) {
self.init()
self.status = status
}
Expand All @@ -147,7 +147,12 @@ open class ActivityDefinition: DomainResource {
if let exist = json["category"] {
presentKeys.insert("category")
if let val = exist as? String {
self.category = val
if let enumval = ActivityDefinitionCategory(rawValue: val) {
self.category = enumval
}
else {
errors.append(FHIRValidationError(key: "category", problem: "the value “\(val)” is not valid"))
}
}
else {
errors.append(FHIRValidationError(key: "category", wants: String.self, has: type(of: exist)))
Expand Down Expand Up @@ -349,8 +354,12 @@ open class ActivityDefinition: DomainResource {
}
if let exist = json["participantType"] {
presentKeys.insert("participantType")
if let val = exist as? [String] {
self.participantType = val
if let val = exist as? [String] { var i = -1
self.participantType = val.map() { i += 1
if let enumval = PlanActionParticipantType(rawValue: $0) { return enumval }
errors.append(FHIRValidationError(key: "participantType.\(i)", problem: "the value “\(val)” is not valid"))
return nil
}.filter() { nil != $0 }.map() { $0! }
}
else {
errors.append(FHIRValidationError(key: "participantType", wants: Array<String>.self, has: type(of: exist)))
Expand Down Expand Up @@ -433,7 +442,12 @@ open class ActivityDefinition: DomainResource {
if let exist = json["status"] {
presentKeys.insert("status")
if let val = exist as? String {
self.status = val
if let enumval = PublicationStatus(rawValue: val) {
self.status = enumval
}
else {
errors.append(FHIRValidationError(key: "status", problem: "the value “\(val)” is not valid"))
}
}
else {
errors.append(FHIRValidationError(key: "status", wants: String.self, has: type(of: exist)))
Expand Down Expand Up @@ -558,7 +572,7 @@ open class ActivityDefinition: DomainResource {
json["approvalDate"] = approvalDate.asJSON()
}
if let category = self.category {
json["category"] = category.asJSON()
json["category"] = category.rawValue
}
if let code = self.code {
json["code"] = code.asJSON(errors: &errors)
Expand Down Expand Up @@ -609,11 +623,7 @@ open class ActivityDefinition: DomainResource {
json["name"] = name.asJSON()
}
if let participantType = self.participantType {
var arr = [Any]()
for val in participantType {
arr.append(val.asJSON())
}
json["participantType"] = arr
json["participantType"] = participantType.map() { $0.rawValue }
}
if let productCodeableConcept = self.productCodeableConcept {
json["productCodeableConcept"] = productCodeableConcept.asJSON(errors: &errors)
Expand All @@ -634,7 +644,7 @@ open class ActivityDefinition: DomainResource {
json["relatedArtifact"] = relatedArtifact.map() { $0.asJSON(errors: &errors) }
}
if let status = self.status {
json["status"] = status.asJSON()
json["status"] = status.rawValue
}
if let timingCodeableConcept = self.timingCodeableConcept {
json["timingCodeableConcept"] = timingCodeableConcept.asJSON(errors: &errors)
Expand Down Expand Up @@ -670,12 +680,12 @@ open class ActivityDefinition: DomainResource {


/**
* Dynamic aspects of the definition.
*
* Dynamic values that will be evaluated to produce values for elements of the resulting resource. For example, if the
* dosage of a medication must be computed based on the patient's weight, a dynamic value would be used to specify an
* expression that calculated the weight, and the path on the intent resource that would contain the result.
*/
Dynamic aspects of the definition.

Dynamic values that will be evaluated to produce values for elements of the resulting resource. For example, if the
dosage of a medication must be computed based on the patient's weight, a dynamic value would be used to specify an
expression that calculated the weight, and the path on the intent resource that would contain the result.
*/
open class ActivityDefinitionDynamicValue: BackboneElement {
override open class var resourceType: String {
get { return "ActivityDefinitionDynamicValue" }
Expand Down
47 changes: 27 additions & 20 deletions Sources/Models/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// Address.swift
// SwiftFHIR
//
// Generated from FHIR 1.7.0.10104 (http://hl7.org/fhir/StructureDefinition/Address) on 2016-11-03.
// Generated from FHIR 1.7.0.10127 (http://hl7.org/fhir/StructureDefinition/Address) on 2016-11-04.
// 2016, SMART Health IT.
//

import Foundation


/**
* An address expressed using postal conventions (as opposed to GPS or other location definition formats).
*
* An address expressed using postal conventions (as opposed to GPS or other location definition formats). This data
* type may be used to convey addresses for use in delivering mail as well as for visiting locations and which might
* not be valid for mail delivery. There are a variety of postal address formats defined around the world.
*/
An address expressed using postal conventions (as opposed to GPS or other location definition formats).

An address expressed using postal conventions (as opposed to GPS or other location definition formats). This data type
may be used to convey addresses for use in delivering mail as well as for visiting locations and which might not be
valid for mail delivery. There are a variety of postal address formats defined around the world.
*/
open class Address: Element {
override open class var resourceType: String {
get { return "Address" }
Expand Down Expand Up @@ -45,11 +45,12 @@ open class Address: Element {
/// Text representation of the address.
public var text: String?

/// postal | physical | both.
public var type: String?
/// Distinguishes between physical addresses (those you can visit) and mailing addresses (e.g. PO Boxes and care-of
/// addresses). Most addresses are both.
public var type: AddressType?

/// home | work | temp | old - purpose of this address.
public var use: String?
/// The purpose of this address.
public var use: AddressUse?


override open func populate(from json: FHIRJSON, presentKeys: inout Set<String>) throws -> [FHIRValidationError]? {
Expand Down Expand Up @@ -134,7 +135,12 @@ open class Address: Element {
if let exist = json["type"] {
presentKeys.insert("type")
if let val = exist as? String {
self.type = val
if let enumval = AddressType(rawValue: val) {
self.type = enumval
}
else {
errors.append(FHIRValidationError(key: "type", problem: "the value “\(val)” is not valid"))
}
}
else {
errors.append(FHIRValidationError(key: "type", wants: String.self, has: type(of: exist)))
Expand All @@ -143,7 +149,12 @@ open class Address: Element {
if let exist = json["use"] {
presentKeys.insert("use")
if let val = exist as? String {
self.use = val
if let enumval = AddressUse(rawValue: val) {
self.use = enumval
}
else {
errors.append(FHIRValidationError(key: "use", problem: "the value “\(val)” is not valid"))
}
}
else {
errors.append(FHIRValidationError(key: "use", wants: String.self, has: type(of: exist)))
Expand All @@ -165,11 +176,7 @@ open class Address: Element {
json["district"] = district.asJSON()
}
if let line = self.line {
var arr = [Any]()
for val in line {
arr.append(val.asJSON())
}
json["line"] = arr
json["line"] = line.map() { $0.asJSON() }
}
if let period = self.period {
json["period"] = period.asJSON(errors: &errors)
Expand All @@ -184,10 +191,10 @@ open class Address: Element {
json["text"] = text.asJSON()
}
if let type = self.type {
json["type"] = type.asJSON()
json["type"] = type.rawValue
}
if let use = self.use {
json["use"] = use.asJSON()
json["use"] = use.rawValue
}

return json
Expand Down
6 changes: 3 additions & 3 deletions Sources/Models/Age.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// Age.swift
// SwiftFHIR
//
// Generated from FHIR 1.7.0.10104 (http://hl7.org/fhir/StructureDefinition/Age) on 2016-11-03.
// Generated from FHIR 1.7.0.10127 (http://hl7.org/fhir/StructureDefinition/Age) on 2016-11-04.
// 2016, SMART Health IT.
//

import Foundation


/**
* A duration of time during which an organism (or a process) has existed.
*/
A duration of time during which an organism (or a process) has existed.
*/
open class Age: Quantity {
override open class var resourceType: String {
get { return "Age" }
Expand Down
Loading

0 comments on commit d54866a

Please sign in to comment.