[英]HL7 FHIR routing with advanced search and modifiers in .Net
我目前正試圖用FHIR搜索來繞過路由。
在網頁https://www.hl7.org/fhir/search.html的 2.1.1.48字符串中,有一節介紹如何使用修飾符返回包含或匹配提供的參數值的結果。
例如:
[base]/Patient?name=eve
[base]/Patient?name:contains=eve
[base]/Patient?name:exact=Eve
我從未見過這些自定義修飾符“?name:exact / contains”在f.ex中被接受的URL。 開箱即用的web api服務。
據我所見,不允許寫一些內容
[Route("{type}/name:contains/{name}")]
public HttpResponseMessage GetContainsName(string name){
//do something
}
[Route("{type}/name:exact/{name}")]
public HttpResponseMessage GetExactName(string name) {
//do something else
}
在sqlonfhir服務器(我也相信Spark服務器)中,參數的處理不是通過webapi路由完成的。
我們都使用路由來提取resourcename,id,operation(以及history和versionId)所有其他功能都是通過從RequestUrl中提取內容並處理它來手動完成的。
[HttpGet, Route("{ResourceName}/{id}/_history/{vid}")]
public HttpResponseMessage Get(string ResourceName, string id, string vid)
{
var buri = this.CalculateBaseURI("{ResourceName}");
fhirstore.RegisterKnownUrl(buri);
if (!Id.IsValidValue(id))
{
throw new FhirServerException(HttpStatusCode.BadRequest, "ID [" + id + "] is not a valid FHIR Resource ID");
}
IModelBase model = GetModel(ResourceName, GetInputs(buri));
var resource = model.Get(id, vid, summary);
if (resource != null)
{
var msg = Request.ResourceResponse(resource, HttpStatusCode.OK);
msg.Headers.Location = resource.ResourceIdentity().WithBase(resource.ResourceBase);
msg.Headers.Add("ETag", String.Format("\"{0}\"", resource.Meta.VersionId));
return msg;
}
// this request is a "you wanted what?"
return Request.CreateResponse(HttpStatusCode.NotFound);
}
(不是完整的代碼提取 - 我剝離了處理二進制資源的代碼,以及_summary參數內容處理)
此代碼中的另一個值得注意的是,處理是在模型中完成的(因此我可以在Web上下文外部進行單元測試)。 CalculateBaseURI方法可確保將請求中的URL應用於結果上的位置,而無需使用配置設置來告知服務器放置哪些內容。
在我討論它的同時,我們也使用媒體格式化器來解析資源內容。
這是使FHIR服務器啟動並運行的可能解決方案。 我使用了Sparks.Engine中的一些代碼,因此更容易使修飾符工作以及“解碼”url。
你希望得到任何一種方法的命中
這些方法應該接受這些網址
fhir/Patient/1
fhir/Patient?name=something
fhir/?_query="nameOfQuery"&name:contains="someName"
服務器本身的代碼如下所示
namespace FHIRServer.Controllers
{
[RoutePrefix("fhir"), EnableCors("*", "*", "*", "*")]
[RouteDataValuesOnly]
public class FhirController : ApiController
{
public FhirController()
{
}
[HttpGet, Route("{type}")]
public HttpResponseMessage ResourceQuery(string type)
{
var searchParams = Request.GetSearchParams();
// do something with the search params
}
[HttpGet, Route("")]
public HttpResponseMessage Query(string _query)
{
var searchParams = Request.GetSearchParams();
// do something with the search params
}
}
}
Request.GetSearchParams()是Sparks.Engine的一部分,你可以在這里找到https://github.com/furore-fhir/spark我已經將Sparks.Engine添加到我們的FHIR解決方案,因為它有很多功能已經實施。
該
var searchParams = Request.GetSearchParams();
幫助解析網址中的不同參數,並使其更容易從那里前進。
這個答案的靈感來自Brian在此主題中的前一個答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.