fhirpack.extraction.sample — fhirpack 0.0.2b0 documentation

# Source code for fhirpack.extraction.sample

    import json
    from typing import Union

    from fhirpy.lib import SyncFHIRResource
    from fhirpy.lib import SyncFHIRReference

    class BaseExtractorMixin:
        def getSampleExtractionMethod(
            self,
            input: Union[
                list[str],
                list[SyncFHIRReference],
                list[SyncFHIRResource],
            ] = None,
            params: dict = None,
            ignoreFrame: bool = False,
        ):

            searchActive = False if searchParams is None else True
            searchParams = {} if searchParams is None else searchParams
            params = {} if params is None else params
            input = [] if input is None else input
            result = []

            # TODO prepare your context here

            if len(input):
                # TODO your code for data coming in as arguments
                input = self.castOperand(input, SyncFHIRReference, "replace")
                result = self.getResources(input, resourceType="replace", raw=True)

            elif self.isFrame and not ignoreFrame:

                # TODO your code for data coming in as a frame
                if self.resourceTypeIs("Patient"):
                    input = self.data

                    result = input.apply(
                        lambda x: self.searchResources(
                            searchParams=dict(searchParams, **{"replace": x.id}),
                            resourceType="replace",
                            raw=True,
                        )
                    )
                    result = result.values

                elif self.resourceTypeIs("replace"):
                    input = self.data.values
                    result = self.getResources(input, resourceType="replace", raw=True)

                else:
                    raise NotImplementedError

            elif searchActive:
                # TODO your code for searches
                result = self.searchResources(
                    searchParams=searchParams, resourceType="replace", raw=True
                )

            else:
                raise NotImplementedError

            result = self.prepareOutput(input)
            return result