Skip to content

Commit

Permalink
Move extensions back to the base element
Browse files Browse the repository at this point in the history
  • Loading branch information
p2 committed Mar 11, 2015
1 parent e5ee6cf commit 43e1583
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Python/fhirelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def __init__(self, jsondict=None):
self._owner = None
""" Points to the parent resource, if there is one. """

self.extension = None
self.modifierExtension = None

if jsondict is not None:
self.update_with_json(jsondict)

Expand All @@ -44,6 +47,28 @@ def update_with_json(self, jsondict):
self.contained[res.id] = res
else:
logging.warning("Contained resource {} does not have an id, ignoring".format(res))

# extract extensions
if "extension" in jsondict and isinstance(jsondict["extension"], list):
extensions = []
for ext_dict in jsondict["extension"]:
if isinstance(ext_dict, dict):
for ext in extension.Extension.with_json(ext_dict):
ext.url = key
extensions.append(ext)
if len(extensions) > 0:
self.extension = extensions

if "modifierExtension" in jsondict and isinstance(jsondict["modifierExtension"], list):
extensions = []
for ext_dict in jsondict["modifierExtension"]:
if isinstance(ext_dict, dict):
for ext in extension.Extension.with_json(ext_dict):
ext.url = key
extensions.append(ext)
if len(extensions) > 0:
self.modifierExtension = extensions


@classmethod
def with_json(cls, jsonobj):
Expand Down Expand Up @@ -111,4 +136,5 @@ def didResolveReference(self, refid, resolved):


# these are subclasses of FHIRElement, import last
import extension
import fhircontainedresource
18 changes: 18 additions & 0 deletions Swift/FHIRElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class FHIRElement: Printable
/// Resolved references.
var _resolved: [String: FHIRElement]?

/// Additional Content defined by implementations
public var extension_fhir: [Extension]?

/// Extensions that cannot be ignored
public var modifierExtension: [Extension]?


// MARK: - JSON Capabilities

Expand All @@ -52,6 +58,12 @@ public class FHIRElement: Printable
}
contained = cont
}
if let val = js["extension"] as? [JSONDictionary] {
self.extension_fhir = Extension.from(val, owner: self) as? [Extension]
}
if let val = js["modifierExtension"] as? [JSONDictionary] {
self.modifierExtension = Extension.from(val, owner: self) as? [Extension]
}
}
}

Expand All @@ -72,6 +84,12 @@ public class FHIRElement: Printable
}
json["contained"] = arr
}
if let extension_fhir = self.extension_fhir {
json["extension"] = Extension.asJSONArray(extension_fhir)
}
if let modifierExtension = self.modifierExtension {
json["modifierExtension"] = Extension.asJSONArray(modifierExtension)
}

return json
}
Expand Down
3 changes: 2 additions & 1 deletion fhirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ class FHIRProfileElement(object):

# properties with these names will be skipped as we implement them in our base classes
skip_properties = [
'id', # implemented in FHIRResource to support URL creation
'id',
'contained',
'extension', 'modifierExtension',
]

def __init__(self, profile, element_dict, is_main_profile_element=False):
Expand Down

0 comments on commit 43e1583

Please sign in to comment.