示例#1
0
        public override Guid WriteToCDS(OrganizationServiceProxy _serviceProxy)
        {
            Guid referralrequestId = Guid.Empty;

            HealthCDM.msemr_referralrequest addReferralRequest = new HealthCDM.msemr_referralrequest();

            addReferralRequest.msemr_SubjectPatient        = new EntityReference(HealthCDM.Contact.EntityLogicalName, Guid.Parse((PatientId)));
            addReferralRequest.msemr_Requestor             = new EntityReference(HealthCDM.Contact.EntityLogicalName, Guid.Parse((PractitionerId)));
            addReferralRequest.msemr_Status                = new OptionSetValue(Status);
            addReferralRequest.msemr_OccurrenceDate        = OccurrendateDate;
            addReferralRequest.msemr_Description           = Description;
            addReferralRequest.msemr_Priority              = new OptionSetValue(Priority);
            addReferralRequest.msemr_Intent                = new OptionSetValue(Intent);
            addReferralRequest.msemr_name                  = Description;
            addReferralRequest.msemr_ContextType           = new OptionSetValue(contextType);
            addReferralRequest.msemr_Subject               = new OptionSetValue(Subject);
            addReferralRequest.msemr_ReferralRequestNumber = ReferralRequestNumber;
            addReferralRequest.msemr_RequesterAgent        = new OptionSetValue(RequestAgent);
            addReferralRequest.msemr_OccurrenceType        = new OptionSetValue(OccurrenceType);
            addReferralRequest.msemr_InitiatingEncounter   = new EntityReference(HealthCDM.msemr_encounter.EntityLogicalName, Guid.Parse((EncounterId)));
            addReferralRequest.msemr_AppointmentEMR        = new EntityReference(HealthCDM.msemr_appointmentemr.EntityLogicalName, Guid.Parse((AppointmentId)));

            try
            {
                referralrequestId = _serviceProxy.Create(addReferralRequest);

                if (referralrequestId != Guid.Empty)
                {
                    ReferralRequestId = referralrequestId.ToString();
                    Console.WriteLine("Created Patient Referral Request [" + ReferralRequestId + "] for Patient [" + PatientId + "]");
                }
                else
                {
                    throw new Exception("ReferralRequestId == null");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }

            return(referralrequestId);
        }
示例#2
0
        public override Guid WriteToCDS(string cdsUrl, string cdsUserName, string cdsPassword)
        {
            Guid referralrequestId = Guid.Empty;

            try
            {
                #region Get our Login Information

                // setup the variables
                OrganizationServiceProxy _serviceProxy;

                // homeRealmUri will stay null for now
                Uri homeRealmUri = null;

                // setup credentials from whatever is in the app.config
                ClientCredentials credentials;

                // same for organizationuri comes from app.config
                Uri organizationUri;

                // set the organization uri from what was in the app.config
                organizationUri = new Uri(cdsUrl);

                credentials = new ClientCredentials();
                credentials.UserName.UserName = cdsUserName;
                credentials.UserName.Password = cdsPassword;

                #endregion

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                using (_serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null))
                {
                    // To impersonate set the GUID of CRM user here (which I merely took from CRM itself
                    // would need not to use this caller id in the future (as it will change per instance of CRM)
                    //_serviceProxy.CallerId = new Guid("14D40CB7-81D5-E311-93F5-00155D00330C");
                    _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

                    //enable using proxy types
                    _serviceProxy.EnableProxyTypes();

                    HealthCDM.msemr_referralrequest addReferrralRequest = new HealthCDM.msemr_referralrequest();

                    addReferrralRequest.msemr_SubjectPatient = new EntityReference(HealthCDM.Contact.EntityLogicalName, Guid.Parse((PatientId)));
                    addReferrralRequest.msemr_Requestor      = new EntityReference(HealthCDM.Contact.EntityLogicalName, Guid.Parse((PractitionerId)));
                    addReferrralRequest.msemr_Status         = new OptionSetValue(Status);
                    addReferrralRequest.msemr_OccurrenceDate = OccurrendateDate;
                    addReferrralRequest.msemr_Description    = Description;
                    addReferrralRequest.msemr_Priority       = new OptionSetValue(Priority);
                    addReferrralRequest.msemr_Intent         = new OptionSetValue(Intent);
                    addReferrralRequest.msemr_name           = Description;

                    try
                    {
                        referralrequestId = _serviceProxy.Create(addReferrralRequest);

                        if (referralrequestId != Guid.Empty)
                        {
                            ReferralRequestId = referralrequestId.ToString();
                            Console.WriteLine("Created Patient Referral Request [" + ReferralRequestId + "] for Patient [" + PatientId + "]");
                        }
                        else
                        {
                            throw new Exception("ReferralRequestId == null");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }

            return(referralrequestId);
        }