示例#1
0
文件: lib.py 项目: ufocoder/fhir-py
    async def __aiter__(self):
        next_link = None
        while True:
            if next_link:
                bundle_data = await self.client._fetch_resource(
                    *parse_pagination_url(next_link))
            else:
                bundle_data = await self.client._fetch_resource(
                    self.resource_type, self.params)
            new_resources = self._get_bundle_resources(bundle_data)
            next_link = get_by_path(bundle_data,
                                    ['link', {
                                        'relation': 'next'
                                    }, 'url'])

            for item in new_resources:
                yield item

            if not next_link:
                break
示例#2
0
    def __iter__(self):
        next_link = None
        while True:
            if next_link:
                bundle_data = self.client._fetch_resource(
                    *parse_pagination_url(next_link))
            else:
                bundle_data = self.client._fetch_resource(
                    self.resource_type, self.params)
            new_resources = self._get_bundle_resources(bundle_data)
            next_link = get_by_path(bundle_data,
                                    ["link", {
                                        "relation": "next"
                                    }, "url"])

            for item in new_resources:
                yield item

            if not next_link:
                break
示例#3
0
    async def test_fetch_all(self):
        patients_count = 18
        name = 'Jack Johnson J'
        patient_ids = await self.create_test_patients(patients_count, name)
        patient_set = self.client.resources('Patient') \
            .search(name=name) \
            .limit(5)

        mocked_request = Mock(wraps=request)
        with patch('aiohttp.request', mocked_request):
            patients = await patient_set.fetch_all()

        received_ids = set(p.id for p in patients)

        assert len(received_ids) == patients_count
        assert patient_ids == received_ids

        assert mocked_request.call_count == ceil(patients_count / 5)

        first_call_args = mocked_request.call_args_list[0][0]
        first_call_url = list(first_call_args)[1]
        path, params = parse_pagination_url(first_call_url)
        assert '/Patient' in path
        assert params == {'name': [name], '_format': ['json'], '_count': ['5']}
 def test_parse_pagination_url_relative(self, client):
     url = "/Patient?_count=100&name=ivan&name=petrov"
     path, params = parse_pagination_url(url)
     assert path == "/Patient"
     assert params == {"_count": ["100"], "name": ["ivan", "petrov"]}
 def test_parse_pagination_url_absolute(self, client):
     url = "https://github.com/beda-software/fhir-py/search?q=fhir-py&unscoped_q=fhir-py"
     path, params = parse_pagination_url(url)
     assert path == url
     assert params is None
示例#6
0
 def test_parse_pagination_url_relative(self, client):
     url = '/Patient?_count=100&name=ivan&name=petrov'
     path, params = parse_pagination_url(url)
     assert path == '/Patient'
     assert params == {'_count': ['100'], 'name': ['ivan', 'petrov']}