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(); }
//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()); }
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)); } }