- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 HL7.Fhir nuget由 Ewout Kramer 创建的软件包 0.9.3。
我将其与 ASP.NET Web API 绑定(bind)在一起,但不幸的是内置的 JSON 序列化无法正确生成 JSON。它包含很多这样的内容:
"<IdentifierElement>k__BackingField"
根据框架的建议,这段代码可以工作......
public HttpResponseMessage GetConformance()
{
var conformance = new Conformance();
var json = FhirSerializer.SerializeResourceToJson(conformance);
return new HttpResponseMessage{Content = new StringContent(json)};
}
但这将变得非常重复,并且不遵循 Web API 的“按照惯例”json/xml 序列化方法。
还有其他可用的 FHIR 对象包还是我应该编写自己的包?
最佳答案
虽然较新版本的 HL7.Fhir NuGet 包(目前处于测试阶段)将携带额外的 [DataContract] 和 [DataMember] 属性,从而防止此类错误,但标准 .NET DataContract 序列化程序将无法将内存中的 POCO 序列化为正确的 FHIR XML 和 Json 表示形式。 FHIR 序列化对于如何使用 XML 和 json 有特定的规则,使用 DataContract 序列化程序的(有限)可能性来配置这即使不是不可能,也是很困难的。
但是,也没有必要为每个调用调用 FhirSerializer,如您在代码片段中所示(事实上,这将是 WebApi 反模式)。例如,我们的 FHIR 服务器(位于 http://spark.furore.com/fhir )基于 WebApi 并使用自定义 MediaTypeFormatter 来处理此问题。为了体验一下它的样子,我们创建了两个格式化程序,一个用于 json,一个用于 xml:
public class JsonFhirFormatter : MediaTypeFormatter
{
public JsonFhirFormatter() : base()
{
foreach (var mediaType in ContentType.JSON_CONTENT_HEADERS)
SupportedMediaTypes.Add(new MediaTypeHeaderValue(mediaType));
}
}
这告诉框架此格式化程序将采用 ContentType.JSON_CONTENT_HEADERS 中的任何格式(即 application/json 和一些常见变体),并且能够解析和读取 FHIR ModelTypes:
public override bool CanReadType(Type type)
{
return type == typeof(ResourceEntry) || type == typeof(Bundle) || (type == typeof(TagList));
}
public override bool CanWriteType(Type type)
{
return type == typeof(ResourceEntry) || type == typeof(Bundle) || (type == typeof(TagList)) || type == typeof(OperationOutcome);
}
最后,您必须重写 ReadFromStreamAsync 和 WriteToStreamAsync 方法:
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
{
// Some code left out...
XmlWriter writer = new XmlTextWriter(writeStream, Encoding.UTF8);
if (type == typeof(ResourceEntry))
{
ResourceEntry entry = (ResourceEntry)value;
FhirSerializer.SerializeResource(entry.Resource, writer);
content.Headers.SetFhirTags(entry.Tags);
}
现在,完成此操作后,您的 Controller 可以简单地执行以下操作:
[HttpGet, Route("metadata")]
public ResourceEntry Metadata()
{
return service.Conformance();
}
[HttpOptions, Route("")]
public ResourceEntry Options()
{
return service.Conformance();
}
请注意,我们的服务器不使用资源作为 Controller 中的参数和返回值。资源不允许您捕获重要的元数据(如 ID、版本 ID、上次修改日期等)。通过在我的 Controller 中使用 ResourceEntry,此数据可以与资源数据一起传递,并且 WebApi 框架可以将此元数据绑定(bind)到适当的 HTTP header 。
关于asp.net-web-api - HL7 FHIR 在 asp.net web api 中序列化为 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21117815/
我认为我正在努力正确定义以下不明确的操作码:LD HL,SP+r8 和 JP (HL) 操作码 (0xE9) > 和 0xF8 分别) 在我的实现中,LD HL,SP+r8 将 HL 设置为 SP+r
我尝试创建一个多线程单例模式类。 标题: class HL{ public: static HL* getInstance(); ......... priva
Windows 7、Emacs 25.1 如果我想改变 hl-line 的背景颜色,我会这样做: (set-face-background 'hl-line "#333333") 好的。但是如何为 h
我使用的是 solr 3.5,并在我的搜索查询中设置了 hl.fragsize = 100 ,但我的片段不完全包含 100 个字符,事实上,平均片段大小是 120。 任何人都可以对这个问题有想法吗?
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
这可以通过以下方式实现: 11 pop hl 10 push hl 在 21 个周期内。我发现的唯一选择是 ex (sp),hl,它需要 19 个周期。缺点是内容必须在我处理完它们后才能恢复到原来的值
我有一个动态文本字段 bar_*在我的索引中,并希望 Solr 返回该字段的突出显示。所以我运行的是: q=gold&hl=true&hl.fl=bar_* 它按预期工作,但以防万一我向 hl.fl
我使用以下代码在全局范围内启用 hl-mode。 (global-hl-line-mode t) 在指定模式下关闭 hl-line 功能。我用下面的代码来做。 (add-hook 'org-mode-
Emacs的hl-line-mode正是我所需要的,但我想更改为可怕的黄色,有人知道我该怎么做吗? 最佳答案 我使用(set-face-background hl-line-face "gray13"
我通过评估突出显示当前行: (hl-line-mode) 也可以全局设置: (global-hl-line-mode nil) 问题是这种方式行突出显示会覆盖highlight-phrase。所以我的
我使用波纹管代码来保护一段 .net 程序。我们选择使用 api 而不是经典的 Envelope 方法,因为我们想要自定义行为而不仅仅是普通窗口“找不到 key ” 我的问题是如何保护供应商代码,因为
我通常让 hl-line 对当前背景采用稍暗的阴影。这在编辑缓冲区时效果很好。但是,在某些缓冲区中,例如 Org 议程和 Gnus 组缓冲区,我想使用更漂亮的颜色(代替光标)。 具体来说,我想更改 g
我使用 Cocoa Emacs 23.1.91,并且我希望始终关闭 hl-line-mode,因为我不喜欢使用它。我可以通过 M-x hl-line-mode 为每个缓冲区关闭它,但这很乏味。任何帮助
我只想知道是否可以制作一个标签或任何其他整数并将其显示到我的游戏 View 中。 var pvElf = SKLabelNode(fontNamed:"Chalkduster") pvElf.text
好的。好吧,我知道这个问题很有可能会在前 10 分钟内结束,但我还是要问这个问题,因为我已经花了将近一天半的时间来寻找解决方案。仍然,我无法弄清楚这一点。尽管有演示,但在 Internet 上甚至在
当我启用 hl-line-mode 时,文件的最后一行只突出显示到它的最后一个字符(如果该行为空,则根本不会突出显示),而不是像其他行一样一直突出显示。一个肮脏的修复是在文件末尾添加一个空行,但我想知
标题基本概括了所有内容。当我:source $MYVIMRC或 :source ~/.vimrc ,重新出现上次搜索。我可以用 :noh 轻松地再次关闭它,但每次我都会重新出现 :source . 这
我们如何配置(或修复?)hl-line,使其背景高亮显示在堆栈中的最后(或第一个?)。 也就是说:如果 hl-line 突出显示某些单词已经具有背景颜色的行,则 hl-line 不应使用自己的背景颜色
使用 solr,我尝试使用 hl.formatter 选项和 hl.simple.pre/post 突出显示一些文本。 我的问题是 hl.simple.pre/post 代码有时没有出现在突出显示的结
我正在尝试为 dired 模式启用 hl-line-mode,但它不起作用。启用 global-hl-mode 有效,但它是每个缓冲区,而不仅仅是我不想要的缓冲区。 (defun hl-mode-fo
我是一名优秀的程序员,十分优秀!