如何在 FHIR API 中更新 Patient?
How to update Patient in FHIR API?
我有 JSON 患者的数据,我尝试用新数据更新它。
当我尝试更新此 Patient 时,条目将重复并且不会像这样更新:
{
"telecom": [
{
"system": "phone",
"value": "2222215",
"use": "home"
},
{
"system": "phone",
"value": "2222215",
"use": "home"
}
],
"gender": "male",
"birthDate": "2020-12-24",
"address": [
{
"use": "home",
"line": [
"28MCT"
],
"city": "Hưng Yên",
"district": "Huyện Kim Động",
"state": "Thị Trấn Lương Bằng",
"country": "VNM"
},
{
"use": "home",
"city": "Hưng Yên",
"district": "Huyện Kim Động",
"state": "Thị Trấn Lương Bằng",
"country": "VNM"
}
]}
具体更新方式是什么?这是我的代码:
private static void UpdatePatient(string patientId)
{
var client = new FhirClient("http://hapi.fhir.org/baseR4");
Patient pat = client.Read<Patient>("Patient/1723313");
pat.Address.Add(new Address(){
Line = new string[1] {"28 MCT"},
District = "Bến Cát",
State = "An Thới",
City = "Bình Dương",
Country = "VNM"
});
client.Update<Patient>(pat);
}
感谢您的帮助。
电信和地址字段是列表。因此,如果您有现有数据并执行 pat.Address.Add,它会向现有列表添加一个新项目 - 保留现有地址。在将更新的数据发送到服务器之前,您实际上必须先更新 Telecom/Address 字段。
例如 - 在 client.Read 和 client.Update 之间,使用 System.Linq:
var a = x.Address.First(ca => ca.Use == Address.AddressUse.Home);
a.Line = new string[] { "28 MCT" };
我有 JSON 患者的数据,我尝试用新数据更新它。 当我尝试更新此 Patient 时,条目将重复并且不会像这样更新:
{
"telecom": [
{
"system": "phone",
"value": "2222215",
"use": "home"
},
{
"system": "phone",
"value": "2222215",
"use": "home"
}
],
"gender": "male",
"birthDate": "2020-12-24",
"address": [
{
"use": "home",
"line": [
"28MCT"
],
"city": "Hưng Yên",
"district": "Huyện Kim Động",
"state": "Thị Trấn Lương Bằng",
"country": "VNM"
},
{
"use": "home",
"city": "Hưng Yên",
"district": "Huyện Kim Động",
"state": "Thị Trấn Lương Bằng",
"country": "VNM"
}
]}
具体更新方式是什么?这是我的代码:
private static void UpdatePatient(string patientId)
{
var client = new FhirClient("http://hapi.fhir.org/baseR4");
Patient pat = client.Read<Patient>("Patient/1723313");
pat.Address.Add(new Address(){
Line = new string[1] {"28 MCT"},
District = "Bến Cát",
State = "An Thới",
City = "Bình Dương",
Country = "VNM"
});
client.Update<Patient>(pat);
}
感谢您的帮助。
电信和地址字段是列表。因此,如果您有现有数据并执行 pat.Address.Add,它会向现有列表添加一个新项目 - 保留现有地址。在将更新的数据发送到服务器之前,您实际上必须先更新 Telecom/Address 字段。
例如 - 在 client.Read 和 client.Update 之间,使用 System.Linq:
var a = x.Address.First(ca => ca.Use == Address.AddressUse.Home);
a.Line = new string[] { "28 MCT" };