Skip to content

Commit

Permalink
[Swift] Conform to Printable. Better renaming of reserved keywords.
Browse files Browse the repository at this point in the history
FHIR datamodel property names that collide with reserved keynames are no longer arbitrarily renamed but receive a "_fhir" suffix. This helps with autocomplete, the developer can start typing the expected FHIR property name and receives an autocomplete suggestion, as expected.
  • Loading branch information
p2 committed Jan 24, 2015
1 parent 12604e1 commit 744d25a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
23 changes: 16 additions & 7 deletions Swift/FHIRElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import Foundation
/**
* Abstract superclass for all FHIR data elements.
*/
public class FHIRElement
public class FHIRElement: Printable
{
/// The name of the resource or element
public class var resourceName: String {
get { return "Element" }
}

/// This should be `extension` but it is a keyword in Swift; renamed to `fhirExtension`.
public var fhirExtension: [Extension]?
/// This should be `extension` but it is a keyword in Swift; renamed to `extension_fhir`.
public var extension_fhir: [Extension]?

/// Optional modifier extensions.
public var modifierExtension: [Extension]?
Expand Down Expand Up @@ -65,7 +65,7 @@ public class FHIRElement
}
}
if countElements(extensions) > 0 {
fhirExtension = extensions
extension_fhir = extensions
}

if let mod = js["modifier"] as? JSONDictionary {
Expand Down Expand Up @@ -99,11 +99,11 @@ public class FHIRElement
}
json["contained"] = dict
}
if let fhirExtension = self.fhirExtension {
json["extension"] = self.dynamicType.asJSONArray(fhirExtension)
if let extension_fhir = self.extension_fhir {
json["extension"] = Extension.asJSONArray(extension_fhir)
}
if let modifierExtension = self.modifierExtension {
json["modifierExtension"] = self.dynamicType.asJSONArray(modifierExtension)
json["modifierExtension"] = Extension.asJSONArray(modifierExtension)
}

return json
Expand Down Expand Up @@ -206,5 +206,14 @@ public class FHIRElement
_resolved = [refid: resolved]
}
}


// MARK: - Printable

public var description: String {
get {
return "<\(self.dynamicType.resourceName)>"
}
}
}

11 changes: 10 additions & 1 deletion Swift/FHIRResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,20 @@ public class FHIRResource: FHIRElement
public class func search(query: AnyObject) -> FHIRSearch {
return FHIRSearch(type: self, query: query)
}


// MARK: - Printable

override public var description: String {
get {
return "<\(self.dynamicType.resourceName)> \(id) on \(_server?.baseURL)"
}
}
}


/**
Holds an element's metadata: http://hl7-fhir.github.io/resource.html#meta
* Holds an element's metadata: http://hl7-fhir.github.io/resource.html#meta
*/
public class FHIRResourceMeta: FHIRElement
{
Expand Down
13 changes: 7 additions & 6 deletions Swift/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@

# Properties that need to be renamed because of language keyword conflicts
reservedmap = {
'class': 'klass',
'import': 'importFrom',
'protocol': 'protokol',
'extension': 'fhirExtension',
'operator': 'operatr',
'modifier': 'mod', # `modifierExtension` is called "modifier" in JSON
'class': 'class_fhir',
'import': 'import_fhir',
'protocol': 'protocol_fhir',
'extension': 'extension_fhir',
'operator': 'operator_fhir',
'modifier': 'modifier_fhir', # `modifierExtension` is called "modifier" in JSON
'description': 'description_fhir', # Reserved for `Printable` classes
}

0 comments on commit 744d25a

Please sign in to comment.