【问题标题】:fhir-net-api (STU3) - Validatingfhir-net-api (STU3) - 验证
【发布时间】:2018-11-20 18:17:32
【问题描述】:

我一直在使用 Hl7.org 工具 org.hl7.fhir.validator.jar 文件来验证我的消息,但我想将此函数添加到我的 .Net 项目中。解析消息后,我可以调用一个类来验证结构。

在 fhir-net-api 中是否有一个验证 FHIR 类将显示与 org.hl7.fhir.validator.jar 相同的结果?

    string HL7FilePath = string.Format("{0}\\{1}", System.IO.Directory.GetCurrentDirectory(), "Sample.xml");
    string HL7FileData = File.ReadAllText(HL7FilePath)

    var b = new FhirXmlParser().Parse<PlanDefinition>(HL7FileData);


FHIR Validator Build ??
Arguments: C:\HL7Tools\validator\REC78_1.xml -version 3.0
  .. connect to tx server @ http://tx.fhir.org
  .. definitions from hl7.fhir.core#3.0.1
    (v3.0.1-null)
  .. validate [C:\HL7Tools\validator\Sample.xml]
Terminology server: Check for supported code systems for http://www.nlm.nih.gov/research/umls/rxnorm
Success.

【问题讨论】:

    标签: hl7-fhir fhir-net-api


    【解决方案1】:

    是的,有。您需要添加 Hl7.Fhir.Specification.STU3 包,然后可以使用这样的验证方法:

    using Hl7.Fhir.Specification.Source;
    using Hl7.Fhir.Validation;
    
    ... your code, reading the PlanDefinition from file and parsing it ...
    
    // setup the resolver to use specification.zip, and a folder with custom profiles
    var source = new CachedResolver(new MultiResolver(
                                       new DirectorySource(@"<path_to_profile_folder>"),
                                       ZipSource.CreateValidationSource()));
    
    // prepare the settings for the validator
    var ctx = new ValidationSettings()
              {
                  ResourceResolver = source,
                  GenerateSnapshot = true,
                  Trace = false,
                  EnableXsdValidation = true,
                  ResolveExteralReferences = false
              }
    
    var validator = new Validator(ctx);
    
    // validate the resource; optionally enter a custom profile url as 2nd parameter
    var result = validator.Validate(b);
    

    结果将是一个包含验证详细信息的 OperationOutcome 资源。

    【讨论】:

    • 这是我收到的消息 总体结果:失败(2 个错误和 0 个警告)[错误] 无法解析对配置文件“hl7.org/fhir/StructureDefinition/PlanDefinition”的引用(在 PlanDefinition)[错误] 无法解析引用配置文件“nccn.org/fhir/StructureDefinition/order-template”(在 PlanDefinition)
    • 我从hl7.org/fhir/downloads.html 下载了整个规范,所以我不确定为什么会出现这个错误。
    • 当您添加 Hl7.Fhir.Specification.STU3 包时,应该会自动将 specification.zip 文件添加到您的项目中。这是您使用 ZipSource.CreateValidationSource 时所读取的内容。无需自行下载规范,但如果有,您可以将 DirectorySource 指向该文件夹。 NCCN 配置文件不在 specification.zip 中,因此您需要下载它们并将 DirectorySource 指向该文件夹。还请检查配置文件的 url,因为我有 NCCN 订单模板:ots.nccn.org/fhir/StructureDefinition/OrderTemplate.
    • 我尝试使用我的 ig,但仍然收到相同的错误消息。 var source = new CachedResolver(new MultiResolver( new DirectorySource(string.Format("{0}\\{1}", "C:\\Project\\IGPublisher\\Publish", "ig.json")), ZipSource .CreateValidationSource()));
    • 您是否可以尝试仅在 DirectorySource 中添加您的文件夹而不是文件,或者取出 DirectorySource 以查看是否至少找到了 specification.zip?如果需要,您可以通过docs.simplifier.net/fhirnetapi/contact.html 上的地址与我联系以获取更多故障排除。
    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 2011-06-04
    • 2014-06-14
    • 1970-01-01
    相关资源
    最近更新 更多