Ejemplo n.º 1
0
class AttributeWithCallables:
    _model = SN(name="my_name")

    def get_name(self):
        return self._model.name

    def set_name(self, value):
        self._model.name = value

    name = Attribute(get_name, set_name)
Ejemplo n.º 2
0
class AttributeWithPropertyGetterAndSetter:
    class Model:
        _name = "my_name"

        def set_name(self, value):
            self._name = value

        name = property(lambda self: self._name, set_name)

    _model = Model()
    name = Attribute("name", "name")
Ejemplo n.º 3
0
    def __get__(self, instance, owner):
        models = import_models()
        classes = [getattr(models, cls_name) for cls_name in self.possible_types]
        pk = Attribute(self.pk_getter).__get__(instance, None)
        resource = None
        for cls in classes:
            if resource is None:
                try:
                    resource = cls._get_item_from_pk(pk)
                    cls_name = cls.__name__
                except:
                    pass
        if resource is None:
            return None

        if (
            self.name in instance._model._contained_names
        ):  # The resource should be contained
            # Get the item
            as_fhir = resource.to_fhir()

            instance._model._refcount += 1

            as_fhir.id = f"ref{instance._model._refcount}"
            instance._model._contained_items.append(as_fhir)

            # Build the reference dict
            reference = {"reference": f"#ref{instance._model._refcount}"}

            # Add a display if possible
            if hasattr(resource, "_as_display"):
                reference["display"] = resource._as_display

            return reference

        else:  # The resource is not contained, generate a url

            # Build the reference dict
            reference = {
                "reference": f"{cls_name}/{pk}",
                "identifier": {"system": f"{cls_name}", "value": str(pk)},
            }

            if self.force_display:  # Do a query to fetch the display
                # TODO: can we check if it supprts `_as_display` before querying?
                if hasattr(resource, "_as_display"):
                    reference["display"] = resource._as_display

            return reference
Ejemplo n.º 4
0
    class FhirMap:
        def search_name(cls, field_name, value, sql_query, query):
            return sql_query

        name = Attribute(searcher=search_name, search_regex=r"(name|NAME)")
Ejemplo n.º 5
0
class AttributeWithConstSetter:
    _model = SN(_name=12)
    name = Attribute('_name', ('_name', const("the_name")))
Ejemplo n.º 6
0
class AttributeWithConst:
    _model = None
    name = Attribute(const("the_name"))
Ejemplo n.º 7
0
class AttributeWithTransformerSetter:
    _model = SN(name="my_name")
    name = Attribute("name", ("name", lambda curr, new: new.upper()))
Ejemplo n.º 8
0
class AttributeWithTransformerGetter:
    _model = SN(name="my_name")
    name = Attribute(("name", lambda x: x.upper()))
Ejemplo n.º 9
0
class AttributeWithPropertyGetter:
    class Model:
        name = property(lambda self: "my_name")

    _model = Model()
    name = Attribute("name")
Ejemplo n.º 10
0
 class FhirMap:
     name = Attribute("_name")
Ejemplo n.º 11
0
 class FhirMap:
     name = Attribute("_name", "_name")
     active = Attribute("_active", "_active")
Ejemplo n.º 12
0
class AttributeWithStringGetterAndSetter:
    _model = SN(name="my_name")
    name = Attribute("name", "name")
Ejemplo n.º 13
0
 class FhirMap:
     active = Attribute(const(True))
     name = Attribute("_name", "_name")
     age = Attribute("_age", "_age")