如果不是一開始就是以FHIR為標準設計的服務(FHIR-based),在對接FHIR時就需要將資料轉為fhir-json格式,因此今天會介紹將數據轉成fhir-json格式回傳的方法,範例會以SpringBoot框架進行開發。
版本 | 備註 | |
---|---|---|
FHIR版本 | R4 | 目前最常用的版本,衛福部IG使用 |
HAPI FHIR Server版本 | 7.2.1 | |
JAVA | 11 | |
PostgreSQL | 15.1 |
以下是POM檔內需要import的dependency。
<!-- FHIR版本為R4-->
<!-- https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-structures-r4 -->
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r4</artifactId>
<version>7.2.1</version>
</dependency>
<!-- FHIR Base-->
<!-- https://mvnrepository.com/artifact/ca.uhn.hapi.fhir/hapi-fhir-base -->
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>7.2.1</version>
</dependency>
引入dependency後就能進行開發啦!接下來以血糖量測數值(Observation Resource)舉例
public String fhirObservationBloodGlucose(String patientID,String bloodGlucose){
// 新增一個 Observation 物件,並將資料置入其中
Observation bloodGlucoseObservation = new Observation();
// bloodGlucoseObservation.addCategory().addCoding().setDisplay("Vital Signs").setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("vital-signs");
// bloodGlucoseObservation.addCategory().setText("Vital Signs");
CodeableConcept bloodGlucoseCode = new CodeableConcept();
// 填入血糖基本資料
bloodGlucoseCode.addCoding().setSystem("http://loinc.org").setCode("15074-8").setDisplay("Glucose [Moles/volume] in Blood");
bloodGlucoseCode.setText("Glucose [Moles/volume] in Blood");
bloodGlucoseObservation.setCode(bloodGlucoseCode);
Quantity bloodGlucoseQty = new Quantity();
bloodGlucoseQty.setValue(Double.parseDouble(bloodGlucose)).setSystem("http://unitsofmeasure.org").setCode("mmol/L").setUnit("mmol/l");
bloodGlucoseObservation.setValue(bloodGlucoseQty);
// 如果要紀錄此量測數據是屬於哪個Patient,可以新增以下Reference
// Reference ref = new Reference();
// ref.setReference("Patient/"+patientID);
// observation.setSubject(ref);
// 將Observation 物件轉成String
String bloodGlucoseObservationstr = FhirContext.forR4().newJsonParser().encodeResourceToString(bloodGlucoseObservation);
// 回傳fhir+JSON格式資料
return bloodGlucoseObservationstr;
}
如果是像血壓這種會一次產生兩種測量數值的Observation Resource,則需要新增兩個Quantity
public String fhirObservationBloodPressure(String patientID,String bp_dp,String bp_sp) {
// 新增一個 Observation 物件,並將資料置入其中
Observation bloodPressureObservation = new Observation();
bloodPressureObservation.addCategory().addCoding().setDisplay("Vital Signs").setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("vital-signs");
bloodPressureObservation.addCategory().setText("Vital Signs");
CodeableConcept bloodPressureCode = new CodeableConcept();
bloodPressureCode.addCoding().setSystem("http://loinc.org").setCode("85354-9").setDisplay("Blood pressure panel with all children optional");
bloodPressureCode.setText("Blood pressure systolic & diastolic");
bloodPressureObservation.setCode(bloodPressureCode);
CodeableConcept bloodPressureSysCode = new CodeableConcept();
bloodPressureSysCode.addCoding().setSystem("http://loinc.org").setCode("8480-6").setDisplay("Systolic blood pressure");
Quantity bloodPressureSysQty = new Quantity();
bloodPressureSysQty.setValue(Integer.parseInt(bp_sp)).setSystem("http://unitsofmeasure.org").setCode("mm[Hg]").setUnit("mmHg");
bloodPressureObservation.addComponent().setCode(bloodPressureSysCode).setValue(bloodPressureSysQty);
CodeableConcept bloodPressureDiasCode = new CodeableConcept();
bloodPressureDiasCode.addCoding().setSystem("http://loinc.org").setCode("8462-4").setDisplay("Diastolic blood pressure");
Quantity bloodPressureDiasQty = new Quantity();
bloodPressureDiasQty.setValue(Integer.parseInt(bp_dp)).setSystem("http://unitsofmeasure.org").setCode("mm[Hg]").setUnit("mmHg");
bloodPressureObservation.addComponent().setCode(bloodPressureDiasCode).setValue(bloodPressureDiasQty);
// 跟上面範例一樣,如果要標記這個Observation Resource的Reference,需要將Reference加入Observation 物件裡
// Reference ref = new Reference();
// ref.setReference("Patient/"+patientID);
// observation.setSubject(ref);
// 將Observation 物件轉成String
String bloodPressureObservationstr = FhirContext.forR4().newJsonParser().encodeResourceToString(bloodPressureObservation);
// 回傳fhir+JSON格式資料
return bloodPressureObservationstr;
}
後續只需要在Controller部分限定回傳的是JSON格式,就可以回傳fhir+JSON格式資料啦!
接下來會介紹關於醫療影像儲存及檔案的內容,敬請期待!