Skip to content

Commit

Permalink
Cleanup the confusion about snapshot/differential
Browse files Browse the repository at this point in the history
  • Loading branch information
p2 committed Dec 18, 2014
1 parent b31e273 commit fcbb818
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 108 deletions.
26 changes: 21 additions & 5 deletions fhirclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ class FHIRClass(object):
""" An element/resource that should become its own class.
"""

known = {}

@classmethod
def for_element(cls, element):
assert element.represents_class

if element.path in cls.known:
return cls.known[element.path]

klass = cls(element)
cls.known[element.path] = klass
return klass

@classmethod
def with_name(cls, class_name):
for path, klass in cls.known.items():
if klass.name == class_name:
return klass
return None

def __init__(self, element):
assert element is not None # and must be instance of FHIRElement
self.path = element.path
Expand Down Expand Up @@ -70,11 +90,7 @@ def __init__(self, type_name, type_obj):
self.path = elem.path
name = elem.prop_name
if '[x]' in name:
# < v0.3: "MedicationPrescription.reason[x]" can be a
# "ResourceReference" but apparently should be called
# "reasonResource", NOT "reasonResourceReference".
kl = 'Resource' if 'ResourceReference' == type_name else type_name # < v0.3
name = name.replace('[x]', '{}{}'.format(kl[:1].upper(), kl[1:]))
name = name.replace('[x]', '{}{}'.format(type_name[:1].upper(), type_name[1:]))

self.orig_name = name
self.name = spec.safe_property_name(name)
Expand Down
3 changes: 2 additions & 1 deletion fhirrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def render(self):
for pname, profile in self.spec.profiles.items():
classes = sorted(profile.writable_classes(), key=lambda x: x.name)
if 0 == len(classes):
logging.info('Profile "{}" returns zero writable classes, skipping'.format(profile.filename))
if profile.filename is not None: # manual profiles have no filename and usually write no classes
logging.info('Profile "{}" returns zero writable classes, skipping'.format(profile.filename))
continue

imports = profile.needed_external_classes()
Expand Down
Loading

0 comments on commit fcbb818

Please sign in to comment.