private void SetSearchParameterValueList(IEnumerable <string> FhirIdList, string ReferanceResourceName, ISearchParameterBase SearchParameterBase) { if (SearchParameterBase is SearchParameterReferance Referance) { Referance.ValueList = new List <SearchParameterReferanceValue>(); //This adds each FhirId as an 'OR' for the search. foreach (string FhirId in FhirIdList) { var FhirUri = IPyroFhirUriFactory.CreateFhirRequestUri(); if (FhirUri.Parse($"{ReferanceResourceName}/{FhirId}")) { Referance.ValueList.Add(new SearchParameterReferanceValue() { FhirRequestUri = FhirUri, IsMissing = false }); } else { throw new Exception($"Server Error: can not parse server constructed FHIR URI of '{Referance.ChainedSearchParameterList[0].Resource}/{FhirId}'"); } } } else { throw new Exception($"Server Error: Cannot cast Chained search parameter as expected to SearchParameterReferance, type was {SearchParameterBase.GetType().ToString()}"); } }
private bool PostProcessing(Bundle.EntryComponent PostEntry, int PostEntryIndex) { IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set(PostEntry.Request); if (RequestMeta.PyroRequestUri.FhirRequestUri.IsOperation) { var Message = $"The FHIR server does not support the use of Operations within Transaction Bundles, found Operation request type of : '{RequestMeta.PyroRequestUri.FhirRequestUri.OperationName}'."; var OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, Message); _ServiceOperationOutcome.ResourceResult = OpOutcome; _ServiceOperationOutcome.HttpStatusCode = System.Net.HttpStatusCode.Forbidden; _ServiceOperationOutcome.OperationType = Enum.RestEnum.CrudOperationType.Create; return(false); } IPyroFhirUri ResourceIdToForce = IPyroFhirUriFactory.CreateFhirRequestUri(); if (String.IsNullOrEmpty(PostEntry.FullUrl)) { //Assgin a new GUID as there is not FullURL GUID to lookup from refererancing ResourceIdToForce.Parse($"{PostEntry.Resource.TypeName}/{Common.Tools.FhirGuid.FhirGuid.NewFhirGuid()}"); } else { //Use the new Resource id that we assigned when updating all referances by looking it up in the GetUUIDfromFullURL dic ResourceIdToForce.Parse(OldNewResourceReferanceMap[GetUUIDfromFullURL(PostEntry.FullUrl)]); } //Remove the Resource Id in the resource as this is a POST and no id should be present in the resource, we do force the new id given this is a transaction operation if (!String.IsNullOrEmpty(PostEntry.Resource.Id)) { PostEntry.Resource.Id = String.Empty; } IResourceServiceOutcome ResourceServiceOutcome = IResourceServices.Post(PostEntry.Resource, RequestMeta, ResourceIdToForce.ResourceId); if (ResourceServiceOutcome.SuccessfulTransaction) { PostEntry.FullUrl = CreateFullUrl(ResourceServiceOutcome); PostEntry.Response = new Bundle.ResponseComponent(); PostEntry.Response.Status = FormatHTTPStatusCodeAsString(ResourceServiceOutcome.HttpStatusCode); if (ResourceServiceOutcome.ResourceResult != null) { if (ResourceServiceOutcome.ResourceResult.ResourceType == ResourceType.OperationOutcome) { PostEntry.Response.Outcome = ResourceServiceOutcome.ResourceResult; } else { PostEntry.Resource = ResourceServiceOutcome.ResourceResult; } } if (ResourceServiceOutcome.LastModified != null) { PostEntry.Response.Etag = HttpHeaderSupport.GetEntityTagHeaderValueFromVersion(ResourceServiceOutcome.ResourceVersionNumber).ToString(); PostEntry.Response.LastModified = ResourceServiceOutcome.LastModified; } PostEntry.Response.Status = $"{((int)ResourceServiceOutcome.HttpStatusCode).ToString()} {ResourceServiceOutcome.HttpStatusCode.ToString()}"; PostEntry.Response.Location = FormatResponseLocation(ResourceServiceOutcome.RequestUri.OriginalString, ResourceServiceOutcome.FhirResourceId, ResourceServiceOutcome.ResourceVersionNumber); return(true); } else { if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is OperationOutcome Op) { IdentifieBatchEntityToClient(Op, PostEntry.FullUrl, "POST", PostEntryIndex); } _ServiceOperationOutcome = ResourceServiceOutcome; return(false); } }
public override bool TryParseValue(string Values) { this.ValueList = new List <SearchParameterReferanceValue>(); foreach (string Value in Values.Split(OrDelimiter)) { var DtoSearchParameterReferanceValue = new SearchParameterReferanceValue(); if (this.Modifier.HasValue && this.Modifier == Hl7.Fhir.Model.SearchParameter.SearchModifierCode.Missing) { bool?IsMissing = DtoSearchParameterReferanceValue.ParseModifierEqualToMissing(Value); if (IsMissing.HasValue) { DtoSearchParameterReferanceValue.IsMissing = IsMissing.Value; this.ValueList.Add(DtoSearchParameterReferanceValue); } else { return(false); } } else if (!this.IsChained) // If IsChained then there is no value to check { IPyroFhirUri RequestUri = IPyroFhirUriFactory.CreateFhirRequestUri(); if (RequestUri.Parse(Value.Trim())) { DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri; } else if (!string.IsNullOrWhiteSpace(Value.Trim()) && this.Modifier.HasValue && this.Modifier == Hl7.Fhir.Model.SearchParameter.SearchModifierCode.Type && !string.IsNullOrWhiteSpace(this.TypeModifierResource)) { IPyroFhirUri RequestUri2 = IPyroFhirUriFactory.CreateFhirRequestUri(); if (RequestUri2.Parse($"{this.TypeModifierResource}/{Value.Trim()}")) { DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri2; } else { this.InvalidMessage = $"Unable to parse the Resource reference search parameter. {RequestUri2.ParseErrorMessage}"; return(false); } } else if (!string.IsNullOrWhiteSpace(Value.Trim()) && this.AllowedReferanceResourceList.Count() == 1) { IPyroFhirUri RequestUri3 = IPyroFhirUriFactory.CreateFhirRequestUri(); if (RequestUri3.Parse($"{this.AllowedReferanceResourceList[0]}/{Value.Trim()}")) { DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri3; } else { this.InvalidMessage = $"The Resource Name was not given as a Type modifier in the reference search parameter and the search parameter supports many Resource types. You must specify the resource name the reference relates to. {RequestUri3.ParseErrorMessage}"; return(false); } } else { this.InvalidMessage = $"The Resource Name was not given as a Type modifier in the reference search parameter and the search parameter supports many Resource types. You must specify the resource name the reference relates to."; return(false); } if (!this.AllowedReferanceResourceList.Contains(DtoSearchParameterReferanceValue.FhirRequestUri.ResourseName)) { this.InvalidMessage = $"The Resource Name used in the reference search parameter is not allowed for this search parameter against this Resource."; return(false); } else { this.ValueList.Add(DtoSearchParameterReferanceValue); } } } if (this.ValueList.Count() > 1) { this.HasLogicalOrProperties = true; } if (this.IsChained || this.ValueList.Count > 0) { return(true); } else { return(false); } }
//public override bool TryParseValueOLD(string Values) //{ // this.ValueList = new List<SearchParameterReferanceValue>(); // foreach (string Value in Values.Split(OrDelimiter)) // { // var DtoSearchParameterReferanceValue = new SearchParameterReferanceValue(); // if (this.Modifier.HasValue && this.Modifier == Hl7.Fhir.Model.SearchParameter.SearchModifierCode.Missing) // { // bool? IsMissing = DtoSearchParameterReferanceValue.ParseModifierEqualToMissing(Value); // if (IsMissing.HasValue) // { // DtoSearchParameterReferanceValue.IsMissing = IsMissing.Value; // this.ValueList.Add(DtoSearchParameterReferanceValue); // } // else // { // return false; // } // } // else if (!this.IsChained) // If IsChained then there is no value to check // { // IPyroFhirUri RequestUri = IPyroFhirUriFactory.CreateFhirRequestUri(); // if (RequestUri.Parse(Value.Trim())) // { // DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri; // } // else if (!string.IsNullOrWhiteSpace(Value.Trim()) && this.Modifier.HasValue && this.Modifier == Hl7.Fhir.Model.SearchParameter.SearchModifierCode.Type && !string.IsNullOrWhiteSpace(this.TypeModifierResource)) // { // IPyroFhirUri RequestUri2 = IPyroFhirUriFactory.CreateFhirRequestUri(); // if (RequestUri2.Parse($"{this.TypeModifierResource}/{Value.Trim()}")) // { // DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri2; // } // else // { // this.InvalidMessage = $"Unable to parse the Resource reference search parameter. {RequestUri2.ParseErrorMessage}"; // return false; // } // } // else if (!string.IsNullOrWhiteSpace(Value.Trim()) && this.AllowedReferanceResourceList.Count() == 1) // { // IPyroFhirUri RequestUri3 = IPyroFhirUriFactory.CreateFhirRequestUri(); // if (RequestUri3.Parse($"{this.AllowedReferanceResourceList[0]}/{Value.Trim()}")) // { // DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri3; // } // else // { // this.InvalidMessage = $"The Resource Name was not given as a Type modifier in the reference search parameter and the search parameter supports many Resource types. You must specify the resource name the reference relates to. {RequestUri3.ParseErrorMessage}"; // return false; // } // } // else // { // this.InvalidMessage = $"The Resource Name was not given as a Type modifier in the reference search parameter and the search parameter supports many Resource types. You must specify the resource name the reference relates to."; // return false; // } // if (!this.AllowedReferanceResourceList.Contains(DtoSearchParameterReferanceValue.FhirRequestUri.ResourseName)) // { // this.InvalidMessage = $"The Resource Name used in the reference search parameter is not allowed for this search parameter against this Resource."; // return false; // } // else // { // this.ValueList.Add(DtoSearchParameterReferanceValue); // } // } // } // if (this.ValueList.Count() > 1) // this.HasLogicalOrProperties = true; // if (this.IsChained || this.ValueList.Count > 0) // { // return true; // } // else // { // return false; // } //} public override bool TryParseValue(string Values) { this.ValueList = new List <SearchParameterReferanceValue>(); foreach (string Value in Values.Split(OrDelimiter)) { var DtoSearchParameterReferanceValue = new SearchParameterReferanceValue(); if (this.Modifier.HasValue && this.Modifier == Hl7.Fhir.Model.SearchParameter.SearchModifierCode.Missing) { bool?IsMissing = DtoSearchParameterReferanceValue.ParseModifierEqualToMissing(Value); if (IsMissing.HasValue) { DtoSearchParameterReferanceValue.IsMissing = IsMissing.Value; this.ValueList.Add(DtoSearchParameterReferanceValue); } 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 if (!this.IsChained) // If IsChained then there is no value to check { IPyroFhirUri RequestUri = IPyroFhirUriFactory.CreateFhirRequestUri(); if (!Value.Contains('/') && !string.IsNullOrWhiteSpace(Value.Trim()) && this.AllowedReferanceResourceList.Count() == 1) { //If only one allowed Resource type then use this string ParseValue = $"{this.AllowedReferanceResourceList[0]}/{Value.Trim()}"; if (RequestUri.Parse(ParseValue)) { DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri; } } else if (RequestUri.Parse(Value.Trim())) { //Most likely an absolute or relative so just parse it DtoSearchParameterReferanceValue.FhirRequestUri = RequestUri; } else { this.InvalidMessage = $"Unable to parse the reference search parameter of: '{Value}'. {RequestUri.ErrorInParseing}"; return(false); } //Check the Resource type we resolved to is allowed for the search parameter if (!string.IsNullOrWhiteSpace(DtoSearchParameterReferanceValue.FhirRequestUri.ResourseName) && !this.AllowedReferanceResourceList.Contains(DtoSearchParameterReferanceValue.FhirRequestUri.ResourseName)) { this.InvalidMessage = $"The Resource Name used in the reference search parameter is not allowed for this search parameter against this Resource."; return(false); } else { this.ValueList.Add(DtoSearchParameterReferanceValue); } } } if (this.ValueList.Count() > 1) { this.HasLogicalOrProperties = true; } if (this.IsChained || this.ValueList.Count > 0) { return(true); } else { return(false); } }