2017-05-25 57 views
0

我目前對DSTU2使用hapi-fhir 2.3。如果我使用hapi-fhir client api創建了一個RiskAssessment對象。我如何將它轉換爲標準的fhir json格式?hapi-fhir將fhir對象轉換爲json字符串

如果使用toSting()方法,會產生以下結果:

{ 
"mySubject" : -{ 
"myReference" : -{ 
"myHaveComponentParts" : false, 
"myUnqualifiedId" : 005543907A, 
"myCoercedValue" : 005543907A, 
"myStringValue" : 005543907A 
} 
}, 
"myDate" : -{ 
"myFractionalSeconds" : 575, 
"myPrecision" : SECOND, 
"myTimeZone" : -{ 
"rawOffset" : 28800000, 
"rawOffsetDiff" : 0, 
"checksum" : -305565502, 
"dstSavings" : 0, 
"transitions" : -[ 
-9048018124800000, 
-8918966038528000, 
-3823593062399950, 
-3781140480000000, 
-3722379263999950, 
-3651969024000000, 
2111569920000050, 
2158623129600000, 
2232955699200050, 
2287440691200000, 
2361773260800050, 
2416258252800000, 
2493068083200050, 
2547553075200000, 
2621885644800050, 
2676370636800000, 
2750703206400050, 
2805188198400000, 
8660385792000000 
], 
"offsets" : -[ 
28800000, 
29143000, 
32400000, 
3600000 
], 
"willGMTOffsetChange" : false, 
"ID" : Asia/Shanghai 
}, 
"myTimeZoneZulu" : false, 
"myCoercedValue" : May 25, 2017 9:46:01 AM, 
"myStringValue" : 2017-05-25T09:46:01+08:00 
}, 
"myMethod" : -{ 
"myText" : -{ 
"myCoercedValue" : My risk score engine., 
"myStringValue" : My risk score engine. 
} 
}, 
"myPrediction" : -[ 
-{ 
"myOutcome" : -{ 
"myText" : -{ 
"myCoercedValue" : Remission, 
"myStringValue" : Remission 
} 
}, 
"myRelativeRisk" : -{ 
"myCoercedValue" : 0.6949999928474426, 
"myStringValue" : 0.6949999928474426 
} 
} 
] 
} 

我所預期的是一樣的東西

{ 
    "resourceType": "RiskAssessment", 
    "id": "prognosis", 
    "text": { 
    "status": "additional", 
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n  <p>Moderate risk of permanent weakness of the left arm, but otherwise no permanent disability</p>\n </div>" 
    }, 
    "status": "final", 
    "occurrenceDateTime": "2010-11-22", 
    "condition": { 
    "reference": "Condition/stroke", 
    "display": "Ischemic Stroke" 
    }, 
    "prediction": [ 
    { 
     "outcome": { 
     "coding": [ 
      { 
      "system": "http://snomed.info/sct", 
      "code": "249943000:363698007=72098002,260868000=6934004" 
      } 
     ], 
     "text": "permanent weakness of the left arm" 
     }, 
     "qualitativeRisk": { 
     "coding": [ 
      { 
      "system": "http://hl7.org/fhir/risk-probability", 
      "code": "moderate", 
      "display": "moderate likelihood" 
      } 
     ] 
     } 
    } 
    ] 
} 

回答

0
String riskAssessmentJson = FhirContext.forDstu2().newJsonParser().encodeResourceToString(resource); 
0

着眼於文檔HAPI-FHIR節「編碼資源來一個字符串「。 但是你真的需要JSON表示嗎? HAPI客戶端在發送給服務器之前自動將對象(資源)解析爲JSON,而在服務器端,它們又是對象。