コード例 #1
0
        private static Resource ValidateCodeOperation(string systemURL, NameValueCollection queryParam)
        {
            string codeVal     = Utilities.GetQueryValue("code", queryParam);
            string displayVal  = Utilities.GetQueryValue("display", queryParam);
            string languageVal = Utilities.GetQueryValue("displayLanguage", queryParam);

            if (!string.IsNullOrEmpty(languageVal) && languageVal != "en-NZ")
            {
                throw new Exception(UNSUPPORTED_DISPLAY_LANGUAGE);
            }

            FhirBoolean validCode    = new FhirBoolean(false);
            FhirString  validDisplay = new FhirString();

            if (FhirSnomed.IsValidURI(systemURL))
            {
                validCode    = new FhirBoolean(FhirSnomed.ValidateCode(codeVal, displayVal, out string prefTerm));
                validDisplay = new FhirString(prefTerm);
            }
            else
            {
                CodeSystem codeSys = GetCodeSystem(TerminologyOperation.validate_code, systemURL, queryParam);

                foreach (CodeSystem.ConceptDefinitionComponent cc in codeSys.Concept)
                {
                    if (string.IsNullOrEmpty(displayVal))
                    {
                        validCode    = new FhirBoolean(true);
                        validDisplay = new FhirString(cc.Display);
                    }
                    else if (displayVal.Trim().ToLower() == cc.Display.Trim().ToLower())
                    {
                        validCode    = new FhirBoolean(true);
                        validDisplay = new FhirString(cc.Display);
                    }
                    else
                    {
                        validDisplay = new FhirString(cc.Display);
                    }
                }
            }

            // build return parameters resource from search result

            Parameters param = new Parameters();

            param.Add("result", validCode);

            if (validCode.Value == false)
            {
                param.Add("message", new FhirString("The code/display value " + codeVal + " / " + displayVal + " passed is incorrect"));
            }

            if (!string.IsNullOrEmpty(validDisplay.Value))
            {
                param.Add("display", validDisplay);
            }

            return(param);
        }
        public void GivenListOfPrimitiveElementNodes_WhenGetDecendantsByType_AllNodesShouldBeReturned()
        {
            Date        date       = new Date();
            Instant     instant    = new Instant();
            FhirBoolean boolean    = new FhirBoolean();
            FhirString  fhirString = new FhirString();

            var nodes = new PrimitiveType[] { date, instant, boolean, fhirString }.Select(n => ElementNode.FromElement(n.ToTypedElement()));

            var results = FhirPathSymbolExtensions.NodesByType(nodes, "string").Select(n => n.Location);

            Assert.Single(results);
            Assert.Contains("string", results);

            results = FhirPathSymbolExtensions.NodesByType(nodes, "date").Select(n => n.Location);
            Assert.Single(results);
            Assert.Contains("date", results);

            results = FhirPathSymbolExtensions.NodesByType(nodes, "boolean").Select(n => n.Location);
            Assert.Single(results);
            Assert.Contains("boolean", results);

            results = FhirPathSymbolExtensions.NodesByType(nodes, "instant").Select(n => n.Location);
            Assert.Single(results);
            Assert.Contains("instant", results);
        }
コード例 #3
0
        public async static Task <ValidateCodeResult> ValidateCodeAsync(this IFhirClient client,
                                                                        FhirUri identifier    = null, FhirUri context                 = null, ValueSet valueSet  = null, Code code = null,
                                                                        FhirUri system        = null, FhirString version              = null, FhirString display = null,
                                                                        Coding coding         = null, CodeableConcept codeableConcept = null, FhirDateTime date  = null,
                                                                        FhirBoolean @abstract = null)
        {
            var par = new Parameters()
                      .Add(nameof(identifier), identifier)
                      .Add(nameof(context), context)
                      .Add(nameof(valueSet), valueSet)
                      .Add(nameof(code), code)
                      .Add(nameof(system), system)
                      .Add(nameof(version), version)
                      .Add(nameof(display), display)
                      .Add(nameof(coding), coding)
                      .Add(nameof(codeableConcept), codeableConcept)
                      .Add(nameof(date), date)
                      .Add(nameof(@abstract), @abstract);

            var result = await client.TypeOperationAsync <ValueSet>(RestOperation.VALIDATE_CODE, par).ConfigureAwait(false);

            if (result != null)
            {
                return(ValidateCodeResult.FromParameters(result.OperationResult <Parameters>()));
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public void AddingModifierExtensionToPatientResource()
        {
            var pat     = new Patient();
            var isRobot = new FhirBoolean(true);

            pat.ModifierExtension.Add(new Extension("http://example.org/robot", isRobot));
        }
コード例 #5
0
        public void TestAddAnnotation()
        {
            FhirBoolean data = new FhirBoolean();

            Assert.IsNull(data.Annotation(typeof(AnnotationData)));
            data.AddAnnotation(new AnnotationData {
                Data = "hi!"
            });
            Assert.IsNotNull(data.Annotation(typeof(AnnotationData)));
            Assert.AreEqual("hi!", data.Annotation <AnnotationData>().Data);
            Assert.AreEqual(1, data.Annotations(typeof(AnnotationData)).Count());

            data.AddAnnotation(new AnnotationData {
                Data = "hi2!"
            });

            // Does not change original outcome (still the first)
            Assert.IsNotNull(data.Annotation(typeof(AnnotationData)));
            Assert.AreEqual("hi!", data.Annotation <AnnotationData>().Data);

            Assert.AreEqual(2, data.Annotations(typeof(AnnotationData)).Count());
            Assert.AreEqual("hi2!", data.Annotations <AnnotationData>().Skip(1).First().Data);

            data.AddAnnotation("Bare string");

            Assert.AreEqual(2, data.Annotations(typeof(AnnotationData)).Count());
            Assert.AreEqual("hi!", data.Annotation <AnnotationData>().Data);

            data.RemoveAnnotations <AnnotationData>();
            Assert.AreEqual(0, data.Annotations(typeof(AnnotationData)).Count());

            Assert.AreEqual("Bare string", data.Annotation <string>());
        }
コード例 #6
0
        public ψParameterElement(
            ItIndexElement tIndexElement,
            FhirBoolean value)
        {
            this.tIndexElement = tIndexElement;

            this.Value = value;
        }
コード例 #7
0
 public static ValidateCodeResult ValidateCode(this IFhirClient client,
                                               FhirUri identifier    = null, FhirUri context                 = null, ValueSet valueSet  = null, Code code = null,
                                               FhirUri system        = null, FhirString version              = null, FhirString display = null,
                                               Coding coding         = null, CodeableConcept codeableConcept = null, FhirDateTime date  = null,
                                               FhirBoolean @abstract = null)
 {
     return(ValidateCodeAsync(client, identifier, context, valueSet, code, system, version, display,
                              coding, codeableConcept, date, @abstract).WaitResult());
 }
コード例 #8
0
        public void ToStringHandlesNullObjectValue()
        {
            var s = new FhirString(null);

            Assert.IsNull(s.ToString());

            var i = new FhirBoolean(null);

            Assert.IsNull(i.ToString());
        }
コード例 #9
0
        public void Can_ConvertElement_R3_FhirBoolean_To_R4_FhirBoolean()
        {
            var value          = true;
            var r3TypeInstance = new FhirBoolean(value);
            var r4TypeInstance = new FhirConverter(FhirVersion.R4, FhirVersion.R3)
                                 .Convert <FhirBoolean, FhirBoolean>(r3TypeInstance);

            Assert.NotNull(r4TypeInstance);
            Assert.Equal(value, r4TypeInstance.Value);
        }
コード例 #10
0
        public ζParameterElement(
            IsIndexElement sIndexElement,
            ImIndexElement mIndexElement,
            FhirBoolean value)
        {
            this.sIndexElement = sIndexElement;

            this.mIndexElement = mIndexElement;

            this.Value = value;
        }
コード例 #11
0
        public yParameterElement(
            IsIndexElement sIndexElement,
            IrIndexElement rIndexElement,
            FhirBoolean value)
        {
            this.sIndexElement = sIndexElement;

            this.rIndexElement = rIndexElement;

            this.Value = value;
        }
コード例 #12
0
        public γParameterElement(
            IrIndexElement rIndexElement,
            ItIndexElement tIndexElement,
            FhirBoolean value)
        {
            this.rIndexElement = rIndexElement;

            this.tIndexElement = tIndexElement;

            this.Value = value;
        }
コード例 #13
0
        public vParameterElement(
            ImIndexElement mIndexElement,
            IrIndexElement rIndexElement,
            FhirBoolean value)
        {
            this.mIndexElement = mIndexElement;

            this.rIndexElement = rIndexElement;

            this.Value = value;
        }
コード例 #14
0
        public wParameterElement(
            IjIndexElement jIndexElement,
            IrIndexElement rIndexElement,
            FhirBoolean value)
        {
            this.jIndexElement = jIndexElement;

            this.rIndexElement = rIndexElement;

            this.Value = value;
        }
コード例 #15
0
        public void FhirBooleanMapTest()
        {
            var input = new FhirBoolean(false);

            var result = sut.Map(input);

            Assert.AreEqual(1, result.Count());
            Assert.IsInstanceOfType(result[0], typeof(CompositeValue));
            var comp = (CompositeValue)result[0];

            CheckCoding(comp, code: "false", system: null, text: null);
        }
コード例 #16
0
        public void TestAnnotationsAreCloneable()
        {
            FhirBoolean data = new FhirBoolean(true);

            data.AddAnnotation(new AnnotationData {
                Data = "Hi!"
            });

            var copied = (FhirBoolean)data.DeepCopy();

            Assert.AreEqual("Hi!", copied.Annotation <AnnotationData>().Data);
        }
コード例 #17
0
        public void NativelySerializedElements()
        {
            Integer i    = new Integer(3141);
            var     json = FhirSerializer.SerializeElementAsJson(i);

            Assert.AreEqual("{\"value\":3141}", json);

            FhirBoolean b = new FhirBoolean(false);

            json = FhirSerializer.SerializeElementAsJson(b);
            Assert.AreEqual("{\"value\":false}", json);
        }
コード例 #18
0
        public void FhirBooleanMapTest()
        {
            var input = new FhirBoolean(false);

            var result = _sut.Map(input);

            Assert.Single(result);
            Assert.IsType <CompositeValue>(result[0]);
            var comp = (CompositeValue)result[0];

            CheckCoding(comp, "false", null, null);
        }
コード例 #19
0
        public void Test_FhirBoolean_TokenIndexSetter_FhirBoolean_IsNull()
        {
            //Arrange
            FhirBoolean FhirBoolean = null;

            TokenIndex Index = new TokenIndex();

            //Act
            ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(FhirBoolean, Index) as TokenIndex;

            //Assert
            Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>());
        }
コード例 #20
0
ファイル: ModelTests.cs プロジェクト: evrimulgen/fhir-net-api
        public void ExtensionManagement()
        {
            Patient p  = new Patient();
            var     u1 = "http://fhir.org/ext/ext-test";

            Assert.IsNull(p.GetExtension("http://fhir.org/ext/ext-test"));

            Extension newEx = p.SetExtension(u1, new FhirBoolean(true));

            Assert.AreSame(newEx, p.GetExtension(u1));

            p.AddExtension("http://fhir.org/ext/ext-test2", new FhirString("Ewout"));
            Assert.AreSame(newEx, p.GetExtension(u1));

            p.RemoveExtension(u1);
            Assert.IsNull(p.GetExtension(u1));

            p.SetExtension("http://fhir.org/ext/ext-test2", new FhirString("Ewout Kramer"));
            var ew = p.GetExtensions("http://fhir.org/ext/ext-test2");

            Assert.AreEqual(1, ew.Count());

            p.AddExtension("http://fhir.org/ext/ext-test2", new FhirString("Wouter Kramer"));

            ew = p.GetExtensions("http://fhir.org/ext/ext-test2");
            Assert.AreEqual(2, ew.Count());

            Assert.AreEqual(0, p.ModifierExtension.Count());
            var me = p.AddExtension("http://fhir.org/ext/ext-test3", new FhirString("bla"), isModifier: true);

            Assert.AreEqual(1, p.ModifierExtension.Count());
            Assert.AreEqual(me, p.GetExtension("http://fhir.org/ext/ext-test3"));
            Assert.AreEqual(me, p.GetExtensions("http://fhir.org/ext/ext-test3").Single());
            Assert.AreEqual(3, p.AllExtensions().Count());

            var code = new Code("test");

            p.AddExtension("http://fhir.org/ext/code", code);
            Assert.AreEqual(code, p.GetExtensionValue <Code>("http://fhir.org/ext/code"));

            var text = new FhirString("test");

            p.AddExtension("http://fhir.org/ext/string", text);
            Assert.AreEqual(text, p.GetExtensionValue <FhirString>("http://fhir.org/ext/string"));

            var fhirbool = new FhirBoolean(true);

            p.AddExtension("http://fhir.org/ext/bool", fhirbool);
            Assert.AreEqual(fhirbool, p.GetExtensionValue <FhirBoolean>("http://fhir.org/ext/bool"));
        }
コード例 #21
0
        public void TestValueValidation()
        {
            var ed = new ElementDefinition
            {
                Binding = new ElementDefinition.BindingComponent
                {
                    Strength = BindingStrength.Required,
                    ValueSet = new ResourceReference("http://hl7.org/fhir/ValueSet/data-absent-reason")
                }
            };

            // Non-bindeable things should succeed
            Element v   = new FhirBoolean(true);
            var     nav = new PocoNavigator(v);

            Assert.True(_validator.ValidateBinding(ed, nav).Success);

            v   = new Quantity(4.0m, "masked", "http://hl7.org/fhir/data-absent-reason"); // nonsense, but hey UCUM is not provided with the spec
            nav = new PocoNavigator(v);
            Assert.True(_validator.ValidateBinding(ed, nav).Success);

            v   = new Quantity(4.0m, "maskedx", "http://hl7.org/fhir/data-absent-reason"); // nonsense, but hey UCUM is not provided with the spec
            nav = new PocoNavigator(v);
            Assert.False(_validator.ValidateBinding(ed, nav).Success);

            v   = new Quantity(4.0m, "kg"); // sorry, UCUM is not provided with the spec - still validate against data-absent-reason
            nav = new PocoNavigator(v);
            Assert.False(_validator.ValidateBinding(ed, nav).Success);

            v   = new FhirString("masked");
            nav = new PocoNavigator(v);
            Assert.True(_validator.ValidateBinding(ed, nav).Success);

            v   = new FhirString("maskedx");
            nav = new PocoNavigator(v);
            Assert.False(_validator.ValidateBinding(ed, nav).Success);

            var ic  = new Coding("http://hl7.org/fhir/data-absent-reason", "masked");
            var ext = new Extension {
                Value = ic
            };

            nav = new PocoNavigator(ext);
            Assert.True(_validator.ValidateBinding(ed, nav).Success);

            ic.Code = "maskedx";
            nav     = new PocoNavigator(ext);
            Assert.False(_validator.ValidateBinding(ed, nav).Success);
        }
コード例 #22
0
        /// <summary>
        /// { code : true/false }, system is absent
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private List <Expression> ToExpressions(FhirBoolean element)
        {
            if (element == null || !element.Value.HasValue)
            {
                return(null);
            }

            var values = new List <IndexValue>();

            values.Add(new IndexValue("code", element.Value.Value ? new StringValue("true") : new StringValue("false")));

            return(ListOf(new CompositeValue(values)));

            //TODO: Include implied system: http://hl7.org/fhir/special-values ?
        }
コード例 #23
0
        public void Test_FhirBoolean_TokenIndexSetter_No_Code_Set_As_Null()
        {
            //Arrange
            var FhirBoolean = new FhirBoolean();

            FhirBoolean.Value = null;

            TokenIndex Index = new TokenIndex();

            //Act
            Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(FhirBoolean, Index) as TokenIndex;

            //Assert
            Assert.IsNull(Index);
        }
コード例 #24
0
        public void ParsePrimitiveWithIllegalAttribute()
        {
            string      xmlString = "<someBoolean xmlns='http://hl7.org/fhir' value='true' unknownattr='yes' />";
            ErrorList   errors    = new ErrorList();
            FhirBoolean result    = (FhirBoolean)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count == 1);
            Assert.IsTrue(errors[0].Message.Contains("unknownattr"));

            string jsonString = "{\"someBoolean\": { \"value\" : true, \"unknownattr\" : \"yes\" } }";

            errors.Clear();
            result = (FhirBoolean)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count == 1);
            Assert.IsTrue(errors[0].Message.Contains("unknownattr"));
        }
コード例 #25
0
        public static bool IsFragment(this StructureDefinition sDef)
        {
            Extension e = sDef.GetExtension(PreFhirGenerator.IsFragmentUrl);

            if (e == null)
            {
                return(false);
            }
            FhirBoolean b = (FhirBoolean)e.Value;

            if (b.Value.HasValue == false)
            {
                return(false);
            }
            return(b.Value.Value);
        }
コード例 #26
0
        /// <summary>
        /// Parse boolean
        /// </summary>
        public static Hl7.Fhir.Model.FhirBoolean ParseFhirBoolean(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FhirBoolean existingInstance = null)
        {
            Hl7.Fhir.Model.FhirBoolean result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FhirBoolean();
            string currentElementName         = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element value
                else if (atName == "value")
                {
                    result.Value = FhirBoolean.Parse(reader.ReadPrimitiveContents(typeof(FhirBoolean))).Value;
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
コード例 #27
0
        public void Test_FhirBoolean_TokenIndexSetter_GoodFormatFalse()
        {
            //Arrange
            bool TheCode = false;

            var Code = new FhirBoolean();

            Code.Value = TheCode;

            TokenIndex Index = new TokenIndex();

            //Act
            Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex;

            //Assert
            Assert.AreEqual(Index.Code, "false");
            Assert.IsNull(Index.System);
        }
コード例 #28
0
        public void ParsePrimitive()
        {
            string      xmlString = "<someBoolean xmlns='http://hl7.org/fhir' value='true' id='3141' />";
            ErrorList   errors    = new ErrorList();
            FhirBoolean result    = (FhirBoolean)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count == 0, errors.ToString());
            Assert.AreEqual(true, result.Value);
            Assert.AreEqual("3141", result.Id.ToString());

            string jsonString = "{\"someBoolean\": { \"value\" : true, \"_id\" : \"3141\" } }";

            errors.Clear();
            result = (FhirBoolean)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count == 0, errors.ToString());
            Assert.AreEqual(true, result.Value);
            Assert.AreEqual("3141", result.Id.ToString());
        }
コード例 #29
0
        public void TestAnnotationsEnumType()
        {
            FhirBoolean data = new FhirBoolean(true);

            data.SetAnnotation(SummaryType.True);

            var copied = (FhirBoolean)data.DeepCopy();

            Assert.AreEqual(SummaryType.True, copied.Annotation <SummaryType>());

            copied.SetAnnotation(SummaryType.Text);
            Assert.AreEqual(SummaryType.Text, copied.Annotation <SummaryType>());

            Assert.IsTrue(copied.HasAnnotation <SummaryType>());

            copied.RemoveAnnotations <SummaryType>();

            Assert.IsFalse(copied.HasAnnotation <SummaryType>());
        }
コード例 #30
0
        public IψParameterElement Create(
            ItIndexElement tIndexElement,
            FhirBoolean value)
        {
            IψParameterElement parameterElement = null;

            try
            {
                parameterElement = new ψParameterElement(
                    tIndexElement,
                    value);
            }
            catch (Exception exception)
            {
                this.Log.Error(
                    exception.Message,
                    exception);
            }

            return(parameterElement);
        }