public ModifyPatientResp CreatePatientNew(Customer customer, PrimaryCarePhysician pcp, BillingAccount billingAccount) { try { var client = new KareoServicesClient(); var requestHeader = new RequestHeader { ClientVersion = ClientVersion, CustomerKey = billingAccount.CustomerKey, User = billingAccount.UserName, Password = billingAccount.Password }; // Create the patient to insert. var newPatient = new PatientCreate { FirstName = customer.Name.FirstName, MiddleName = customer.Name.MiddleName, LastName = customer.Name.LastName, DateofBirth = customer.DateOfBirth, Gender = customer.Gender == Gender.Male ? GenderCode.Male : customer.Gender == Gender.Female ? GenderCode.Female : GenderCode.Unknown, MedicalRecordNumber = customer.CustomerId.ToString(), AddressLine1 = customer.Address.StreetAddressLine1, AddressLine2 = customer.Address.StreetAddressLine2, City = customer.Address.City, State = customer.Address.StateCode, ZipCode = customer.Address.ZipCode.Zip, HomePhone = customer.HomePhoneNumber != null ? customer.HomePhoneNumber.FormatPhoneNumber : string.Empty, WorkPhone = customer.OfficePhoneNumber != null ? customer.OfficePhoneNumber.FormatPhoneNumber : string.Empty, MobilePhone = customer.MobilePhoneNumber != null ? customer.MobilePhoneNumber.FormatPhoneNumber : string.Empty, EmailAddress = customer.Email != null?customer.Email.ToString() : string.Empty, PatientExternalID = customer.CustomerId.ToString() }; // Set the practice we want to add this patient to var practice = new PracticeIdentifierReq { PracticeName = billingAccount.Name }; newPatient.Practice = practice; // Create the case details for the patient var patientCase = new PatientCaseCreateReq { CaseName = CaseName, //patientCase.PayerScenario Active = true, SendPatientStatements = true }; newPatient.Cases = new[] { patientCase }; if (pcp != null) { newPatient.PrimaryCarePhysician = new PhysicianIdentifierReq { FullName = pcp.Name.FullName }; } // Create the create patient request object var request = new CreatePatientReq { RequestHeader = requestHeader, Patient = newPatient }; // Call the Create Patient method var response = client.CreatePatient(request); // Check the response for an error if (response.ErrorResponse.IsError) { throw new Exception(response.ErrorResponse.ErrorMessage); } if (!response.SecurityResponse.SecurityResultSuccess) { throw new Exception(response.SecurityResponse.SecurityResult); } client.Close(); return(response); } catch (Exception ex) { throw new Exception(ex.Message); } }
public ModifyPatientResp CreatePatient(Customer customer, Eligibility eligibility, IEnumerable <InsuranceCompany> insuranceCompanies, PrimaryCarePhysician pcp, BillingAccount billingAccount) { try { var client = new KareoServicesClient(); var requestHeader = new RequestHeader { ClientVersion = ClientVersion, CustomerKey = billingAccount.CustomerKey, User = billingAccount.UserName, Password = billingAccount.Password }; // Create the patient to insert. var newPatient = new PatientCreate { FirstName = customer.Name.FirstName, MiddleName = customer.Name.MiddleName, LastName = customer.Name.MiddleName, DateofBirth = customer.DateOfBirth, Gender = customer.Gender == Gender.Male ? GenderCode.Male : customer.Gender == Gender.Female ? GenderCode.Female : GenderCode.Unknown, MedicalRecordNumber = customer.CustomerId.ToString(), AddressLine1 = customer.Address.StreetAddressLine1, AddressLine2 = customer.Address.StreetAddressLine2, City = customer.Address.City, State = customer.Address.StateCode, ZipCode = customer.Address.ZipCode.Zip, HomePhone = customer.HomePhoneNumber != null ? customer.HomePhoneNumber.FormatPhoneNumber : string.Empty, WorkPhone = customer.OfficePhoneNumber != null ? customer.OfficePhoneNumber.FormatPhoneNumber : string.Empty, MobilePhone = customer.MobilePhoneNumber != null ? customer.MobilePhoneNumber.FormatPhoneNumber : string.Empty, EmailAddress = customer.Email != null?customer.Email.ToString() : string.Empty, PatientExternalID = customer.CustomerId.ToString() }; // Set the practice we want to add this patient to var practice = new PracticeIdentifierReq { PracticeName = billingAccount.Name }; // Create the case details for the patient var patientCase = new PatientCaseCreateReq { CaseName = CaseName, //patientCase.PayerScenario Active = true, SendPatientStatements = true }; var eligibleResponse = JsonConvert.DeserializeObject <EligibleResponse>(eligibility.Response); InsuranceCompany insuranceCompany = null; if (eligibleResponse.PrimaryInsurance != null) { insuranceCompany = insuranceCompanies.FirstOrDefault(ic => ic.Code == eligibleResponse.PrimaryInsurance.Id); } else if (eligibleResponse.Insurance != null) { insuranceCompany = insuranceCompanies.FirstOrDefault(ic => ic.Code == eligibleResponse.Insurance.Id); } if (insuranceCompany == null) { insuranceCompany = insuranceCompanies.First(ic => ic.Id == eligibility.InsuranceCompanyId); } // Create the insurance policies for the patient case var primaryPolicy = new InsurancePolicyCreateReq { CompanyName = insuranceCompany.Name, PlanName = eligibleResponse.Plan.PlanName, PolicyNumber = eligibleResponse.Demographics.Subscriber.MemberId, PolicyGroupNumber = eligibleResponse.Demographics.Subscriber.GroupId, Copay = eligibility.CoPayment.ToString("0.00") }; //primaryPolicy.PlanID = eligibleResponse.Plan.PlanNumber; patientCase.Policies = new InsurancePolicyCreateReq[] { primaryPolicy }; newPatient.Practice = practice; newPatient.Cases = new PatientCaseCreateReq[] { patientCase }; if (pcp != null) { newPatient.PrimaryCarePhysician = new PhysicianIdentifierReq { FullName = pcp.Name.FullName }; } // Create the create patient request object var request = new CreatePatientReq { RequestHeader = requestHeader, Patient = newPatient }; // Call the Create Patient method var response = client.CreatePatient(request); // Check the response for an error if (response.ErrorResponse.IsError) { throw new Exception(response.ErrorResponse.ErrorMessage); } if (!response.SecurityResponse.SecurityResultSuccess) { throw new Exception(response.SecurityResponse.SecurityResult); } client.Close(); return(response); } catch (Exception ex) { throw new Exception(ex.Message); } }