【问题标题】:Issues with Epic Bulk Data Request - 401 ErrorEpic 批量数据请求问题 - 401 错误
【发布时间】:2021-12-08 20:07:07
【问题描述】:

我正在 Python 中实现 FHIR 集成,以从 Epic 的沙盒环境中提取数据。我想看看是否有其他人尝试过此操作,或者在执行启动请求时是否遇到过令牌身份验证问题。

关于我的构建/进度的一些值得注意的信息:

  1. 我正在使用https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token 获取令牌

  2. 传回的 JWT 有效且已签名

  3. 根据 Epic 的批量导出规范,我使用 https://apporchard.epic.com/interconnect-aocurprd-oauth/api/FHIR/R4/Group/eIscQb2HmqkT.aPxBKDR1mIj3721CpVk1suC7rlu3yX83/$export 作为端点来请求数据。

  4. 对于上面的 url,在我的 get 请求中,我传递了以下标头:

    '接受':'application/fhir+json',

    'Content-type' : 'application/fhir+json',

    'Prefer':'respond-async',

    “授权”:“持有者”+令牌

  5. 我使用会话来处理请求,并通过覆盖 requests.Session 中的 NoRebuildAuthSession 来保留 Authorization 标头

get 请求的响应返回 401 错误和 www-authenticate 下的以下信息: Bearer error="invalid_token", error_description="提供的访问令牌无效"

任何指导都会有所帮助!我想我可能使用了错误的端点,但我现在完全被难住了。

class NoRebuildAuthSession(Session):
    def rebuild_auth(self, prepared_request, response):
        """
        No code here means requests will always preserve the 
        Authorization
        header when redirected.
        """

session = NoRebuildAuthSession()

logging.basicConfig(level=logging.DEBUG)

instance = jwt.JWT()
message = {
    # Client ID for non-production
    'iss': '<client-id>',
    'sub': '<client-id>',
    'aud': 'https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token',
    'jti': '<string of characters>',
    'iat': get_int_from_datetime(datetime.now(timezone.utc)),
    'exp': get_int_from_datetime(datetime.now(timezone.utc) + timedelta(minutes=1)),
}
# Load a RSA key from a PEM file.
with open('<private-key-path>', 'rb') as fh:
    signing_key = jwt.jwk_from_pem(fh.read())

compact_jws = instance.encode(message, signing_key, alg='RS384')
headers = CaseInsensitiveDict()
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 = session.post('https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token', headers=headers, data=data)

responseDict = json.loads(x.text)
token = x.json()['access_token']
print(responseDict['access_token'])
headers = {
    'Accept':'application/fhir+json',
    'Content-type' : 'application/fhir+json',
    'Prefer':'respond-async',
    'Authorization' : 'Bearer ' + token
    }
session.headers = headers
base = "https://apporchard.epic.com/interconnect-aocurprd-oauth/api/FHIR/R4/Group/eIscQb2HmqkT.aPxBKDR1mIj3721CpVk1suC7rlu3yX83/$export"
y = session.get(base, headers = headers)
print(yaml.dump(y.headers, default_flow_style=False))
print(y.text)

【问题讨论】:

  • 嗨,欢迎来到 SO!我一开始在 HL7 聊天室发现了你的问题。建议您在此处复制/粘贴您的代码。
  • @Cargo23 添加了代码。谢谢!
  • 对于沙盒问题,我们希望人们联系 open@epic.com 寻求故障排除帮助。

标签: hl7-fhir smart-on-fhir


【解决方案1】:

正如 Cooper 所说,您最好的资源是直接联系 Epic 以获取有关其沙盒/API 的故障排除帮助。

也就是说,浏览您的代码,URL 似乎确实是个问题。您似乎在模仿 Epic 中的 Bulk FHIR 教程,该教程在沙盒中可能完全可重现,也可能不完全重现。

在这里,您在 FHIR 端点上调用 Epic 以获取 OAuth 令牌: x = session.post('https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token', headers=headers, data=data)

但是,您随后继续使用 App Orchard 端点进行实际的批量 FHIR 调用: base = "https://apporchard.epic.com/interconnect-aocurprd-oauth/api/FHIR/R4/Group/eIscQb2HmqkT.aPxBKDR1mIj3721CpVk1suC7rlu3yX83/$export"

这是不正确的。假设您尝试在 FHIR 上使用 Epic,则要使用的基本 URL 为 https://fhir.epic.com/interconnect-fhir-oauth,因此该行应为 base = "https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/Group/..." 之类的内容。

【讨论】:

  • 谢谢!我确实意识到这是问题的一部分,并且能够收到令牌接受的响应。我不相信 Epic 通过文档提供的 Group ID 对测试有效,因此如果有人知道沙盒环境中确实存在的 Group ID,将不胜感激。我已经向 Epic 提出了类似的要求。
猜你喜欢
  • 1970-01-01
  • 2014-08-19
  • 1970-01-01
  • 2018-02-05
  • 2018-06-12
  • 1970-01-01
  • 2018-05-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多