예제 #1
0
 def as_properties(self):
     """ If the element describes a *class property*, returns a list of
     FHIRClassProperty instances, None otherwise.
     """
     assert self._did_resolve_dependencies
     if self.is_main_profile_element or self.definition is None:
         return None
     
     # TODO: handle slicing information (not sure why these properties were
     # omitted previously)
     #if self.definition.slicing:
     #    logger.debug('Omitting property "{}" for slicing'.format(self.definition.prop_name))
     #    return None
     
     # this must be a property
     if self.parent is None:
         raise Exception('Element reports as property but has no parent: "{}"'
             .format(self.path))
     
     # create a list of FHIRClassProperty instances (usually with only 1 item)
     if len(self.definition.types) > 0:
         props = []
         for type_obj in self.definition.types:
             
             # an inline class
             if 'BackboneElement' == type_obj.code or 'Element' == type_obj.code:        # data types don't use "BackboneElement"
                 props.append(fhirclass.FHIRClassProperty(self, type_obj, self.name_if_class))
                 # TODO: look at http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name ?
             else:
                 props.append(fhirclass.FHIRClassProperty(self, type_obj))
         return props
     
     # no `type` definition in the element: it's a property with an inline class definition
     type_obj = FHIRElementType()
     return [fhirclass.FHIRClassProperty(self, type_obj, self.name_if_class)]
예제 #2
0
    def as_properties(self):
        """ If the element describes a *class property*, returns a list of
        FHIRClassProperty instances, None otherwise.
        """
        assert self._did_resolve_dependencies
        if self.is_main_profile_element or self.definition is None:
            return None

        if self.definition.slicing:
            logger.debug('Omitting property "{}" for slicing'.format(
                self.definition.prop_name))
            return None

        # this must be a property
        if self.parent is None:
            raise Exception(
                'Element reports as property but has no parent: "{}"'.format(
                    self.path))

        # create a list of FHIRClassProperty instances (usually with only 1 item)
        if len(self.definition.types) > 0:
            props = []
            for type_obj in self.definition.types:

                # an inline class
                if 'BackboneElement' == type_obj.code or 'Element' == type_obj.code:  # data types don't use "BackboneElement"
                    props.append(
                        fhirclass.FHIRClassProperty(self, type_obj,
                                                    self.name_if_class()))
                    # TODO: look at http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name ?

                # the wildcard type: expand to all possible types, as defined in our mapping
                elif '*' == type_obj.code:
                    for exp_type in self.profile.spec.star_expand_types:
                        props.append(
                            fhirclass.FHIRClassProperty(
                                self, type_obj, exp_type))
                else:
                    props.append(fhirclass.FHIRClassProperty(self, type_obj))
            return props

        # no `type` definition in the element: it's a property with an inline class definition
        type_obj = FHIRElementType()
        return [
            fhirclass.FHIRClassProperty(self, type_obj, self.name_if_class())
        ]