Exemple #1
0
        public void Binding_CanCreate()
        {
            Binding binding = NewBinding <Person, PersonDto>();
            var     actual  = BindingValidator.IsValid(binding);

            Assert.AreEqual(true, actual);
        }
Exemple #2
0
        public void TestCodeableConceptValidation()
        {
            var val = new BindingValidator(_termService, "Demo");

            var binding = new ElementDefinition.BindingComponent
            {
                ValueSet = new ResourceReference("http://hl7.org/fhir/ValueSet/data-absent-reason"),
                Strength = BindingStrength.Required
            };

            var cc = new CodeableConcept();

            cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "NaN"));
            cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "not-asked"));

            var result = val.ValidateBinding(cc, binding);

            Assert.True(result.Success);

            cc.Coding.First().Code = "NaNX";
            result = val.ValidateBinding(cc, binding);
            Assert.True(result.Success);

            cc.Coding.Skip(1).First().Code = "did-ask";
            result = val.ValidateBinding(cc, binding);
            Assert.False(result.Success);

            //EK 2017-07-6 No longer reports warnings when failing a preferred binding
            binding.Strength = BindingStrength.Preferred;
            result           = val.ValidateBinding(cc, binding);
            Assert.True(result.Success);
            Assert.Equal(0, result.Warnings);
        }
Exemple #3
0
        public void TestEmptyIllegalAndLegalCode()
        {
            var val = new BindingValidator(_termService, "Demo");

            var binding = new ElementDefinition.BindingComponent
            {
                ValueSet = new ResourceReference("http://hl7.org/fhir/ValueSet/data-absent-reason"),
                Strength = BindingStrength.Required
            };

            var cc = new CodeableConcept();

            cc.Coding.Add(new Coding(null, null, "Just some display text"));

            // First, with no code at all in a CC
            var result = val.ValidateBinding(cc, binding);

            Assert.False(result.Success);
            Assert.Contains("No code found in instance", result.ToString());

            // Now with no code + illegal code
            cc.Coding.Add(new Coding("urn:oid:1.2.3.4.5", "16", "Here's a code"));
            result = val.ValidateBinding(cc, binding);
            Assert.False(result.Success);
            Assert.Contains("None of the Codings in the CodeableConcept were valid for the binding", result.ToString());

            // Now, add a third valid code according to the binding.
            cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "asked"));
            result = val.ValidateBinding(cc, binding);
            Assert.True(result.Success);
        }
 /// <summary>
 /// Validate the bindings of a keyvalue pair
 /// where the key is the View type and the value is the ViewModel type.
 /// </summary>
 /// <param name="viewViewModelDictionary">IDictionary of View type / ViewModel type</param>
 /// <returns>Enumerable of validations results</returns>
 public IEnumerable <ValidationResult> Validate(IDictionary <Type, Type> viewViewModelDictionary)
 {
     foreach (var viewViewModel in viewViewModelDictionary)
     {
         BindingValidator validator       = ValidatorFor(viewViewModel.Key, viewViewModel.Value);
         ValidationResult validatorResult = validator.Validate();
         yield return(validatorResult);
     }
 }
Exemple #5
0
        public void TestCodingValidation()
        {
            var val     = new BindingValidator(_termService, "Demo");
            var binding = new ElementDefinition.BindingComponent
            {
                ValueSet = new ResourceReference("http://hl7.org/fhir/ValueSet/data-absent-reason"),
                Strength = BindingStrength.Required
            };

            var c      = new Coding("http://hl7.org/fhir/data-absent-reason", "NaN");
            var result = val.ValidateBinding(c, binding);

            Assert.True(result.Success);

            c.Code = "NaNX";
            result = val.ValidateBinding(c, binding);
            Assert.False(result.Success);

            c.Code           = "NaN";
            binding.Strength = null;
            result           = val.ValidateBinding(c, binding);
            Assert.True(result.Success);
            Assert.Equal(1, result.Warnings);  // missing binding strength

            c.Display        = "Not a Number";
            binding.Strength = BindingStrength.Required;
            result           = val.ValidateBinding(c, binding);
            Assert.True(result.Success);

            c.Display = "Not a NumberX";
            result    = val.ValidateBinding(c, binding);
            Assert.True(result.Success);        // local terminology service treats incorrect displays as warnings (GH#624)

            // But this won't, it's also a composition, but without expansion - the local term server won't help you here
            var binding2 = new ElementDefinition.BindingComponent
            {
                ValueSet = new FhirUri("http://hl7.org/fhir/ValueSet/allergyintolerance-substance-code"),
                Strength = BindingStrength.Required
            };

            c      = new Coding("http://snomed.info/sct", "160244002");
            result = val.ValidateBinding(c, binding2);
            Assert.True(result.Success);
            Assert.NotEmpty(result.Where(type: OperationOutcome.IssueType.NotSupported));
        }
Exemple #6
0
        public void Binding_Action_CanMap()
        {
            Binding   binding   = NewBinding <Person, PersonDto>();
            PersonDto personDto = new PersonDto();

            if (BindingValidator.IsValid(binding))
            {
                binding.GetAction().Invoke(_person, personDto);
            }

            bool actual =
                personDto.FirstName.Equals(_person.FirstName) &&
                personDto.LastName.Equals(_person.LastName) &&
                personDto.Phone.Equals(_person.Phone) &&
                personDto.Nickname.Equals(_person.Nickname);

            Assert.AreEqual(true, actual);
        }
        protected static ValidationResult <TPresenter> BoundView()
        {
            BindingValidator <TPresenter> validator = Validator.For <TView, TPresenter>();

            return(validator.Validate());
        }