FHIR Chat · FHIR Validator in VSCode · IG creation

Stream: IG creation

Topic: FHIR Validator in VSCode


view this post on Zulip Eirik Myklebost (Oct 10 2021 at 15:34):

This might be useful for those of you using VSCode during IG creation: You can create a custom-task in tasks.json that runs the fhir-validator on your resources and reports the output as problems with highlighting in vscode using a custom problemMatcher:
vscode-validator-example.png

Note: This problemMatcher only works when validating at least 2 resources, because the console-output when validating a single resource differs from multi-resource validation.

tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run FHIR Validator",
      "type": "shell",
      "command": "java",
      "args": [
        "-jar", "validator_cli.jar",
        "${workspaceFolder}/test-resources",
        "-version", "4.0",
      ],
      "presentation": {
        "clear": true
      },
      "problemMatcher": [
        {
          "source": "FHIR Validator",
          "fileLocation": "absolute",
          "pattern": [
            {
              "regexp": "^-- (.+) -{5,}$",
              "file": 1,
            },
            {
              "regexp": "^.*$",
            },
            {
              "regexp": "^  ((?:Info|Warning|Error)).* \\(line ?(\\d+), col ?(\\d+)\\) : (.+)$",
              "severity": 1,
              "line": 2,
              //"column": 3,
              "message": 4,
              "loop": true
            }
          ]
        }
      ]
    }
  ]
}

view this post on Zulip Grahame Grieve (Oct 11 2021 at 01:08):

This problemMatcher only works when validating at least 2 resources, because the console-output when validating a single resource differs from multi-resource validation

umm. really? I would've thought it would be the other way around?

view this post on Zulip Eirik Myklebost (Oct 11 2021 at 07:59):

Grahame Grieve said:

This problemMatcher only works when validating at least 2 resources, because the console-output when validating a single resource differs from multi-resource validation

umm. really? I would've thought it would be the other way around?

Output from single resource validation:

Validating
  Validate fsh-generated\resources\Questionnaire-NAV-06-03-04.json   ..Detect format for fsh-generated\resources\Questionnaire-NAV-06-03-04.json
 00:01.0003
Done. Times: Loading: 00:12.0465, validation: 00:01.0004. Memory = 398Mb

Success: 0 errors, 5 warnings, 2 notes
  Information @ Questionnaire.item[0].answerValueSet (line 21, col68) : Canonical URL 'http://fhir.nav.no/ValueSet/icd10-vs-nr2' does not resolve

Output from multi resource validation:

Validating
  Validate fsh-generated\resources\Patient.json   ..Detect format for fsh-generated\resources\Patient.json
 00:00.0083
  Validate fsh-generated\resources\Questionnaire-NAV-06-03-04.json   ..Detect format for fsh-generated\resources\Questionnaire-NAV-06-03-04.json
 00:00.0836
Done. Times: Loading: 00:10.0786, validation: 00:00.0923 (#2). Memory = 353Mb

-- fsh-generated\resources\Patient.json --------------------------------------------
Success: 0 errors, 0 warnings, 1 notes
  Information @ ?? : All OK
------------------------------------------------------------------------------------

-- fsh-generated\resources\Questionnaire-NAV-06-03-04.json ---------------------------------------------------------------
Success: 0 errors, 5 warnings, 2 notes
  Information @ Questionnaire.item[0].answerValueSet (line 21, col68) : Canonical URL 'http://fhir.nav.no/ValueSet/icd10-vs-nr2' does not resolve

The problemMatcher uses regex and looks for -- {filepath} -----, which is excluded from the single-resource validation output.

view this post on Zulip Eirik Myklebost (Oct 12 2021 at 15:34):

@Grahame Grieve , is it possible to change the log format, or add support for different styles? Using an already established format will make it easier to integrate the validator in IDEs and tools, e.g. as a linter. ESlint's compact or stylish format are some alternatives.

view this post on Zulip Grahame Grieve (Oct 12 2021 at 18:28):

it's possible, sure. I'd accept a PR or you can create a task. I'

view this post on Zulip Grahame Grieve (Oct 12 2021 at 18:28):

I'm not going to change the default behaviour but we'd sure support an -output-style paramter

view this post on Zulip Eirik Myklebost (Oct 12 2021 at 21:46):

Alright, will look into it. :+1:

view this post on Zulip Grahame Grieve (Oct 21 2021 at 01:56):

ok so I added a parameter -output-style and a possible value eslint-compact. And it's now much easier to add any kind of other output style because I refactored the code to make it easy

view this post on Zulip Grahame Grieve (Oct 21 2021 at 01:56):

@Eirik Myklebost should be in today's release


Last updated: Apr 12 2022 at 19:14 UTC