private void ValidateOutput(AnonymizerSettings settings, Resource anonymizedNode)
 {
     if (settings != null && settings.ValidateOutput)
     {
         _validator.ValidateOutput(anonymizedNode);
     }
 }
        public string AnonymizeJson(string json, AnonymizerSettings settings = null)
        {
            EnsureArg.IsNotNullOrEmpty(json, nameof(json));

            ElementNode root;
            Resource    resource;

            try
            {
                resource = _parser.Parse <Resource>(json);
                root     = ElementNode.FromElement(resource.ToTypedElement());
            }
            catch (Exception innerException)
            {
                throw new Exception("Failed to parse json resource, please check the json content.", innerException);
            }

            if (settings != null && settings.ValidateInput)
            {
                _validator.ValidateInput(resource);
            }
            var anonymizedNode = AnonymizeResourceNode(root);

            if (settings != null && settings.ValidateOutput)
            {
                anonymizedNode.RemoveNullChildren();
                _validator.ValidateOutput(anonymizedNode.ToPoco <Resource>());
            }

            FhirJsonSerializationSettings serializationSettings = new FhirJsonSerializationSettings
            {
                Pretty = settings != null && settings.IsPrettyOutput
            };

            return(anonymizedNode.ToJson(serializationSettings));
        }