コード例 #1
0
        /// <summary>
        /// Create the object
        /// </summary>
        protected override TModel Create(TModel modelInstance, TransactionMode mode)
        {
            if (modelInstance is ITargetedAssociation targetedAssociation)
            {
                // We may be creating multiple objects so let's do that
                var transaction = new Core.Model.Collection.Bundle()
                {
                    Item = new List <IdentifiedData>()
                    {
                        modelInstance
                    }
                };
                if (targetedAssociation.TargetEntity != null)
                {
                    transaction.Item.Insert(0, targetedAssociation.TargetEntity as IdentifiedData);
                }
                if (targetedAssociation.SourceEntity != null)
                {
                    transaction.Item.Insert(0, targetedAssociation.SourceEntity as IdentifiedData);
                }

                // Create
                this.m_bundleRepository.Insert(transaction);
                return(modelInstance);
            }
            else
            {
                return(this.m_repository.Insert(modelInstance));
            }
        }
コード例 #2
0
 /// <summary>
 /// Maps a OpenIZ bundle as FHIR
 /// </summary>
 protected override SanteDB.Messaging.FHIR.Resources.Bundle MapToFhir(Core.Model.Collection.Bundle model, RestOperationContext webOperationContext)
 {
     return(new SanteDB.Messaging.FHIR.Resources.Bundle()
     {
         Type = BundleType.Collection,
         // TODO: Actually construct a response bundle
     });
 }
コード例 #3
0
        /// <summary>
        /// Map the bundle to a model transaction
        /// </summary>
        public IdentifiedData MapToModel(Resource resourceInstance)
        {
            // Resource instance validation and convert
            if (!(resourceInstance is Hl7.Fhir.Model.Bundle fhirBundle))
            {
                this.m_tracer.TraceError("Argument must be a bundle");
                throw new ArgumentException(this.m_localizationService.FormatString("error.type.ArgumentException", new
                {
                    param = "bundle"
                }));
            }

            var sdbBundle = new Core.Model.Collection.Bundle();

            foreach (var entry in fhirBundle.Entry)
            {
                if (!entry.Resource.TryDeriveResourceType(out ResourceType entryType))
                {
                    continue;
                }
                var handler = FhirResourceHandlerUtil.GetResourceHandler(entryType) as IFhirResourceMapper;

                // Allow this entry to know its context in the bundle
                entry.Resource.AddAnnotation(fhirBundle);
                entry.Resource.AddAnnotation(sdbBundle);

                // Map and add to bundle
                var itm = handler.MapToModel(entry.Resource);
                sdbBundle.Remove(itm.Key.GetValueOrDefault());
                sdbBundle.Add(itm);

                // HACK: If the ITM is a relationship or participation insert it into the bundle
                if (itm is ITargetedAssociation targetedAssociation && targetedAssociation.TargetEntity != null)
                {
                    sdbBundle.Insert(sdbBundle.Item.Count - 1, targetedAssociation.TargetEntity as IdentifiedData);
                    itm = targetedAssociation.TargetEntity as IdentifiedData;
                }

                // Add original URLs so that subsequent bundle entries (which might reference this entry) can resolve
                if (itm is ITaggable taggable)
                {
                    taggable.AddTag(FhirConstants.OriginalUrlTag, entry.FullUrl);
                    taggable.AddTag(FhirConstants.OriginalIdTag, entry.Resource.Id);
                }

                if (entry.Request != null)
                {
                    sdbBundle.FocalObjects.Add(itm.Key.Value);
                }
            }

            sdbBundle.Item.RemoveAll(o => o == null || o is ITaggable taggable && taggable.GetTag(FhirConstants.PlaceholderTag) == "true");
            return(sdbBundle);
        }
コード例 #4
0
        /// <summary>
        /// Map FHIR resource to our bundle
        /// </summary>
        protected override Core.Model.Collection.Bundle MapToModel(SanteDB.Messaging.FHIR.Resources.Bundle resource, RestOperationContext webOperationContext)
        {
            var retVal = new Core.Model.Collection.Bundle();

            foreach (var entry in resource.Entry)
            {
                var entryType = entry.Resource.Resource?.GetType();
                if (entryType == null)
                {
                    continue;
                }
                var handler = FhirResourceHandlerUtil.GetResourceHandler(entryType.GetCustomAttribute <XmlRootAttribute>().ElementName) as IBundleResourceHandler;
                if (handler == null)
                {
                    this.traceSource.TraceWarning("Can't find bundle handler for {0}...", entryType.Name);
                    continue;
                }
                retVal.Add(handler.MapToModel(entry, webOperationContext, resource));
            }
            retVal.Item.RemoveAll(o => o == null);
            return(retVal);
        }