def _make_bundle(self): ''' helper function for creating a bundle as a dictionary ''' bundle = {} entries = [] for resource in self.resources: relative_resource_url = resource.get_url(self.version_specific) resource_url = urljoin(self.api_base, relative_resource_url) resource_content = json.loads(resource.data) resource_type = relative_resource_url.split('/')[0] if self.data_format == 'xml': resource_content = json_to_xml(resource_content) entries.append({ 'fullUrl': resource_url, 'resource': resource_content }) bundle['entry'] = entries links = [{'rel': 'self', 'href': self.request_url}] if self.next_url is not None: links.append({'rel': 'next', 'href': self.next_url}) if self.prev_url is not None: links.append({'rel': 'previous', 'href': self.prev_url}) bundle['link'] = links bundle['total'] = self.resource_count bundle['updated'] = self.update_time bundle['id'] = self.request_url bundle['type'] = 'searchset' bundle['resourceType'] = 'Bundle' return bundle
def new_error(status_code): ''' Create a new OperationOutcome resource from HTTP status_code ''' msg, severity = CODES[status_code] outcome_content = { 'resourceType': 'OperationOutcome', 'issue': { 'severity': severity, 'details': msg } } is_xml = (request.args.get('_format', 'xml') == 'xml') response= (json_response(json.dumps(outcome_content)) if not is_xml else xml_response(json_to_xml(outcome_content))) response.status = status_code return response
def _make_bundle(self): ''' helper function for creating a bundle as a dictionary ''' bundle = {} entries = [] for resource in self.resources: relative_resource_url = resource.get_url(self.version_specific) resource_url = urljoin(self.api_base, relative_resource_url) resource_content = json.loads(resource.data) if self.data_format == 'xml': resource_content = json_to_xml(resource_content) entries.append({ 'content': resource_content, 'created': resource.create_time.isoformat(), 'updated': resource.update_time.isoformat(), 'id': resource_url, 'title': relative_resource_url }) bundle['entry'] = entries links = [{'rel': 'self', 'href': self.request_url}] if self.next_url is not None: links.append({ 'rel': 'next', 'href': self.next_url }) if self.prev_url is not None: links.append({ 'rel': 'previous', 'href': self.prev_url }) bundle['link'] = links bundle['totalResults'] = self.resource_count bundle['updated'] = self.update_time bundle['title'] = BUNDLE_TITLE bundle['id'] = self.request_url bundle['resourceType'] = 'Bundle' return bundle
def as_response(self, request, created=False): ''' return the resource as a HTTP response ''' status = '201' if created else '200' if request.format == 'json': response = json_response(status=status) response.data = self.data else: response = xml_response(status=status) response.data = json_to_xml(json.loads(self.data)) loc_header = 'Location' if created else 'Content-Location' response.headers[loc_header] = urljoin( request.api_base, '%s/%s/_history/%s' % (self.resource_type, self.resource_id, self.version)) return response
def as_response(self, request, created=False): ''' return the resource as a HTTP response ''' status = '201' if created else '200' if request.format == 'json': response = json_response(status=status) response.data = self.data else: response = xml_response(status=status) response.data = json_to_xml(json.loads(self.data)) loc_header = 'Location' if created else 'Content-Location' response.headers[loc_header] = urljoin(request.api_base, '%s/%s/_history/%s' % ( self.resource_type, self.resource_id, self.version)) return response
def _make_bundle(self): ''' helper function for creating a bundle as a dictionary ''' bundle = {} entries = [] for resource in self.resources: relative_resource_url = resource.get_url(self.version_specific) resource_url = urljoin(self.api_base, relative_resource_url) resource_content = json.loads(resource.data) resource_type = relative_resource_url.split('/')[0] if self.data_format == 'xml': resource_content = json_to_xml(resource_content) entries.append({ 'fullUrl': resource_url, 'resource': resource_content }) bundle['entry'] = entries links = [{'relation': 'self', 'url': self.request_url}] if self.next_url is not None: links.append({ 'rel': 'next', 'href': self.next_url }) if self.prev_url is not None: links.append({ 'rel': 'previous', 'href': self.prev_url }) bundle['link'] = links bundle['total'] = self.resource_count bundle['updated'] = self.update_time bundle['id'] = self.request_url bundle['type'] = 'searchset' bundle['resourceType'] = 'Bundle' return bundle