/// <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://santedb.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://santedb.org/security/policy"), o.Policy.Oid)).ToList() ?? new List <FhirCoding>(); retVal.Meta.Security.Add(new FhirCoding(new Uri("http://santedb.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> /// Converts a <see cref="Concept"/> instance to an <see cref="FhirCodeableConcept"/> instance. /// </summary> /// <param name="concept">The concept to be converted to a <see cref="FhirCodeableConcept"/></param> /// <param name="preferredCodeSystem">The preferred code system for the codeable concept</param> /// <param name="nullIfNoPreferred">When true, instructs the system to return only code in preferred code system or nothing</param> /// <returns>Returns a FHIR codeable concept.</returns> public static FhirCodeableConcept ToFhirCodeableConcept(Concept concept, String preferredCodeSystem = null, bool nullIfNoPreferred = false) { traceSource.TraceEvent(EventLevel.Verbose, "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 = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>(); var refTerm = codeSystemService.GetConceptReferenceTerm(concept.Key.Value, preferredCodeSystem); if (refTerm == null && nullIfNoPreferred) { return(null); // No code in the preferred system, ergo, we will instead use our own } else if (refTerm == null) { 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> /// Converts an <see cref="EntityTelecomAddress"/> instance to <see cref="FhirTelecom"/> instance. /// </summary> /// <param name="telecomAddress">The telecom address.</param> /// <returns>Returns the mapped FHIR telecom.</returns> public static FhirTelecom ToFhirTelecom(EntityTelecomAddress telecomAddress) { traceSource.TraceEvent(EventLevel.Verbose, "Mapping entity telecom address"); return(new FhirTelecom() { Use = telecomAddress.AddressUseKey == NullReasonKeys.NoInformation ? null : DataTypeConverter.ToFhirCodeableConcept(telecomAddress.AddressUse, "http://hl7.org/fhir/contact-point-use", true)?.GetPrimaryCode()?.Code, Value = telecomAddress.IETFValue }); }
/// <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(EventLevel.Verbose, "Mapping codeable concept"); return(codeableConcept?.Coding.Select(o => DataTypeConverter.ToConcept(o)).FirstOrDefault(o => o != null)); }