iT邦幫忙

0

想把資料丟到FHIR上,格式問題請教

post資料至國際FHIR ''Patient''上
http://hapi.fhir.org/resource?serverId=home_r4&pretty=true&resource=Patient

小弟有嘗試照著格式撰寫出現錯誤訊息
程式錄:

def postFHIR11(): #post data to FHIR server RFID
    postdata02 = {
  "resourceType": "Bundle",
  "id": "4ba17d68-022c-478f-ad5a-1fb6b866dda8",
  "meta": {
    "lastUpdated": "2020-08-10T13:55:05.322+00:00"
  },
  "type": "searchset",
  "total": 0,
  "link": [
      {
    "relation": "self",
    "url": "http://hapi.fhir.org/baseR4/Patient"
       }
    ]
}  
    r = requests.post(url = 'http://hapi.fhir.org/baseR4/Patient', data = json.dumps(postdata02))
    print(r.text)
    response = json.loads(r.text)
    print('狀態碼,r.status_code)    

錯誤訊息
{
"resourceType": "OperationOutcome",
"text": {
"status": "generated",
"div": "<div xmlns="http://www.w3.org/1999/xhtml\">Operation Outcome<table border="0"><td style="font-weight: bold;">ERROR[]No Content-Type header was provided in the request. This is required for "CREATE" operation\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t"
},
"issue": [ {
"severity": "error",
"code": "processing",
"diagnostics": "No Content-Type header was provided in the request. This is required for "CREATE" operation"
} ]
}
狀態 400
請問是什麼原因造成的

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2020-08-10 22:50:21
最佳解答

錯誤訊息是說No Content-Type header was provided in the request
那就在 header 裡提供 Content-Type 參數

r = requests.post(url = 'http://hapi.fhir.org/baseR4/Patient', data = json.dumps(postdata02))

改成

headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url = 'http://hapi.fhir.org/baseR4/Patient', data = json.dumps(postdata02), headers=headers)

試試看

看更多先前的回應...收起先前的回應...

謝謝前輩經驗點數+1

結果如何?有解決嗎?

https://ithelp.ithome.com.tw/upload/images/20200810/201265771ZcW0yCTg0.png

可以順利上傳 但有一個小問題 我嘗試添加參數

def postFHIR11(): #post data to FHIR server RFID
    postdata02 = {
  "resourceType": "Patient",
  "id": "4ba17d68-022c-478f-ad5a-1fb6b866dda8",
  "meta": {
    "lastUpdated": "2020-08-10T13:55:05.322+00:00"
  },
  "metas": {
    "text": 'aaa'

"metas": {
"text": 'aaa'
是我要隨便添加的文字
再上傳一次的話
一樣如上圖沒有添加文字

目的 我想要把程式中的變數帶進去一起上傳

這就得讀 FHIR Patient 的規格了
你慢慢自己研究囉...

非常感謝您

我要發表回答

立即登入回答