public void GivenAValidPartialDateTime_WhenToStringIsCalled_ThenCorrectStringShouldBeReturned(string input, string expected) { PartialDateTime dateTime = PartialDateTime.Parse(input); Assert.NotNull(dateTime); Assert.Equal(expected, dateTime.ToString()); }
private static string convertToXmlString(object value) { return(value switch { bool bl => XmlConvert.ToString(bl), Byte by => XmlConvert.ToString(by), // Not used in FHIR serialization Char cr => XmlConvert.ToString(cr), // Not used in FHIR serialization DateTime dt => XmlConvert.ToString(dt, FMT_FULL), // Obsolete: use DateTimeOffset instead!! decimal dec => XmlConvert.ToString(dec), Double dbl => XmlConvert.ToString(dbl), Int16 i16 => XmlConvert.ToString(i16), Int32 i32 => XmlConvert.ToString(i32), Int64 i64 => XmlConvert.ToString(i64), // Not used in FHIR serialization SByte sb => XmlConvert.ToString(sb), // Not used in FHIR serialization Single sing => XmlConvert.ToString(sing), // Not used in FHIR serialization UInt16 uint16 => XmlConvert.ToString(uint16), // Not used in FHIR serialization UInt32 uint32 => XmlConvert.ToString(uint32), // Not used in FHIR serialization UInt64 uint64 => XmlConvert.ToString(uint64), // Not used in FHIR serialization byte[] barr => System.Convert.ToBase64String(barr), DateTimeOffset dto => XmlConvert.ToString(dto, FMT_FULL), Uri uri => uri.ToString(), PartialDateTime pdt => pdt.ToString(), PartialTime pt => pt.ToString(), PartialDate pd => pd.ToString(), Enum en => en.GetLiteral(), BigInteger bi => bi.ToString(), Quantity q => q.ToString(), _ => throw Error.NotSupported($"Cannot convert '{value.GetType().Name}' value '{value}' to string"), });
public void GivenACulture_WhenToStringisCalled_ThenCorrectStringShouldBeReturned(string culture, string input, string expected) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture); PartialDateTime dateTime = PartialDateTime.Parse(input); Assert.NotNull(dateTime); Assert.Equal(expected, dateTime.ToString()); }
/// <inheritdoc /> public override string ToString() { if (_originalDate != null) { return(_originalDate.ToString()); } return($"{Start.ToString("o")}-{End.ToString("o")}"); }
public async Task <ResourceElement> SearchHistoryAsync( string resourceType, string resourceId, PartialDateTime at, PartialDateTime since, PartialDateTime before, int?count, string continuationToken, CancellationToken cancellationToken) { var queryParameters = new List <Tuple <string, string> >(); if (at != null) { if (since != null) { // _at and _since cannot be both specified. throw new InvalidSearchOperationException( string.Format( CultureInfo.InvariantCulture, Core.Resources.AtCannotBeSpecifiedWithBeforeOrSince, KnownQueryParameterNames.At, KnownQueryParameterNames.Since)); } if (before != null) { // _at and _since cannot be both specified. throw new InvalidSearchOperationException( string.Format( CultureInfo.InvariantCulture, Core.Resources.AtCannotBeSpecifiedWithBeforeOrSince, KnownQueryParameterNames.At, KnownQueryParameterNames.Before)); } } if (before != null) { var beforeOffset = before.ToDateTimeOffset( defaultMonth: 1, defaultDaySelector: (year, month) => 1, defaultHour: 0, defaultMinute: 0, defaultSecond: 0, defaultFraction: 0.0000000m, defaultUtcOffset: TimeSpan.Zero).ToUniversalTime(); if (beforeOffset.CompareTo(Clock.UtcNow) > 0) { // you cannot specify a value for _before in the future throw new InvalidSearchOperationException( string.Format( CultureInfo.InvariantCulture, Core.Resources.HistoryParameterBeforeCannotBeFuture, KnownQueryParameterNames.Before)); } } bool searchByResourceId = !string.IsNullOrEmpty(resourceId); if (searchByResourceId) { queryParameters.Add(Tuple.Create(SearchParameterNames.Id, resourceId)); } if (!string.IsNullOrEmpty(continuationToken)) { queryParameters.Add(Tuple.Create(KnownQueryParameterNames.ContinuationToken, continuationToken)); } if (at != null) { queryParameters.Add(Tuple.Create(SearchParameterNames.LastUpdated, at.ToString())); } else { if (since != null) { queryParameters.Add(Tuple.Create(SearchParameterNames.LastUpdated, $"ge{since}")); } if (before != null) { queryParameters.Add(Tuple.Create(SearchParameterNames.LastUpdated, $"lt{before}")); } } if (count.HasValue && count > 0) { queryParameters.Add(Tuple.Create(KnownQueryParameterNames.Count, count.ToString())); } SearchOptions searchOptions = !string.IsNullOrEmpty(resourceType) ? _searchOptionsFactory.Create(resourceType, queryParameters) : _searchOptionsFactory.Create(queryParameters); SearchResult searchResult = await SearchHistoryInternalAsync(searchOptions, cancellationToken); // If no results are returned from the _history search // determine if the resource actually exists or if the results were just filtered out. // The 'deleted' state has no effect because history will return deleted resources if (searchByResourceId && searchResult.Results.Any() == false) { var resource = await _fhirDataStore.GetAsync(new ResourceKey(resourceType, resourceId), cancellationToken); if (resource == null) { throw new ResourceNotFoundException(string.Format(Core.Resources.ResourceNotFoundById, resourceType, resourceId)); } } return(_bundleFactory.CreateHistoryBundle( unsupportedSearchParams: null, result: searchResult)); }
public async Task <Bundle> SearchHistoryAsync( string resourceType, string resourceId, PartialDateTime at, PartialDateTime since, int?count, string continuationToken, CancellationToken cancellationToken) { var queryParameters = new List <Tuple <string, string> >(); if (at != null && since != null) { // _at and _since cannot be both specified. throw new InvalidSearchOperationException( string.Format( CultureInfo.InvariantCulture, Core.Resources.AtAndSinceCannotBeBothSpecified, KnownQueryParameterNames.At, KnownQueryParameterNames.Since)); } bool searchByResourceId = !string.IsNullOrEmpty(resourceId); if (searchByResourceId) { queryParameters.Add(Tuple.Create(SearchParameterNames.Id, resourceId)); } if (!string.IsNullOrEmpty(continuationToken)) { queryParameters.Add(Tuple.Create(KnownQueryParameterNames.ContinuationToken, continuationToken)); } if (at != null) { queryParameters.Add(Tuple.Create(SearchParameterNames.LastUpdated, at.ToString())); } else if (since != null) { queryParameters.Add(Tuple.Create(SearchParameterNames.LastUpdated, $"ge{since}")); } if (count.HasValue && count > 0) { queryParameters.Add(Tuple.Create(KnownQueryParameterNames.Count, count.ToString())); } SearchOptions searchOptions = !string.IsNullOrEmpty(resourceType) ? _searchOptionsFactory.Create(resourceType, queryParameters) : _searchOptionsFactory.Create(queryParameters); SearchResult searchResult = await SearchHistoryInternalAsync(searchOptions, cancellationToken); // If no results are returned from the _history search // determine if the resource actually exists or if the results were just filtered out. // The 'deleted' state has no effect because history will return deleted resources if (searchByResourceId && searchResult.Results.Any() == false) { var resource = await _dataStore.GetAsync(new ResourceKey(resourceType, resourceId), cancellationToken); if (resource == null) { throw new ResourceNotFoundException(string.Format(Core.Resources.ResourceNotFoundById, resourceType, resourceId)); } } return(_bundleFactory.CreateHistoryBundle( unsupportedSearchParams: null, result: searchResult)); }