microsoft/Tools-for-Health-Data-Anonymization

Cannot instantiate `AnonymizerEngine`

evergreen-lee-campbell opened this issue · 2 comments

Firstly, this is a brilliant idea for a project. Thank you!

I'm using the AnonymizerEngine class from the NuGet package at:

<PackageReference Include="Microsoft.Health.Fhir.Anonymizer.R4.Core" Version="3.0.0.33" />

with the following configuration file:

https://raw.githubusercontent.com/microsoft/Tools-for-Health-Data-Anonymization/master/FHIR/src/Microsoft.Health.Fhir.Anonymizer.R4.CommandLineTool/configuration-sample.json

Upon instantiating the class, the following Exception is thrown:

Microsoft.Health.Fhir.Anonymizer.Core.Exceptions.AnonymizerConfigurationException
  HResult=0x80131500
  Message=Invalid FHIR path nodesByType('Extension')
  Source=Microsoft.Health.Fhir.Anonymizer.R4.Core
  StackTrace:
   at Microsoft.Health.Fhir.Anonymizer.Core.AnonymizerConfigurations.AnonymizerConfigurationValidator.Validate(AnonymizerConfiguration config)
   at Microsoft.Health.Fhir.Anonymizer.Core.AnonymizerConfigurationManager..ctor(AnonymizerConfiguration configuration)
   at Microsoft.Health.Fhir.Anonymizer.Core.AnonymizerConfigurationManager.CreateFromSettingsInJson(String settingsInJson)
   at Microsoft.Health.Fhir.Anonymizer.Core.AnonymizerConfigurationManager.CreateFromConfigurationFile(String configFilePath)
   at Microsoft.Health.Fhir.Anonymizer.Core.AnonymizerEngine..ctor(String configFilePath)
   at [REFERENCES TO MY CALLING CODE]

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
ArgumentException: Unknown symbol 'nodesByType'

Any idea what I might be doing wrong?

Hi,
For the current NuGet package, if using 'nodesByType' expression, you should first initialize this symbol
Sample usage:

AnonymizerEngine.InitializeFhirPathExtensionSymbols(); // Initialize extension symbols

var engine = new AnonymizerEngine("configuration-sample.json");
var result = engine.AnonymizeJson(File.ReadAllText("sample.json"));

I will follow the issue if any other questions.

That's solved it! Thank you :)