0

我正在尝试调用从 Cerner EHR 提供患者详细信息的 get API。我正在使用基于系统的 SMART 应用程序。但是当我试图调用它时,我得到一个错误

无效范围。
'范围':'system/Observation.write system/Patient.read system/Patient.write system/Observation.read'

我在邮递员中试过这个,CURL 都很好用。

但是,当我将范围指定为 -'scope':'system/Patient.write system/Patient.read system/Observation.write system/Observation.read'即将 system/Patient.write 或任何其他范围作为第一个范围时,我无法获取患者的详细信息,我必须将 system/Patient.read 作为第一个范围本身我可以阅读患者的详细信息。我不明白为什么范围的顺序在这里很重要。

获取访问令牌的代码如下:

const getAuth = async () => {
 try{
    const token_url = 'token-url endpoint';
    const data = qs.stringify({'grant_type':'client_credentials','scope':'system/Patient.write system/Patient.read system/Observation.write  system/Observation.read '});
    console.log(data)
    const opts = {
    headers: { 
      'Authorization': `Basic ${auth_token}`,
      'Content-Type': 'application/x-www-form-urlencoded',
      'Accept': 'application/json',
      'Content-Length': '61',
      'Connection':'close',
      'cache-control': 'no-cache'  
     }
    };

    const response = await axios.post(token_url, data, opts);
  
    return response.data.access_token;

  }catch(error){
    console.log( error);
  }
}

在此之后,我正在调用一个函数来获取患者详细信息,函数代码如下:

async function getFunction(){
    const bearer_token=await getAuth();
  
  const get_url = 'get endpoint';
  const get_header = {
    headers: {
      'Authorization': `Bearer ${bearer_token}`,
      'Accept': 'application/json+fhir'
   }
  }
    console.log(bearer_token);
     
      const get_respone = await axios.get(get_url, get_header);
      let data = get_respone.data;
      console.log(data);
      return data;
    
    }

但显示错误为:

数据:{resourceType:'OperationOutcome',问题:[{严重性:'错误',代码:'禁止',诊断:'Bearer realm="fhir-ehr-code.cerner.com",错误="insufficient_scope"',表达式:['http.Authorization'] } ] }

但是,如果我通过将范围更改为来获取访问令牌:

'scope':'system/Patient.read system/Patient.write system/Observation.write  system/Observation.read'

然后我会得到病人的详细信息,因为我在system/Patient.read范围的开头添加了范围。

我使用 Node.js 作为这个 SMART 应用程序的后端,而且我是 Node.js 的初学者,所以我不明白为什么范围的顺序在调用 API 时很重要。有人知道吗?

4

0 回答 0