/// <summary>
        /// Create organization scoper
        /// </summary>
        private MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization CreateOrganization(HealthcareParticipant scoper, List <MARC.Everest.Connectors.IResultDetail> details)
        {
            if (scoper == null)
            {
                return(null);
            }

            PN tName = null;

            if (scoper.LegalName != null)
            {
                tName = CreatePN(scoper.LegalName, details);
            }

            var id = scoper.AlternateIdentifiers.Find(o => o.Domain != this.m_configService.OidRegistrar.GetOid("CR_PID").Oid);

            // Basic return value
            var retVal = new MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization(
                SET <II> .CreateSET(CreateII(id, details)),
                scoper.Type != null ? CreateCD <String>(scoper.Type, details) : null,
                tName != null ? BAG <ON> .CreateBAG(new ON(tName.Use[0], tName.Part)) : null,
                null
                );

            // Find all representatives
            foreach (HealthcareParticipant rep in scoper.FindAllComponents(HealthServiceRecordSiteRoleType.RepresentitiveOf))
            {
                var cp = new MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.ContactParty(
                    CreateIISet(rep.AlternateIdentifiers, details),
                    rep.Type != null ? CreateCD <String>(rep.Type, details) : null,
                    rep.PrimaryAddress != null ? BAG <AD> .CreateBAG(CreateAD(rep.PrimaryAddress, details)) : null,
                    null,
                    null
                    );

                // Add telecoms
                if (rep.TelecomAddresses != null)
                {
                    cp.Telecom = new BAG <TEL>();
                    foreach (var tel in rep.TelecomAddresses)
                    {
                        cp.Telecom.Add(CreateTEL(tel, details));
                    }
                }

                // Person info
                if (rep.Classifier == HealthcareParticipant.HealthcareParticipantType.Person && rep.LegalName != null)
                {
                    cp.ContactPerson = new MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Person(
                        BAG <EN> .CreateBAG(CreatePN(rep.LegalName, details))
                        );
                }
                retVal.ContactParty.Add(cp);
            }

            return(retVal);
        }
        /// <summary>
        /// Create provider organization
        /// </summary>
        private Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization CreateProviderOrganization(HealthcareParticipant providerOrg)
        {
            var contactParties = providerOrg.FindAllComponents(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.RepresentitiveOf);

            // Construct
            var retVal = new Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization(
                CreateIISet(providerOrg.AlternateIdentifiers),
                CreateCD <String>(providerOrg.Type),
                BAG <ON> .CreateBAG(CreateON(providerOrg.LegalName)),
                null
                );

            // Converts the contact party(ies)
            foreach (HealthcareParticipant cp in contactParties)
            {
                var contact = new Everest.RMIM.UV.NE2008.COCT_MT150003UV03.ContactParty(
                    CreateIISet(cp.AlternateIdentifiers),
                    CreateCD <String>(cp.Type),
                    BAG <AD> .CreateBAG(CreateAD(cp.PrimaryAddress)),
                    null,
                    null);

                // Add tel addresses to the contact parties
                if (cp.TelecomAddresses != null)
                {
                    contact.Telecom = new BAG <TEL>();
                    foreach (var tel in cp.TelecomAddresses)
                    {
                        contact.Telecom.Add(CreateTEL(tel));
                    }
                }

                // Person?
                if (cp.Classifier == HealthcareParticipant.HealthcareParticipantType.Person)
                {
                    contact.ContactPerson = new Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Person(
                        BAG <EN> .CreateBAG(CreatePN(cp.LegalName))
                        );
                }

                retVal.ContactParty.Add(contact);
            }

            return(retVal);
        }
        public override SVC.Messaging.FHIR.Resources.ResourceBase ProcessComponent(System.ComponentModel.IComponent component, List <Everest.Connectors.IResultDetail> dtls)
        {
            // Create a component
            HealthcareParticipant ptcpt = component as HealthcareParticipant;

            if (ptcpt.Classifier != HealthcareParticipant.HealthcareParticipantType.Organization)
            {
                ; // Not an organization pass off
            }
            // Organization
            Organization retVal = new Organization();

            retVal.Id        = ptcpt.Id.ToString();
            retVal.VersionId = ptcpt.Id.ToString();

            // Other identifiers
            foreach (var id in ptcpt.AlternateIdentifiers)
            {
                retVal.Extension.Add(ExtensionUtil.CreateIdentificationExtension(id));
            }

            if (ptcpt.Type != null)
            {
                retVal.Type = base.ConvertCode(ptcpt.Type);
            }

            retVal.Name   = ptcpt.LegalName.Parts[0].Value;
            retVal.Active = true;

            // Address
            if (ptcpt.PrimaryAddress != null)
            {
                retVal.Address = base.ConvertAddressSet(ptcpt.PrimaryAddress);
            }

            // Telecoms
            if (ptcpt.TelecomAddresses != null)
            {
                foreach (var tel in ptcpt.TelecomAddresses)
                {
                    retVal.Telecom.AddRange(base.ConvertTelecom(tel));
                }
            }

            var contacts = ptcpt.FindAllComponents(SVC.Core.ComponentModel.HealthServiceRecordSiteRoleType.RepresentitiveOf);

            foreach (HealthcareParticipant contact in contacts)
            {
                ContactEntity ce = new ContactEntity();

                // Link
                var processor     = FhirMessageProcessorUtil.GetComponentProcessor(contact.GetType());
                var processResult = processor.ProcessComponent(contact, dtls);

                if (processResult is Practictioner)
                {
                    var prac = processResult as Practictioner;
                    ce.Name    = prac.Name[0];
                    ce.Address = prac.Address[0];
                    ce.Gender  = prac.Gender;
                    ce.Telecom = prac.Telecom;
                }

                if (ce.Name != null)
                {
                    ce.Name = base.ConvertNameSet(contact.LegalName);
                }
                if (contact.TelecomAddresses != null)
                {
                    foreach (var t in contact.TelecomAddresses)
                    {
                        ce.Telecom.AddRange(base.ConvertTelecom(t));
                    }
                }
                if (contact.PrimaryAddress != null)
                {
                    ce.Address = base.ConvertAddressSet(contact.PrimaryAddress)[0];
                }

                retVal.ContactEntity.Add(ce);
            }

            return(retVal);
        }