-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Personal/rogrdon/create common validation logic (#152)
* Initial commit * Allowing a batch of events to be validated * Adding documentation * Changes due to code review * Changed due to code review * Ensure multiple deviceEvents get validated * Updating test
- Loading branch information
1 parent
f660a25
commit 64d7be5
Showing
21 changed files
with
1,186 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/lib/Microsoft.Health.Fhir.Ingest.Validation/Extensions/IResultExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using EnsureThat; | ||
using Microsoft.Health.Fhir.Ingest.Validation.Models; | ||
|
||
namespace Microsoft.Health.Fhir.Ingest.Validation.Extensions | ||
{ | ||
public static class IResultExtensions | ||
{ | ||
public static void CaptureError(this IResult validationResult, string message, ErrorLevel errorLevel) | ||
{ | ||
EnsureArg.IsNotNull(validationResult, nameof(validationResult)); | ||
EnsureArg.IsNotNullOrWhiteSpace(message, nameof(message)); | ||
|
||
validationResult.Exceptions.Add(new ValidationError(message, errorLevel)); | ||
} | ||
|
||
public static void CaptureException(this IResult validationResult, Exception exception) | ||
{ | ||
EnsureArg.IsNotNull(validationResult, nameof(validationResult)); | ||
EnsureArg.IsNotNull(exception, nameof(exception)); | ||
|
||
validationResult.Exceptions.Add(new ValidationError(exception.Message)); | ||
} | ||
|
||
public static void CaptureWarning(this IResult validationResult, string warning) | ||
{ | ||
EnsureArg.IsNotNull(validationResult, nameof(validationResult)); | ||
EnsureArg.IsNotNullOrWhiteSpace(warning, nameof(warning)); | ||
|
||
validationResult.Exceptions.Add(new ValidationError(warning, ErrorLevel.WARN)); | ||
} | ||
|
||
public static IEnumerable<ValidationError> GetErrors(this IResult validationResult, ErrorLevel errorLevel) | ||
{ | ||
EnsureArg.IsNotNull(validationResult, nameof(validationResult)); | ||
return validationResult.Exceptions.Where(error => errorLevel.Equals(error.Level)); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/lib/Microsoft.Health.Fhir.Ingest.Validation/IMappingValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Health.Fhir.Ingest.Validation.Models; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.Health.Fhir.Ingest.Validation | ||
{ | ||
public interface IMappingValidator | ||
{ | ||
/// <summary> | ||
/// Performs validation of Device and Fhir Mapping templates. The templates will be first be validated individually and then validated for compatibility | ||
/// with each other. Finally, if a device event is supplied Measurements and Fhir Observations will attempt to be built from it. Any errors/warnings | ||
/// found will be captured in the resulting ValidationResult object. | ||
/// | ||
/// At least one of deviceMappingContent or fhirMappingContent must be provided. | ||
/// </summary> | ||
/// <param name="deviceEvent">A sample DeviceEvent. Optional</param> | ||
/// <param name="deviceMappingContent">A device mapping template. Optional</param> | ||
/// <param name="fhirMappingContent">A fhir mapping template. Optional</param> | ||
/// <returns>A ValidationResult object</returns> | ||
ValidationResult PerformValidation(JToken deviceEvent, string deviceMappingContent, string fhirMappingContent); | ||
|
||
/// <summary> | ||
/// Performs validation of Device and Fhir Mapping templates. The templates will be first be validated individually and then validated for compatibility | ||
/// with each other. Finally, if device events are supplied Measurements and Fhir Observations will attempt to be built from them. Any errors/warnings | ||
/// found will be captured in the resulting ValidationResult object. | ||
/// | ||
/// At least one of deviceMappingContent or fhirMappingContent must be provided. | ||
/// </summary> | ||
/// <param name="deviceEvents">A collection of DeviceEvents. Optional</param> | ||
/// <param name="deviceMappingContent">A device mapping template. Optional</param> | ||
/// <param name="fhirMappingContent">A fhir mapping template. Optional</param> | ||
/// <returns>A ValidationResult object</returns> | ||
ValidationResult PerformValidation(IEnumerable<JToken> deviceEvents, string deviceMappingContent, string fhirMappingContent); | ||
} | ||
} |
Oops, something went wrong.