/// <summary> /// Converts a <see cref="Concept"/> instance to an <see cref="FhirCodeableConcept"/> instance. /// </summary> /// <param name="concept">The concept.</param> /// <returns>Returns a FHIR codeable concept.</returns> public static FhirCodeableConcept ToFhirCodeableConcept(Concept concept, String preferredCodeSystem = null) { traceSource.TraceEvent(TraceEventType.Verbose, 0, "Mapping concept"); if (concept == null) { return(null); } if (String.IsNullOrEmpty(preferredCodeSystem)) { return new FhirCodeableConcept { Coding = concept.LoadCollection <ConceptReferenceTerm>(nameof(Concept.ReferenceTerms)).Select(o => DataTypeConverter.ToCoding(o.LoadProperty <ReferenceTerm>(nameof(ConceptReferenceTerm.ReferenceTerm)))).ToList(), Text = concept.LoadCollection <ConceptName>(nameof(Concept.ConceptNames)).FirstOrDefault()?.Name } } ; else { var codeSystemService = ApplicationContext.Current.GetService <IConceptRepositoryService>(); var refTerm = codeSystemService.GetConceptReferenceTerm(concept.Key.Value, preferredCodeSystem); if (refTerm == null) // No code in the preferred system, ergo, we will instead use our own { return new FhirCodeableConcept { Coding = concept.LoadCollection <ConceptReferenceTerm>(nameof(Concept.ReferenceTerms)).Select(o => DataTypeConverter.ToCoding(o.LoadProperty <ReferenceTerm>(nameof(ConceptReferenceTerm.ReferenceTerm)))).ToList(), Text = concept.LoadCollection <ConceptName>(nameof(Concept.ConceptNames)).FirstOrDefault()?.Name } } ; else { return new FhirCodeableConcept { Coding = new List <FhirCoding>() { ToCoding(refTerm) }, Text = concept.LoadCollection <ConceptName>(nameof(Concept.ConceptNames)).FirstOrDefault()?.Name } }; } }
/// <summary> /// Creates the resource. /// </summary> /// <typeparam name="TResource">The type of the t resource.</typeparam> /// <param name="resource">The resource.</param> /// <returns>TResource.</returns> public static TResource CreateResource <TResource>(IVersionedEntity resource) where TResource : ResourceBase, new() { var retVal = new TResource(); retVal.Id = resource.Key.ToString(); retVal.VersionId = resource.VersionKey.ToString(); // metadata retVal.Meta = new ResourceMetadata() { LastUpdated = (resource as IdentifiedData).ModifiedOn.DateTime, VersionId = resource.VersionKey?.ToString(), Profile = new Uri("http://openiz.org/fhir") }; retVal.Meta.Tags = (resource as ITaggable)?.Tags.Select(o => DataTypeConverter.ToFhirTag(o)).ToList(); // TODO: Configure this namespace / coding scheme retVal.Meta.Security = (resource as ISecurable)?.Policies.Where(o => o.GrantType == Core.Model.Security.PolicyGrantType.Grant).Select(o => new FhirCoding(new Uri("http://openiz.org/security/policy"), o.Policy.Oid)).ToList() ?? new List <FhirCoding>(); retVal.Meta.Security.Add(new FhirCoding(new Uri("http://openiz.org/security/policy"), PermissionPolicyIdentifiers.ReadClinicalData)); retVal.Extension = (resource as IExtendable)?.Extensions.Where(o => o.ExtensionTypeKey != ExtensionTypeKeys.JpegPhotoExtension).Select(o => DataTypeConverter.ToExtension(o)).ToList(); return(retVal); }
/// <summary> /// Gets the concept via the codeable concept /// </summary> /// <param name="codeableConcept">The codeable concept.</param> /// <returns>Returns a concept.</returns> public static Concept ToConcept(FhirCodeableConcept codeableConcept) { traceSource.TraceEvent(TraceEventType.Verbose, 0, "Mapping codeable concept"); return(codeableConcept?.Coding.Select(o => DataTypeConverter.ToConcept(o)).FirstOrDefault(o => o != null)); }