首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决向Epic Fhir Sandbox发送请求时的ID错误

问如何解决向Epic Fhir Sandbox发送请求时的ID错误
EN

Stack Overflow用户
提问于 2022-06-27 21:08:03
回答 1查看 199关注 0票数 0

我正在尝试将来自https://fhir.epic.com/的沙箱用于后端服务。

我正在学习本教程:ion=BackendOAuth2Guide:

我已经注册了一个新的应用程序,创建了一个在https://jwt.io/上测试JWT的JWT (使用SSL密钥):工作得很好!当我将JWT发布到端点(https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token)时,我会得到一个访问令牌。

使用此访问令牌,我可以访问单个病人预约重新来源,但仅此而已。我不明白如何访问其他资源,如DiagnosticReport、观察等等。当然,我将它们添加到应用程序的范围中,但似乎仍然不起作用。

我在这里错过了什么?

这是我可以访问约会资源的代码:

代码语言:javascript
复制
import json
from datetime import datetime, timedelta, timezone
import requests
from requests.structures import CaseInsensitiveDict
from jwt import (
    JWT,
    jwk_from_dict,
    jwk_from_pem,
)
from jwt.utils import get_int_from_datetime
import random
import xmltodict


def main():
    instance = JWT()

    message = {
        # Client ID for non-production
        'iss': 'my_iss_here',
        'sub': 'my_sub_here',
        'aud': 'https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token',
        'jti': f'7777-7777-7777-7777-7777{random.randint(100,1000)}',
        'iat': get_int_from_datetime(datetime.now(timezone.utc)),
        'exp': get_int_from_datetime(datetime.now(timezone.utc) + timedelta(minutes=2)),
    }


    # Load a RSA key from a PEM file.
    with open('./privatekey.pem', 'rb') as fh:
        signing_key = jwk_from_pem(fh.read())

    compact_jws = instance.encode(message, signing_key, alg='RS384')

    headers = {}
    headers['Content-Type'] = 'application/x-www-form-urlencoded'

    data = {
      'grant_type': 'client_credentials',
      'client_assertion_type': 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
      'client_assertion': compact_jws
    }
    
    x = requests.post('https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token', headers=headers, data=data)

    access_token = x.json()['access_token']

    headers = {}
    headers['Authorization'] = f'Bearer {access_token}'
    x = requests.get('https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/STU3/Appointment/eWLhfjXHp4RUczv2om.1Ii2uiHcDc6rMEjO0xHBA3', headers=headers)

    print(x.content)

当我更改这两个(在线教程)之一的请求时,它不起作用:

代码语言:javascript
复制
x = requests.get('https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/Observation/erXuFYUfucBZaryVksYEcMg3', headers=headers)

我用的是Camilia Lopez的FHIR ID (测试病人)。她应该有一个观察源,但我发现了一个错误:

代码语言:javascript
复制
<OperationOutcome xmlns="http://hl7.org/fhir"><issue><severity value="fatal" /><code value="not-found" /><details><coding><system value="urn:oid:1.2.840.114350.1.13.0.1.7.2.657369" /><code value="59008" /><display value="The FHIR ID provided was not found." /></coding><text value="The FHIR ID provided was not found." /></details><diagnostics value="Invalid FHIR ID provided" /><location value="/f:id" /><expression value="id" /></issue></OperationOutcome>
EN

回答 1

Stack Overflow用户

发布于 2022-06-28 00:13:43

这两种证件似乎都不是“关于FHIR沙箱的史诗”中所要求的资源的有效FHIR in。本教程中的ID只是示例。您应该使用测试数据引用这里来识别可用于测试的病人和其他资源。您还应该确保在您的调用中包括所有必要的标头。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72778319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档