设置 FHIR 服务器

Setting up a FHIR server

我正在尝试使用 asp.net 核心 (c#) 在我的本地主机(概念验证)环境中设置一个小服务器,但是当我访问 'get' 路线:

FormatException: Cannot determine type of resource to create from json input data. Is there a 'resourceType' member present? (at path 'line 1, pos 1')

这是我的代码:

[Route("Patient/rvrbk")]
public Patient ServeClient()
{
    Patient patient = new Patient();

    patient.Id = "1";
    patient.Gender = AdministrativeGender.Male;
    patient.Name = new List<HumanName> { new HumanName { Family = "Verbeek", Given = new List<string> { "Rik" }, Suffix = new List<string> { "The Small" } } };
    patient.BirthDate = "2004-03-10";
    patient.Active = true;

    return patient;
}

[Route("get")]
public Patient GetClient()
{
    FhirClient client = new FhirClient("http://localhost:54240/");

    var patient = client.Read<Patient>("Patient/rvrbk");

    return patient;
}

我已尝试在患者对象上设置 resourceType,但由于它是只读的,因此会产生错误。我确定我遗漏了一些微不足道的东西,但无法弄清楚是什么。

编辑

在@AdrianoRepetti 提供的答案之后,我想出了以下设置,但 运行 进入另一个错误:

FhirOperationException: Operation was unsuccessful, and returned status OK. OperationOutcome: Overall result: FAILURE (1 errors and 0 warnings) [ERROR] (no details)(further diagnostics: Endpoint returned a body with contentType 'text/plain', while a valid FHIR xml/json body type was expected. Is this a FHIR endpoint?).

代码:

[Route("Patient/rvrbk")]
public string ServeClient()
{
    Patient patient = new Patient();

    patient.Id = "1";
    patient.Gender = AdministrativeGender.Male;
    patient.Name = new List<HumanName> { new HumanName { Family = "Verbeek", Given = new List<string> { "Rik" }, Suffix = new List<string> { "The Small" } } };
    patient.BirthDate = "2004-03-10";
    patient.Active = true;

    FhirJsonSerializer serializer = new FhirJsonSerializer();

    string json = serializer.SerializeToString(patient);

    return json;
}

我明白了。

我的第一个问题是(正如@Adriano Repetti 所指出的那样)客户端不知道它正在接收哪个对象,这个问题通过 运行 对象通过 SerializeToString([object]) 解决了FhirJsonSerializer 提供的函数。

我的下一个问题是我返回了一个字符串,而客户期望 'application/json'。这是通过将 'server' 的返回类型更改为 JsonResult 并将生成的字符串解析为 json 和 JObject.Parse([string]).

来解决的

代码

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
using Hl7.Fhir.Serialization;
using Newtonsoft.Json.Linq;

namespace FIHR.Controllers
{
    [Route("")]
    public class HomeController : Controller
    {
        public string Index()
        {
            return "Welkom op de FIHR API";
        }

        [Route("Patient/rvrbk")]
        public IActionResult ServeClient()
        {
            Patient patient = new Patient();

            patient.Id = "1";
            patient.Gender = AdministrativeGender.Male;
            patient.Name = new List<HumanName> { new HumanName { Family = "Verbeek", Given = new List<string> { "Rik" }, Suffix = new List<string> { "The Small" } } };
            patient.BirthDate = "2004-03-10";
            patient.Active = true;

            FhirJsonSerializer serializer = new FhirJsonSerializer();

            string jstring = serializer.SerializeToString(patient);

            return Content(jstring, "application/json");
        }

        [Route("get")]
        public Patient GetClient()
        {
            FhirClient client = new FhirClient("http://localhost:54240/"); // http://vonk.fire.ly

            Patient patient = client.Read<Patient>("Patient/rvrbk"); // Patient/example

            return patient;
        }
    }
}