private string ResolveRelativeUriPart(string RequestRelativePath) { if (RequestRelativePath == string.Empty) { return(string.Empty); } string Remainder = string.Empty; var SplitParts = RequestRelativePath.Split('?')[0].Split('/'); foreach (string Segment in SplitParts) { if (Segment.StartsWith("$")) { //It is a base operation this.OperationType = FhirOperationEnum.OperationScope.Base; this.OperationName = Segment.TrimStart('$'); return(RequestRelativePath.Substring(this.OperationName.Count() + 1, RequestRelativePath.Count() - (this.OperationName.Count() + 1))); } else if (Segment.StartsWith("#")) { //It is a contained referance with out a resource name e.g (#123456) and not (Patient/#123456) this.IsContained = true; this.IsRelativeToServer = false; this.ResourceId = Segment.TrimStart('#'); return(RequestRelativePath.Substring(this.ResourceId.Count() + 1, RequestRelativePath.Count() - (this.ResourceId.Count() + 1))); } else if (Segment.ToLower() == _MetadataName) { //This is a metadata request this.IsMetaData = true; Remainder = RequestRelativePath.Substring(_MetadataName.Count(), RequestRelativePath.Count() - _MetadataName.Count()); return(RemoveStartsWithSlash(Remainder)); } else if (SplitParts.Count() > 1 || this.OriginalString.Contains('/')) { //This is a Resource referance where Patient/123456 this.ResourseName = Segment; this.ResourceType = ResourceNameResolutionSupport.GetResourceType(this.ResourseName); Remainder = RequestRelativePath.Substring(this.ResourseName.Count(), RequestRelativePath.Count() - this.ResourseName.Count()); return(RemoveStartsWithSlash(Remainder)); } else if (SplitParts.Count() == 1) { return(Segment); } } ParseErrorMessage = $"The URI has no Resource or metadata or $Operation or #Contained segment. Found invalid segment: {RequestRelativePath} in URL {this.OriginalString}"; ErrorInParseing = true; return(string.Empty); }
private string ResolveResourceIdPart(string value) { string Remainder = value; if (value == string.Empty) { return(value); } else { var Split = value.Split('/'); foreach (string Segment in Split) { if (this.ResourceId == null) { //Resource Id if (Segment.StartsWith("#")) { //Contained Resource #Id this.IsContained = true; this.IsRelativeToServer = false; this.ResourceId = Segment.TrimStart('#'); Remainder = RemoveStartsWithSlash(Remainder.Substring(this.ResourceId.Count() + 1, Remainder.Count() - (this.ResourceId.Count() + 1))); } else if (Segment.ToLower() == _SearchFormDataName) { //Search Form Data this.IsFormDataSearch = true; Remainder = RemoveStartsWithSlash(Remainder.Substring(_SearchFormDataName.Count(), Remainder.Count() - _SearchFormDataName.Count())); //Must not be anything after _search, the search parameters are in the body. break; } else if (!this.IsOperation && Segment.StartsWith("$")) { //A Resource $operation e.g (base/Patient/$operation) this.OperationType = FhirOperationEnum.OperationScope.Resource; this.OperationName = Segment.TrimStart('$'); Remainder = RemoveStartsWithSlash(Remainder.Substring(this.OperationName.Count() + 1, Remainder.Count() - (this.OperationName.Count() + 1))); return(Remainder); } else { //Normal Resource Id this.ResourceId = Segment; Remainder = RemoveStartsWithSlash(Remainder.Substring(this.ResourceId.Count(), Remainder.Count() - this.ResourceId.Count())); } } else { if (!this.IsOperation && this.ResourceId != null && Segment.StartsWith("$")) { //A Resource Instance $operation e.g (base/Patient/10/$operation) this.OperationType = FhirOperationEnum.OperationScope.Instance; this.OperationName = Segment.TrimStart('$'); Remainder = RemoveStartsWithSlash(Remainder.Substring(this.OperationName.Count() + 1, Remainder.Count() - (this.OperationName.Count() + 1))); return(Remainder); } else if (Segment.ToLower() == _HistoryName) { //History segment e.g (_history) //Is this case iterate over loop again to see is we have a Resource VersionId this.IsHistoryReferance = true; Remainder = RemoveStartsWithSlash(Remainder.Substring(_HistoryName.Count(), Remainder.Count() - _HistoryName.Count())); } else if (this.IsHistoryReferance) { //History version id this.VersionId = Segment; Remainder = RemoveStartsWithSlash(Remainder.Substring(this.VersionId.Count(), Remainder.Count() - this.VersionId.Count())); return(Remainder); } else if (IsResourceTypeString(Segment)) { //Is this a Compartment reference e.g ([base]/Patient/[id]/Condition?code:in=http://hspc.org/ValueSet/acute-concerns) //where 'Patient' is the compartment and 'Condition' is the resource. this.CompartmentalisedResourseName = Segment; this.CompartmentalisedResourseType = ResourceNameResolutionSupport.GetResourceType(this.ResourseName); this.IsCompartment = true; Remainder = RemoveStartsWithSlash(Remainder.Substring(this.CompartmentalisedResourseName.Count(), Remainder.Count() - this.CompartmentalisedResourseName.Count())); return(Remainder); } } } return(Remainder); } }
private string ResolveRelativeUriPart(string RequestRelativePath) { if (RequestRelativePath == string.Empty) { return(string.Empty); } string Remainder = string.Empty; var SplitParts = RequestRelativePath.Split('?')[0].Split('/'); foreach (string Segment in SplitParts) { if (Segment.StartsWith("$")) { //It is a base operation this.OperationType = FhirOperationEnum.OperationScope.Base; this.OperationName = Segment.TrimStart('$'); return(RequestRelativePath.Substring(this.OperationName.Count() + 1, RequestRelativePath.Count() - (this.OperationName.Count() + 1))); } else if (Segment.StartsWith("#")) { //It is a contained referance with out a resource name e.g (#123456) and not (Patient/#123456) this.IsContained = true; this.IsRelativeToServer = false; this.ResourceId = Segment.TrimStart('#'); return(RequestRelativePath.Substring(this.ResourceId.Count() + 1, RequestRelativePath.Count() - (this.ResourceId.Count() + 1))); } else if (Segment.ToLower() == _MetadataName) { //This is a metadata request this.IsMetaData = true; Remainder = RequestRelativePath.Substring(_MetadataName.Count(), RequestRelativePath.Count() - _MetadataName.Count()); return(RemoveStartsWithSlash(Remainder)); } else { //This is a Resource referance this.ResourseName = Segment; this.ResourceType = ResourceNameResolutionSupport.GetResourceType(this.ResourseName); Remainder = RequestRelativePath.Substring(this.ResourseName.Count(), RequestRelativePath.Count() - this.ResourseName.Count()); return(RemoveStartsWithSlash(Remainder)); //Changed this to above which only calls 'ResourceNameResolutionSupport.GetResourceType' //which will throw an exception if not a Resource type, that exception also //provides detailed user info about the failure. //if (IsResourceTypeString(Segment)) //{ // this.ResourseName = Segment; // this.ResourceType = ResourceNameResolutionSupport.GetResourceType(this.ResourseName); // Remainder = RequestRelativePath.Substring(this.ResourseName.Count(), RequestRelativePath.Count() - this.ResourseName.Count()); // return RemoveStartsWithSlash(Remainder); //} //else //{ // ParseErrorMessage = $"The URI has no Resource or metadata or $Operation or #Contained or Compartment segment or does not begin with http:// or https://. Found invalid segment: {Segment} in URL: {this.OriginalString}"; // ErrorInParseing = true; // return string.Empty; //} } } ParseErrorMessage = $"The URI has no Resource or metadata or $Operation or #Contained segment. Found invalid segment: {RequestRelativePath} in URL {this.OriginalString}"; ErrorInParseing = true; return(string.Empty); }