我有患者的JSON数据,我尝试用新数据更新它。当我尝试更新此患者时,条目将是重复的,并且不会像这样更新:
{
"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);
}
谢谢你的帮助。
发布于 2020-12-23 21:44:05
电信和地址字段是列表。因此,如果你有现有的数据,并且你做了pat.Address.Add,它会在现有的列表中添加一个新的项目--保留已经存在的地址。在将更新的数据发送到服务器之前,您实际上必须首先更新您的电信/地址字段。
例如,在client.Read和client.Update之间,使用System.Linq:
var a = x.Address.First(ca => ca.Use == Address.AddressUse.Home);
a.Line = new string[] { "28 MCT" };
https://stackoverflow.com/questions/65423618
复制相似问题