Exemplo n.º 1
0
        private static string GetContainedId(Hl7.Fhir.Model.Composition composition, string resourceType, string sectionCode)
        {
            var resourceId  = string.Empty;
            var containedId = composition.Section
                              .FirstOrDefault(c => c.Code.Coding.Any(coding => coding.Code.Equals(sectionCode)))?.Content
                              .Reference?.TrimStart('#') ?? string.Empty;

            if (string.IsNullOrWhiteSpace(containedId))
            {
                return(resourceId);
            }

            var containedList = composition.Contained.FirstOrDefault(c => containedId.Equals(c.Id) && c.ResourceType == ResourceType.List) as List;

            if (containedList != null)
            {
                resourceId = containedList.Entry.FirstOrDefault()?.Item?.Reference
                             ?.Replace($"{resourceType}/", string.Empty) ?? string.Empty;
            }

            return(resourceId);
        }
        public static DocumentReference DocumentToDocumentReference(Composition composition, Bundle bundle, Binary bin, Uri binLocation)
        {
            var reference = new DocumentReference();
            reference.MasterIdentifier = new Identifier(Identifier.SYSTMEM_URI, bundle.Id.ToString());
            reference.Identifier = composition.Identifier != null ? new List<Identifier>() { composition.Identifier } : null;
            reference.Subject = composition.Subject;
            reference.Type = composition.Type;
            reference.Class = composition.Class;
            reference.Author = new List<ResourceReference>( composition.Author );
            reference.Custodian = composition.Custodian;
            reference.Authenticator = composition.Attester != null ? composition.Attester.Where(att => att.Mode.Any(am => am == Composition.CompositionAttestationMode.Professional ||
                                                                    am == Composition.CompositionAttestationMode.Legal) && att.Party != null).Select(att => att.Party).Last() : null;
            reference.CreatedElement = composition.Date != null ? new FhirDateTime(composition.Date) : null;
            reference.IndexedElement = Instant.Now();
            reference.Status = DocumentReference.DocumentReferenceStatus.Current;

            reference.DocStatus = composition.Status != null ?
                new CodeableConcept { Coding = new List<Coding>() { new Coding("http://hl7.org/fhir/composition-status", composition.Status.ToString()) } } : null;
            // todo: Use proper Enumerator conversion for composition.Status

            reference.Description = composition.Title;
            reference.Confidentiality = composition.Confidentiality != null ? new List<CodeableConcept>() { new CodeableConcept() { Coding = new List<Coding>() { composition.Confidentiality } } } : null;
            reference.PrimaryLanguage = composition.Language;
            reference.MimeType = bin.ContentType;
            reference.Format = new List<Uri>( bundle.Tags.FilterOnFhirSchemes().Where(t => t.Scheme != Tag.FHIRTAGSCHEME_SECURITY).Select(tg => new Uri(tg.Term)) );
            reference.Size = bin.Content.Length;
            reference.Hash = calculateSHA1(bin.Content);
            reference.Location = binLocation;

            if (composition.Event != null)
            {
                reference.Context = new DocumentReference.DocumentReferenceContextComponent();
                reference.Context.Event = composition.Event.Code != null ? new List<CodeableConcept>(composition.Event.Code) : null;
                reference.Context.Period = composition.Event.Period != null ? composition.Event.Period : null;
            }

            return reference;
        }
 public UpsertCompositionCommand(Hl7.Fhir.Model.Composition composition)
 {
     Composition = composition ?? throw new ArgumentNullException(nameof(composition));
 }