private static ExpressionStarter <ResCurrentType> Equals(ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewLastUpdatedPredicate, SearchParameterDateTimeValue SearchValue) { var ExpressionLow = Search.LastUpdatedPropertyGreaterThanOrEqualTo(SearchValue.Value); var ExpressionHigh = Search.LastUpdatedPropertyLessThanOrEqualTo(FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); var Expression = ExpressionLow.And(ExpressionHigh); NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(Expression); return(NewLastUpdatedPredicate); }
public override bool TryParseValue(string Values) { this.ValueList = new List <SearchParameterDateTimeValue>(); foreach (string Value in Values.Split(OrDelimiter)) { var DtoSearchParameterDateTimeValue = new SearchParameterDateTimeValue(); if (this.Modifier.HasValue && this.Modifier == SearchParameter.SearchModifierCode.Missing) { bool?IsMissing = DtoSearchParameterDateTimeValue.ParseModifierEqualToMissing(Value); if (IsMissing.HasValue) { DtoSearchParameterDateTimeValue.IsMissing = IsMissing.Value; ValueList.Add(DtoSearchParameterDateTimeValue); } else { this.InvalidMessage = $"Found the {Hl7.Fhir.Model.SearchParameter.SearchModifierCode.Missing.GetPyroLiteral()} Modifier yet is value was expected to be true or false yet found '{Value}'. "; return(false); } } else { var DateTimeStirng = DtoSearchParameterDateTimeValue.ParsePrefix(Value); FhirDateTimeSupport FhirDateTimeSupport = new FhirDateTimeSupport(DateTimeStirng.Trim()); if (FhirDateTimeSupport.IsValid) { if (FhirDateTimeSupport.Value.HasValue) { DtoSearchParameterDateTimeValue.Value = FhirDateTimeSupport.Value.Value; DtoSearchParameterDateTimeValue.Precision = FhirDateTimeSupport.Precision; ValueList.Add(DtoSearchParameterDateTimeValue); } else { return(false); } } else { this.InvalidMessage = $"Unable to parse the provided value of {DateTimeStirng.Trim()} as a FHIR DateTime."; return(false); } } } if (ValueList.Count > 1) { this.HasLogicalOrProperties = true; } if (this.ValueList.Count == 0) { return(false); } else { return(true); } }
public override bool TryParseValue(string Values) { this.ValueList = new List <SearchParameterDateTimeValue>(); foreach (string Value in Values.Split(OrDelimiter)) { var DtoSearchParameterDateTimeValue = new SearchParameterDateTimeValue(); if (this.Modifier.HasValue && this.Modifier == SearchParameter.SearchModifierCode.Missing) { bool?IsMissing = DtoSearchParameterDateTimeValue.ParseModifierEqualToMissing(Value); if (IsMissing.HasValue) { DtoSearchParameterDateTimeValue.IsMissing = IsMissing.Value; ValueList.Add(DtoSearchParameterDateTimeValue); } else { return(false); } } else { var DateTimeStirng = DtoSearchParameterDateTimeValue.ParsePrefix(Value); FhirDateTimeSupport FhirDateTimeSupport = new FhirDateTimeSupport(DateTimeStirng.Trim()); if (FhirDateTimeSupport.IsValid) { if (FhirDateTimeSupport.Value.HasValue) { DtoSearchParameterDateTimeValue.Value = FhirDateTimeSupport.Value.Value; DtoSearchParameterDateTimeValue.Precision = FhirDateTimeSupport.Precision; ValueList.Add(DtoSearchParameterDateTimeValue); } else { return(false); } } else { return(false); } } } if (ValueList.Count > 1) { this.HasLogicalOrProperties = true; } if (this.ValueList.Count == 0) { return(false); } else { return(true); } }
public void Test_FhirDateTimeTo_DateTimeOffset_YearMonthDayHourMinSecMilli_AndTimeZoneMinus_BadFormat() { //Arrange string FhirDateTime = "1974-12-25T12:35:70.123-03:00"; DateTimeOffset Expected = new DateTimeOffset(1974, 12, 25, 12, 35, 15, 123, new TimeSpan(-3, 0, 0)); //Act FhirDateTimeSupport Result = new FhirDateTimeSupport(FhirDateTime); //Assert Assert.IsFalse(Result.Value.HasValue); Assert.IsFalse(Result.IsValid); }
public void Test_FhirDateTimeTo_DateTimeOffset_YearMonthDay_BadFormat() { //Arrange string FhirDateTime = "1974-12-38"; DateTimeOffset Expected = new DateTimeOffset(1974, 12, 25, 0, 0, 0, TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)); //Act FhirDateTimeSupport Result = new FhirDateTimeSupport(FhirDateTime); //Assert Assert.IsFalse(Result.Value.HasValue); Assert.IsFalse(Result.IsValid); }
public void Test_FhirDateTimeTo_DateTimeOffset_YearMonthDayHourMin_TimeZone() { //Arrange string FhirDateTime = "1974-12-25T12:35-04:00"; DateTimeOffset Expected = new DateTimeOffset(1974, 12, 25, 12, 35, 0, new TimeSpan(-4, 0, 0)).ToUniversalTime(); //Act FhirDateTimeSupport Result = new FhirDateTimeSupport(FhirDateTime); //Assert Assert.AreEqual(Expected, Result.Value); Assert.IsTrue(Result.IsValid); Assert.AreEqual(FhirDateTimeSupport.DateTimePrecision.HourMin, Result.Precision); }
public void Test_FhirDateTimeTo_DateTimeOffset_YearMonthDayHourMinSec() { //Arrange string FhirDateTime = "1974-12-25T12:35:15"; DateTimeOffset Expected = new DateTimeOffset(1974, 12, 25, 12, 35, 15, TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)); //Act FhirDateTimeSupport Result = new FhirDateTimeSupport(FhirDateTime); //Assert Assert.AreEqual(Expected, Result.Value); Assert.IsTrue(Result.IsValid); Assert.AreEqual(FhirDateTimeSupport.DateTimePrecision.Sec, Result.Precision); }
public void Test_FhirDateTimeTo_DateTimeOffset_Month() { //Arrange string FhirDateTime = "1974-09"; DateTimeOffset Expected = new DateTimeOffset(1974, 9, 1, 0, 0, 0, TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)).ToUniversalTime(); //Act FhirDateTimeSupport Result = new FhirDateTimeSupport(FhirDateTime); //Assert Assert.AreEqual(Expected, Result.Value); Assert.IsTrue(Result.IsValid); Assert.AreEqual(FhirDateTimeSupport.DateTimePrecision.Month, Result.Precision); }
public void Test_FhirDateTimeTo_DateTimeOffset_YearMonthDayHourMinSecMilli_AndTimeZoneMinus() { //Arrange string FhirDateTime = "1974-12-25T12:35:15.123-03:00"; DateTimeOffset Expected = new DateTimeOffset(1974, 12, 25, 12, 35, 15, 123, new TimeSpan(-3, 0, 0)); //Act FhirDateTimeSupport Result = new FhirDateTimeSupport(FhirDateTime); //Assert Assert.AreEqual(Expected, Result.Value); Assert.IsTrue(Result.IsValid); Assert.AreEqual(FhirDateTimeSupport.DateTimePrecision.MilliSec, Result.Precision); }
public static void Build(List <ISearchParameterBase> SearchParametersList, ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> MainPredicate) { var LastUpdatedSearchParamerterList = SearchParametersList.Where(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_lastUpdated"); if (LastUpdatedSearchParamerterList != null) { ExpressionStarter <ResCurrentType> NewLastUpdatedPredicate = null; foreach (var LastUpdatedSearchParameter in LastUpdatedSearchParamerterList) { if (LastUpdatedSearchParameter is SearchParameterDateTime SearchTypeToken) { NewLastUpdatedPredicate = LinqKit.PredicateBuilder.New <ResCurrentType>(); foreach (var SearchValue in SearchTypeToken.ValueList) { if (!SearchTypeToken.Modifier.HasValue) { if (SearchValue.Prefix.HasValue == false) { NewLastUpdatedPredicate = Equals(Search, NewLastUpdatedPredicate, SearchValue); } else { switch (SearchValue.Prefix) { case SearchParameter.SearchComparator.Eq: NewLastUpdatedPredicate = Equals(Search, NewLastUpdatedPredicate, SearchValue); break; case SearchParameter.SearchComparator.Ne: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated."); case SearchParameter.SearchComparator.Gt: var ExpressionGreaterThan = Search.LastUpdatedPropertyGreaterThan(FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionGreaterThan); break; case SearchParameter.SearchComparator.Lt: var ExpressionLessThan = Search.LastUpdatedPropertyLessThan(SearchValue.Value); NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionLessThan); break; case SearchParameter.SearchComparator.Ge: var ExpressionGreaterThanOrEqualTo = Search.LastUpdatedPropertyGreaterThanOrEqualTo(SearchValue.Value); NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionGreaterThanOrEqualTo); break; case SearchParameter.SearchComparator.Le: var ExpressionLessThanOrEqualTo = Search.LastUpdatedPropertyLessThanOrEqualTo(FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(ExpressionLessThanOrEqualTo); break; case SearchParameter.SearchComparator.Sa: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated."); case SearchParameter.SearchComparator.Eb: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated."); case SearchParameter.SearchComparator.Ap: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter _lastUpdated."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchValue.Prefix.Value.GetLiteral(), (int)SearchValue.Prefix, typeof(SearchParameter.SearchComparator)); } } } else { throw new FormatException($"The search Modifiers are not supported for search parameter _lastUpdated. Found modifier {SearchTypeToken.Modifier.Value.GetLiteral()}"); } } } MainPredicate.Extend <ResCurrentType>(NewLastUpdatedPredicate, PredicateOperator.And); } SearchParametersList.RemoveAll(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_lastUpdated"); } }
public static ExpressionStarter <ResCurrentType> Build(ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterBase SearchItem) { if (SearchItem is SearchParameterDateTime) { var SearchTypeDateTime = SearchItem as SearchParameterDateTime; foreach (var SearchValue in SearchTypeDateTime.ValueList) { if (SearchTypeDateTime.Modifier.HasValue == false) { if (SearchValue.Prefix.HasValue == false) { NewPredicate = CollectionEqualToPredicate(Search, NewPredicate, SearchTypeDateTime, SearchValue); } else { switch (SearchValue.Prefix) { case SearchParameter.SearchComparator.Eq: NewPredicate = CollectionEqualToPredicate(Search, NewPredicate, SearchTypeDateTime, SearchValue); break; case SearchParameter.SearchComparator.Ne: NewPredicate = CollectionNotEqualToPredicate(Search, NewPredicate, SearchTypeDateTime, SearchValue); break; case SearchParameter.SearchComparator.Gt: NewPredicate = NewPredicate.Or(Search.DateTimePeriodCollectionGreaterThan(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision))); break; case SearchParameter.SearchComparator.Lt: NewPredicate = NewPredicate.Or(Search.DateTimePeriodCollectionLessThan(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision))); break; case SearchParameter.SearchComparator.Ge: NewPredicate = NewPredicate.Or(Search.DateTimePeriodCollectionGreaterThanOrEqualTo(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision))); break; case SearchParameter.SearchComparator.Le: NewPredicate = NewPredicate.Or(Search.DateTimePeriodCollectionLessThanOrEqualTo(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision))); break; case SearchParameter.SearchComparator.Sa: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime."); case SearchParameter.SearchComparator.Eb: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime."); case SearchParameter.SearchComparator.Ap: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchValue.Prefix.Value.GetLiteral(), (int)SearchValue.Prefix, typeof(SearchParameter.SearchComparator)); } } } else { switch (SearchTypeDateTime.Modifier.Value) { case SearchParameter.SearchModifierCode.Missing: if (SearchValue.Prefix.HasValue == false) { if (SearchValue.IsMissing) { NewPredicate = NewPredicate.Or(Search.SearchParameterIsNull <ResIndexDateTimeType>(SearchTypeDateTime.Id)); } else { NewPredicate = NewPredicate.Or(Search.SearchParameterIdIsNotNull <ResIndexDateTimeType>(SearchTypeDateTime.Id)); } } else { switch (SearchValue.Prefix) { case SearchParameter.SearchComparator.Eq: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Ne: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Gt: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Lt: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Ge: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Le: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Sa: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Eb: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); case SearchParameter.SearchComparator.Ap: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of FhirDateTime with a Modifier of: {SearchTypeDateTime.Modifier.ToString()}."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchValue.Prefix.Value.GetLiteral(), (int)SearchValue.Prefix, typeof(SearchParameter.SearchComparator)); } //break; } break; case SearchParameter.SearchModifierCode.Exact: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Contains: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Text: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Type: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Below: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Above: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.In: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.NotIn: throw new FormatException($"The search modifier: {SearchTypeDateTime.Modifier.ToString()} is not supported for search parameter types of date."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchTypeDateTime.Modifier.Value.GetLiteral(), (int)SearchTypeDateTime.Modifier, typeof(SearchParameter.SearchModifierCode)); } } } } return(NewPredicate); }
private static ExpressionStarter <ResCurrentType> CollectionNotEqualToPredicate(ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterDateTime SearchTypeDateTime, SearchParameterDateTimeValue SearchValue) { var NotEqualToExpression = Search.DateTimePeriodCollectionAnyNotEqualTo(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); var CollectionIsNullExpression = Search.SearchParameterIsNull <ResIndexDateTimeType>(SearchTypeDateTime.Id); NewPredicate = NewPredicate.Or(NotEqualToExpression); NewPredicate = NewPredicate.Or(CollectionIsNullExpression); return(NewPredicate); }
private static ExpressionStarter <IResourceIndexed> CollectionNotEqualToPredicate(Search <IResourceIndexed> Search, ExpressionStarter <IResourceIndexed> NewPredicate, SearchParameterDateTime SearchTypeDateTime, SearchParameterDateTimeValue SearchValue) { var NotEqualToExpression = Search.DateTimePeriodCollectionAnyNotEqualTo(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); var CollectionIsNullExpression = Search.SearchParameterIsNull <Index.IDateTimeIndex>(SearchTypeDateTime.Id); NewPredicate = NewPredicate.Or(NotEqualToExpression); NewPredicate = NewPredicate.Or(CollectionIsNullExpression); return(NewPredicate); }