public static CodeableConcept ParseCodeableConcept(this IElementNavigator instance) { var newCodeableConcept = new CodeableConcept(); newCodeableConcept.Coding = instance.GetChildrenByName("coding").Select(codingNav => codingNav.ParseCoding()).ToList(); newCodeableConcept.Text = instance.GetChildrenByName("text").GetString(); return(newCodeableConcept); }
public static Coding ParseCoding(this IElementNavigator instance) { var newCoding = new Coding(); newCoding.System = instance.GetChildrenByName("system").GetString(); newCoding.Version = instance.GetChildrenByName("version").GetString(); newCoding.Code = instance.GetChildrenByName("code").GetString(); newCoding.Display = instance.GetChildrenByName("display").GetString(); newCoding.UserSelected = instance.GetChildrenByName("userSelected").SingleOrDefault()?.Value as bool?; return(newCoding); }
public static IEnumerable <Scope> HarvestResource(IElementNavigator instance) { return(instance.GetChildrenByName("contained") .Select(child => new Scope(child, "#" + getStringValue(child.GetChildrenByName("id").FirstOrDefault())))); }
public static IEnumerable <Scope> HarvestBundle(IElementNavigator instance) { return(instance.GetChildrenByName("entry") .SelectMany(entry => entry.GetChildrenByName("resource").Take(1) .Select(res => new Scope(res, getStringValue(entry.GetChildrenByName("fullUrl").FirstOrDefault()))))); }
public ProfilePreprocessor(Func <string, StructureDefinition> profileResolver, Action <StructureDefinition> snapshotGenerator, IElementNavigator instance, string declaredTypeProfile, IEnumerable <StructureDefinition> additionalProfiles, IEnumerable <string> additionalCanonicals) { _profileResolver = profileResolver; _snapshotGenerator = snapshotGenerator; _path = instance.Path; _profiles = new ProfileAssertion(_path, _profileResolver); if (instance.TypeName != null) { _profiles.SetInstanceType(ModelInfo.CanonicalUriForFhirCoreType(instance.TypeName)); } if (declaredTypeProfile != null) { _profiles.SetDeclaredType(declaredTypeProfile); } // This is only for resources, but I don't bother checking, since this will return empty anyway _profiles.AddStatedProfile(instance.GetChildrenByName("meta").ChildrenValues("profile").Cast <string>()); //Almost identically, extensions can declare adherance to a profile using the 'url' attribute if (declaredTypeProfile == ModelInfo.CanonicalUriForFhirCoreType(FHIRDefinedType.Extension)) { var urlDeclaration = instance.GetChildrenByName("url").FirstOrDefault()?.Value as string; if (urlDeclaration != null && urlDeclaration.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)) { _profiles.AddStatedProfile(urlDeclaration); } } if (additionalProfiles != null) { _profiles.AddStatedProfile(additionalProfiles); } if (additionalCanonicals != null) { _profiles.AddStatedProfile(additionalCanonicals); } }
public static Model.Quantity ParseQuantity(this IElementNavigator instance) { var newQuantity = new Quantity(); newQuantity.Value = instance.GetChildrenByName("value").SingleOrDefault()?.Value as decimal?; var comp = instance.GetChildrenByName("comparator").GetString(); if (comp != null) { newQuantity.ComparatorElement = new Code <Quantity.QuantityComparator> { ObjectValue = comp } } ; newQuantity.Unit = instance.GetChildrenByName("unit").GetString(); newQuantity.System = instance.GetChildrenByName("system").GetString(); newQuantity.Code = instance.GetChildrenByName("code").GetString(); return(newQuantity); }
internal static OperationOutcome ValidateResourceReference(this Validator validator, IElementNavigator instance, ElementDefinition.TypeRefComponent typeRef) { var outcome = new OperationOutcome(); var references = instance.GetChildrenByName("reference"); var reference = references.FirstOrDefault()?.Value as string; if (reference == null) // No reference found -> this is always valid { return(outcome); } if (references.Count() > 1) { validator.Trace(outcome, $"Encountered multiple references, just using first ({reference})", Issue.CONTENT_REFERENCE_HAS_MULTIPLE_REFERENCES, instance); } // Try to resolve the reference *within* the current instance (Bundle, resource with contained resources) first ElementDefinition.AggregationMode?encounteredKind; var referencedResource = validator.ResolveReference(instance, reference, out encounteredKind, outcome); // Validate the kind of aggregation. // If no aggregation is given, all kinds of aggregation are allowed, otherwise only allow // those aggregation types that are given in the Aggregation element bool hasAggregation = typeRef.Aggregation != null && typeRef.Aggregation.Count() != 0; if (hasAggregation && !typeRef.Aggregation.Any(a => a == encounteredKind)) { validator.Trace(outcome, $"Encountered a reference ({reference}) of kind '{encounteredKind}' which is not allowed", Issue.CONTENT_REFERENCE_OF_INVALID_KIND, instance); } // If we failed to find a referenced resource within the current instance, try to resolve it using an external method if (referencedResource == null && encounteredKind == ElementDefinition.AggregationMode.Referenced) { try { referencedResource = validator.ExternalReferenceResolutionNeeded(reference, outcome, instance); } catch (Exception e) { validator.Trace(outcome, $"Resolution of external reference {reference} failed. Message: {e.Message}", Issue.UNAVAILABLE_REFERENCED_RESOURCE, instance); } } // If the reference was resolved (either internally or externally, validate it if (referencedResource != null) { validator.Trace(outcome, $"Starting validation of referenced resource {reference} ({encounteredKind})", Issue.PROCESSING_START_NESTED_VALIDATION, instance); // References within the instance are dealt with within the same validator, // references to external entities will operate within a new instance of a validator (and hence a new tracking context). // In both cases, the outcome is included in the result. if (encounteredKind != ElementDefinition.AggregationMode.Referenced) { outcome.Include(validator.Validate(referencedResource, typeRef.GetDeclaredProfiles(), statedProfiles: null, statedCanonicals: null)); } else { var newValidator = validator.NewInstance(); outcome.Include(newValidator.Validate(referencedResource, typeRef.GetDeclaredProfiles(), statedProfiles: null, statedCanonicals: null)); } } else { validator.Trace(outcome, $"Cannot resolve reference {reference}", Issue.UNAVAILABLE_REFERENCED_RESOURCE, instance); } return(outcome); }