【发布时间】:2020-01-24 11:08:45
【问题描述】:
我在我的项目中使用Hl7.Fhir.R4 库,它是Azure API for FHIR 周围的API 包装器(在ASP.NET Core 2.2 中)。 在视图模型中,我将 FHIR 元素 (FHIR's General-Purpose Data Type) 声明为属性。示例:
public class MyPatient
{
public string Name { get; set;}
public Hl7.Fhir.Model.CodeableConcept MaritalStatus { get; set;} //This is
//defined in the library
}
现在,问题是:'MaritalStatus' 没有正确地从 json 解析到 c# 对象 (defined in the library)(即它只是 'not null')。也没有抛出任何异常。
详细解释: 这是我从前端收到的 JSON:
{
"name": "TheName",
"maritalStatus": {
"coding": [
{
"system": "terminology.hl7.org/CodeSystem/v3-MaritalStatus",
"code": "U",
"display": "unmarried"
}
],
"text": "Unmarried"
}
}
这是我从前端收到的 JSON 模型(C# 类):
public class MyPatient
{
public string Name { get; set;}
public Hl7.Fhir.Model.CodeableConcept MaritalStatus { get; set;}
}
这是满足请求的控制器操作(在包装层 - 我的项目中):
[HttpPut("{id}")]
[Consumes("application/json")]
[Produces("application/json")]
public async Task<ActionResult> Update([Required][FromRoute] string id,[Required][FromBody] MyPatient myPatient)
{
if (ModelState.IsValid)
{
Hl7.Fhir.Model.Patient patient = await _fhirClient.ReadAsync<Patient>(location: "Patient/" + id);
patient.MaritalStatus = myPatient.MaritalStatus;
patient.Name[0].Text = myPatient.Name;
patient = await _fhirClient.UpdateAsync<Patient>(patient);
return Ok();
}//ends If ModelState.IsValid
return BadRequest();
}//ends Update
【问题讨论】:
-
你能详细说明你在做什么吗?你是怎么解析的,json是什么样子的?当您说您正在使用官方库时,为什么不解析为常规 FHIR Patient 对象?为什么需要“MyPatient”类?
-
1.我需要更新 Azure FHIR Db 中的患者 FHIR 资源。我从前端获取 JSON 格式的“maritalStatus”对象,Json.NET(.NET Core 中的默认 JSON 解析器)将该对象解析为 C# 对象(类型:CodeableConcept)。然后我将这个 C# 对象的引用存储在检索到的 FHIR 资源 Patient.MaritalStatus 中。最后,我使用这个本地更新的对象对 Azure FHIR 服务器进行更新调用。 2. 我正在使用 .NET Core 中的默认 JSON 转换器进行解析。 3. 我需要允许用户仅部分更新患者对象(即“MaritalStatus”)。
-
json 看起来像: { "name": "TheName", "maritalStatus": { "coding": [ { "system": "terminology.hl7.org/CodeSystem/v3-MaritalStatus", "code": "U" , "display": "unmarried" } ], "text": "Unmarried" } }
-
我只需要解析“CodeableConcept”类型的“maritalStatus”,它是从包装层的前端获取的。因此,不可能将其解析为整个 Patient FHIR 对象。 @MirjamBaltus
标签: asp.net-core types hl7-fhir jsonparser fhir-net-api