public override Guid WriteToCDS(OrganizationServiceProxy _serviceProxy) { Guid allergyIntolernaceId = Guid.Empty; HealthCDM.msemr_allergyintolerance addAllergyIntolerance = new HealthCDM.msemr_allergyintolerance(); addAllergyIntolerance.msemr_Patient = new EntityReference(HealthCDM.Contact.EntityLogicalName, Guid.Parse((PatientId))); addAllergyIntolerance.msemr_name = Item; addAllergyIntolerance.msemr_Code = Item; addAllergyIntolerance.msemr_Criticality = new OptionSetValue(Severity); addAllergyIntolerance.msemr_VerificationStatus = new OptionSetValue(VertificationStatus); addAllergyIntolerance.msemr_Type = new OptionSetValue(Type); try { allergyIntolernaceId = _serviceProxy.Create(addAllergyIntolerance); if (allergyIntolernaceId != Guid.Empty) { AllergyIntoleranceId = allergyIntolernaceId.ToString(); Console.WriteLine("Created Allergy Intolerance [" + AllergyIntoleranceId + "] for Patient [" + PatientId + "]"); } else { throw new Exception("AllegyIntoleranceId == null"); } } catch (Exception ex) { throw new Exception(ex.ToString()); } return(allergyIntolernaceId); }
public override Guid WriteToCDS(string cdsUrl, string cdsUserName, string cdsPassword) { Guid allergyIntolernaceId = 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_allergyintolerance addAllergyIntolerance = new HealthCDM.msemr_allergyintolerance(); addAllergyIntolerance.msemr_Patient = new EntityReference(HealthCDM.Contact.EntityLogicalName, Guid.Parse((PatientId))); addAllergyIntolerance.msemr_name = Item; addAllergyIntolerance.msemr_Code = Item; addAllergyIntolerance.msemr_Criticality = new OptionSetValue(Severity); addAllergyIntolerance.msemr_VerificationStatus = new OptionSetValue(VertificationStatus); addAllergyIntolerance.msemr_Type = new OptionSetValue(Type); try { allergyIntolernaceId = _serviceProxy.Create(addAllergyIntolerance); if (allergyIntolernaceId != Guid.Empty) { AllergyIntoleranceId = allergyIntolernaceId.ToString(); Console.WriteLine("Created Allergy Intolerance [" + AllergyIntoleranceId + "] for Patient [" + PatientId + "]"); } else { throw new Exception("AllergyIntoleranceId == null"); } } catch (Exception ex) { throw new Exception(ex.ToString()); } } } catch (Exception ex) { throw new Exception(ex.ToString()); } return(allergyIntolernaceId); }