Пример #1
0
        public static void SerializeFhirDateTime(Hl7.Fhir.Model.FhirDateTime value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartComplexContent();

            // Serialize element value
            if (value.Value != null)
            {
                writer.WritePrimitiveContents("value", value, XmlSerializationHint.Attribute);
            }

            // Serialize element _id
            if (value.LocalIdElement != null)
            {
                writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute);
            }

            // Serialize element extension
            if (value.Extension != null && !summary && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach (var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }


            writer.WriteEndComplexContent();
        }
 public string Cast(FhirDateTime dt)
 {
     if (dt != null)
         return dt.Value;
     else
         return null;
 }
Пример #3
0
        public void DateTimeHandling()
        {
            FhirDateTime dt = new FhirDateTime("2010-01-01");
            Assert.AreEqual("2010-01-01", dt.Value);

            FhirDateTime dt2 = new FhirDateTime(1972, 11, 30, 15, 10);
            Assert.IsTrue(dt2.Value.StartsWith("1972-11-30T15:10"));
        }
Пример #4
0
            public static ExpansionComponent Create()
            {
                var expansion = new ExpansionComponent();

                expansion.TimestampElement  = FhirDateTime.Now();
                expansion.IdentifierElement = Uuid.Generate().AsUri();

                return(expansion);
            }
Пример #5
0
 public DateTimeValue(string datetime)
 {
     if (!FhirDateTime.IsValidValue(datetime))
     {
         throw Error.Argument("datetime", "The string [" + datetime + "] cannot be translated to a DateTimeValue");
     }
     var fdt = new FhirDateTime(datetime);
     Value = fdt.ToDateTimeOffset();
 }
Пример #6
0
        private List <Expression> ToExpressions(Hl7.Fhir.Model.Date element)
        {
            if (element == null || String.Empty.Equals(element.Value))
            {
                return(null);
            }

            FhirModel.FhirDateTime fdt = new FhirModel.FhirDateTime(element.Value);
            return(ToExpressions(fdt));
        }
        public void ValidateResourceWithIncorrectChildElement()
        {
            FhirDateTime dt = new FhirDateTime();
            dt.Value = "Ewout Kramer";

            Observation o = new Observation { Applies = dt };
            DiagnosticReport rep = new DiagnosticReport();
            rep.Contained = new List<Resource> { o };

            validateErrorOrFail(rep);
        }
Пример #8
0
        private List <Expression> ToExpressions(FhirModel.Instant element)
        {
            if (element == null || !element.Value.HasValue)
            {
                return(null);
            }

            var fdt = new FhirModel.FhirDateTime(element.Value.Value);

            return(ToExpressions(fdt));
        }
Пример #9
0
        public void DateTimeHandling()
        {
            FhirDateTime dt = new FhirDateTime("2010-01-01");
            Assert.AreEqual("2010-01-01", dt.Value);

            FhirDateTime dt2 = new FhirDateTime(1972, 11, 30, 15, 10);
            Assert.IsTrue(dt2.Value.StartsWith("1972-11-30T15:10"));

            var stamp = new DateTimeOffset(1972, 11, 30, 15, 10, 0, TimeSpan.Zero);
            dt = new FhirDateTime(stamp);
            Assert.IsTrue(dt.Value.EndsWith("+00:00"));
        }
Пример #10
0
        //public static void SaveBody(this HttpRequest request, string contentType, byte[] data)
        //{
        //    Binary b = new Binary { Content = data, ContentType = contentType };

        //    request.Properties.Add(Const.UNPARSED_BODY, b);
        //}

        //public static Binary GetBody(this HttpRequest request)
        //{
        //    if (request.Properties.ContainsKey(Const.UNPARSED_BODY))
        //        return request.Properties[Const.UNPARSED_BODY] as Binary;
        //    else
        //        return null;
        //}



        //public static HttpResponseMessage ResourceResponse(this HttpRequest request, Resource entry, HttpStatusCode? code=null)
        //{
        //    request.SaveEntry(entry);

        //    HttpResponseMessage msg;

        //    if(code != null)
        //        msg = request.CreateResponse<Resource>(code.Value,entry);
        //    else
        //        msg = request.CreateResponse<Resource>(entry);

        //    // msg.Headers.SetFhirTags(entry.Tags);
        //    return msg;
        //}


        //public static HttpResponseMessage StatusResponse(this HttpRequest request, Resource entry, HttpStatusCode code)
        //{
        //    request.SaveEntry(entry);
        //    HttpResponseMessage msg = request.CreateResponse(code);
        //    msg.Headers.Location = entry.ResourceIdentity();
        //    return msg;
        //}

        public static DateTimeOffset?GetDateParameter(this HttpRequest request, string name)
        {
            string param = request.GetParameter(name);

            if (param == null)
            {
                return(null);
            }
            var t = new Hl7.Fhir.Model.FhirDateTime(param);

            return(t.ToDateTimeOffset());
        }
Пример #11
0
        [TestMethod, Ignore] //Server throws error: Access violation at address 000000000129D56C in module 'FHIRServer.exe'. Read of address 0000000000000000
        public void InvokeTestPatientGetEverything()
        {
            var client = new FhirClient(testEndpoint);
            var start = new FhirDateTime(2014,11,1);
            var end = new FhirDateTime(2015,1,1);
            var par = new Parameters().Add("start", start).Add("end", end);
            var bundle = (Bundle)client.InstanceOperation(ResourceIdentity.Build("Patient", "1"), "everything", par);
            Assert.IsTrue(bundle.Entry.Any());

            var bundle2 = client.FetchPatientRecord(ResourceIdentity.Build("Patient","1"), start, end);
            Assert.IsTrue(bundle2.Entry.Any());
        }
Пример #12
0
 public static bool TryParse(string value, out FhirDateTime result)
 {
     if (value == null || Regex.IsMatch(value, "^" + PATTERN + "$", RegexOptions.Singleline))
     {
         result = new FhirDateTime(value);
         return(true);
     }
     else
     {
         result = null;
         return(false);
     }
 }
Пример #13
0
        public static FhirDateTime Parse(string value)
        {
            FhirDateTime result = null;

            if (TryParse(value, out result))
            {
                return(result);
            }
            else
            {
                throw new FhirFormatException("Not a correctly formatted dateTime value");
            }
        }
Пример #14
0
        /// <summary>
        /// { start : lowerbound-of-fhirdatetime, end : upperbound-of-fhirdatetime }
        /// <seealso cref="ToExpressions(Period)"/>, with lower and upper bounds of FhirDateTime as bounds of the Period.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private List <Expression> ToExpressions(FhirModel.FhirDateTime element)
        {
            if (element == null)
            {
                return(null);
            }

            var bounds = new List <IndexValue>();

            bounds.Add(new IndexValue("start", new DateTimeValue(element.LowerBound())));
            bounds.Add(new IndexValue("end", new DateTimeValue(element.UpperBound())));

            return(ListOf(new CompositeValue(bounds)));
        }
        /// <summary>
        /// Parse dateTime
        /// </summary>
        public static Hl7.Fhir.Model.FhirDateTime ParseFhirDateTime(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FhirDateTime existingInstance = null)
        {
            Hl7.Fhir.Model.FhirDateTime result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FhirDateTime();
            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 = FhirDateTime.Parse(reader.ReadPrimitiveContents(typeof(FhirDateTime))).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);
        }
Пример #16
0
 public static bool TryParse(string value, out FhirDateTime result)
 {
     if (value==null || Regex.IsMatch(value, "^" + PATTERN + "$", RegexOptions.Singleline ) )
     {
         result = new FhirDateTime(value);
         return true;
     }
     else
     {
         result = null;
         return false;
     }
 }
Пример #17
0
        private static IMongoQuery DateQuery(String parameterName, Operator optor, String modifier, ValueExpression operand)
        {
            if (optor == Operator.IN)
            {
                IEnumerable<ValueExpression> opMultiple = ((ChoiceValue)operand).Choices;
                return M.Query.Or(opMultiple.Select(choice => DateQuery(parameterName, Operator.EQ, modifier, choice)));
            }

            string start = parameterName + ".start";
            string end = parameterName + ".end";

            var typedOperand = ((UntypedValue)operand).AsDateValue();
            //            var value = GroomDate(typedOperand.Value);
            var fdtValue = new FhirDateTime(typedOperand.Value);
            var value = BsonDateTime.Create(fdtValue.ToDateTimeOffset());

            switch (optor)
            {
                case Operator.EQ:
                    return
                        M.Query.And(
                            M.Query.Or(M.Query.Exists(start), M.Query.Exists(end)),
                            M.Query.Or(M.Query.LTE(start, value), M.Query.NotExists(start)),
                            M.Query.Or(M.Query.GT(end, value), M.Query.NotExists(end))
                        );
                case Operator.GT:
                    return
                        M.Query.Or(
                            M.Query.GT(parameterName, value),
                            M.Query.GT(start, value)
                        );
                case Operator.GTE:
                    return
                        M.Query.Or(
                            M.Query.GTE(parameterName, value),
                            M.Query.GTE(start, value)
                        );
                case Operator.LT:
                    return
                        M.Query.Or(
                            M.Query.LT(parameterName, value),
                            M.Query.LT(end, value)
                        );
                case Operator.LTE:
                    return
                        M.Query.Or(
                            M.Query.LTE(parameterName, value),
                            M.Query.LTE(end, value)
                        );
                case Operator.ISNULL:
                    return M.Query.EQ(parameterName, null); //We don't use M.Query.NotExists, because that would exclude resources that have this field with an explicit null in it.
                case Operator.NOTNULL:
                    return M.Query.NE(parameterName, null); //We don't use M.Query.Exists, because that would include resources that have this field with an explicit null in it.
                default:
                    throw new ArgumentException(String.Format("Invalid operator {0} on date parameter {1}", optor.ToString(), parameterName));
            }
        }
Пример #18
0
 public Period(FhirDateTime start, FhirDateTime end)
 {
     StartElement = start;
     EndElement   = end;
 }
Пример #19
0
        public void HandleDateTimeParam()
        {
            var p1 = new FhirDateTime(new DateTimeOffset(1972, 11, 30, 15, 20, 49, TimeSpan.Zero));
            Assert.AreEqual("1972-11-30T15:20:49+00:00", p1.Value.ToString());

            var crit = Criterium.Parse("paramX=1972-11-30T18:45:36Z");
            var p3 = ((UntypedValue)crit.Operand).AsDateValue();
            Assert.AreEqual("1972-11-30", p3.Value);

            var p4 = ((UntypedValue)crit.Operand).AsDateTimeValue();
            Assert.AreEqual("1972-11-30T18:45:36Z", p4.Value);
        }
Пример #20
0
        public void ValidateResourceWithIncorrectChildElement()
        {
            // First create an incomplete encounter (class not supplied)
            var enc = new Encounter();
            validateErrorOrFail(enc, membername: "StatusElement");
            validateErrorOrFail(enc,true);  // recursive checking shouldn't matter

            enc.Status = Encounter.EncounterState.Planned;

            // Now, it should work
            DotNetAttributeValidation.Validate(enc);
            DotNetAttributeValidation.Validate(enc, true);  // recursive checking shouldnt matter

            // Hide an incorrect datetime deep into the Encounter
            FhirDateTime dt = new FhirDateTime();
            dt.Value = "Ewout Kramer";  // clearly, a wrong datetime

            enc.Period = new Period() { StartElement = dt };

            // When we do not validate recursively, we should still be ok
            DotNetAttributeValidation.Validate(enc);

            // When we recurse, this should fail
            validateErrorOrFail(enc, true, membername: "Value");
        }
Пример #21
0
        public void ValidateResourceWithIncorrectElement()
        {
            FhirDateTime dt = new FhirDateTime();

            dt.Value = "Ewout Kramer";

            Observation o = new Observation { Applies = dt };
            DiagnosticReport rep = new DiagnosticReport();
            rep.Contained = new List<Resource> { o };

            var errors = dt.Validate();

            Assert.IsTrue(errors.Count == 1);
        }
Пример #22
0
 public void FhirDateTimeMapTest()
 {
     var input = new FhirDateTime(2015, 3, 14);
     var result = sut.Map(input);
     CheckPeriod(result, "2015-03-14T00:00:00+01:00", "2015-03-15T00:00:00+01:00");
 }