public void UpsertProviderClient(ProviderClient providerClient) { using (var db = new fasams_db()) { ProviderClient existing = db.ProviderClients .Include(x => x.ProviderClientIdentifiers) .Include(x => x.ProviderClientPhones) .Include(x => x.ProviderClientEmailAddresses) .Include(x => x.ProviderClientPhysicalAddresses) .SingleOrDefault(c => c.SourceRecordIdentifier == providerClient.SourceRecordIdentifier && c.FederalTaxIdentifier == providerClient.FederalTaxIdentifier); if (existing == null) { db.ProviderClients.Add(providerClient); foreach (var row in providerClient.ProviderClientIdentifiers) { db.ProviderClientIdentifiers.Add(row); } if (providerClient.ProviderClientPhones != null) { foreach (var row in providerClient.ProviderClientPhones) { db.ProviderClientPhones.Add(row); } } if (providerClient.ProviderClientEmailAddresses != null) { foreach (var row in providerClient.ProviderClientEmailAddresses) { db.ProviderClientEmailAddresses.Add(row); } } if (providerClient.ProviderClientPhysicalAddresses != null) { foreach (var row in providerClient.ProviderClientPhysicalAddresses) { db.ProviderClientPhysicalAddresses.Add(row); } } } else { db.Entry(existing).CurrentValues.SetValues(providerClient); } db.SaveChanges(); } }
public void UpsertServiceEvent(ServiceEvent serviceEvent) { using (var db = new fasams_db()) { ServiceEvent existing = db.ServiceEvents .Include(x => x.ServiceEventCoveredServiceModifiers) .Include(x => x.ServiceEventHcpcsProcedureModifiers) .Include(x => x.ServiceEventExpenditureModifiers) .SingleOrDefault(s => s.SourceRecordIdentifier == serviceEvent.SourceRecordIdentifier); if (existing == null) { db.ServiceEvents.Add(serviceEvent); if (serviceEvent.ServiceEventCoveredServiceModifiers != null) { foreach (var row in serviceEvent.ServiceEventCoveredServiceModifiers) { db.CoveredServiceModifiers.Add(row); } } if (serviceEvent.ServiceEventHcpcsProcedureModifiers != null) { foreach (var row in serviceEvent.ServiceEventHcpcsProcedureModifiers) { db.HcpcsProcedureModifiers.Add(row); } } if (serviceEvent.ServiceEventExpenditureModifiers != null) { foreach (var row in serviceEvent.ServiceEventExpenditureModifiers) { db.ExpenditureModifiers.Add(row); } } } else { db.Entry(existing).CurrentValues.SetValues(serviceEvent); } db.SaveChanges(); } }
public void UpsertSubContract(Subcontract subcontract) { using (var db = new fasams_db()) { Subcontract existing = db.Subcontracts .Include(x => x.SubcontractServices) .Include(x => x.SubcontractOutputMeasures) .Include(x => x.SubcontractOutcomeMeasures) .SingleOrDefault(s => s.ContractNumber == subcontract.ContractNumber && s.SubcontractNumber == subcontract.SubcontractNumber && s.AmendmentNumber == subcontract.AmendmentNumber); if (existing == null) { db.Subcontracts.Add(subcontract); if (subcontract.SubcontractServices != null) { foreach (var row in subcontract.SubcontractServices) { row.ContractNumber = subcontract.ContractNumber; row.SubcontractNumber = subcontract.SubcontractNumber; row.AmendmentNumber = subcontract.AmendmentNumber; db.SubcontractServices.Add(row); } } if (subcontract.SubcontractOutputMeasures != null) { foreach (var row in subcontract.SubcontractOutputMeasures) { row.ContractNumber = subcontract.ContractNumber; row.SubcontractNumber = subcontract.SubcontractNumber; row.AmendmentNumber = subcontract.AmendmentNumber; db.SubcontractOutputMeasures.Add(row); } } if (subcontract.SubcontractOutcomeMeasures != null) { foreach (var row in subcontract.SubcontractOutcomeMeasures) { row.ContractNumber = subcontract.ContractNumber; row.SubcontractNumber = subcontract.SubcontractNumber; row.AmendmentNumber = subcontract.AmendmentNumber; db.SubcontractOutcomeMeasures.Add(row); } } } else { db.Entry(existing).CurrentValues.SetValues(subcontract); if (subcontract.SubcontractServices != null) { foreach (var row in subcontract.SubcontractServices) { var exRow = db.SubcontractServices.Find(row.SourceRecordIdentifier); if (exRow != null) { db.Entry(exRow).CurrentValues.SetValues(row); } else { db.SubcontractServices.Add(row); } } } if (subcontract.SubcontractOutputMeasures != null) { foreach (var row in subcontract.SubcontractOutputMeasures) { var exRow = db.SubcontractOutputMeasures.Find(row.ProgramAreaCode, row.ServiceCategoryCode, row.ContractNumber, row.SubcontractNumber, row.AmendmentNumber); if (exRow != null) { db.Entry(exRow).CurrentValues.SetValues(row); } else { db.SubcontractOutputMeasures.Add(row); } } } if (subcontract.SubcontractOutcomeMeasures != null) { foreach (var row in subcontract.SubcontractOutcomeMeasures) { var exRow = db.SubcontractOutcomeMeasures.Find(row.ProgramAreaCode, row.OutcomeMeasureCode, row.ContractNumber, row.SubcontractNumber, row.AmendmentNumber); if (exRow != null) { db.Entry(exRow).CurrentValues.SetValues(row); } else { db.SubcontractOutcomeMeasures.Add(row); } } } } db.SaveChanges(); } }
public void UpsertTreatmentSession(TreatmentEpisode treatmentEpisode) { using (var db = new fasams_db()) { TreatmentEpisode existing = db.TreatmentEpisodes .Include(x => x.Admissions.Select(a => a.Discharge)) .Include(x => x.ImmediateDischarges) .SingleOrDefault(e => e.SourceRecordIdentifier == treatmentEpisode.SourceRecordIdentifier && e.FederalTaxIdentifier == treatmentEpisode.FederalTaxIdentifier); if (existing == null) { db.TreatmentEpisodes.Add(treatmentEpisode); if (treatmentEpisode.Admissions != null) { foreach (var row in treatmentEpisode.Admissions) { db.Admissions.Add(row); if (row.PerformanceOutcomeMeasures != null) { foreach (var perf in row.PerformanceOutcomeMeasures) { db.PerformanceOutcomeMeasures.Add(perf); if (perf.SubstanceUseDisorders != null) { foreach (var sad in perf.SubstanceUseDisorders) { db.SubstanceUseDisorders.Add(sad); } } } } if (row.Evaluations != null) { foreach (var item in row.Evaluations) { db.Evaluations.Add(item); } } if (row.Diagnoses != null) { foreach (var item in row.Diagnoses) { db.Diagnoses.Add(item); } } if (row.Discharge != null && row.Discharge.SourceRecordIdentifier != null) { db.Discharges.Add(row.Discharge); } } } } else { db.Entry(existing).CurrentValues.SetValues(treatmentEpisode); if (treatmentEpisode.Admissions != null) { //db.Entry(existing.Admissions).CurrentValues.SetValues(treatmentEpisode.Admissions); foreach (var row in treatmentEpisode.Admissions) { var exAdmit = db.Admissions.Find(row.SourceRecordIdentifier); db.Entry(exAdmit).CurrentValues.SetValues(row); if (row.PerformanceOutcomeMeasures != null) { foreach (var perf in row.PerformanceOutcomeMeasures) { var exPerf = db.PerformanceOutcomeMeasures.Find(perf.SourceRecordIdentifier); if (exPerf != null) { db.Entry(exPerf).CurrentValues.SetValues(perf); } else { db.PerformanceOutcomeMeasures.Add(perf); } } } if (row.Evaluations != null) { foreach (var item in row.Evaluations) { var exItem = db.Evaluations.Find(item.SourceRecordIdentifier); if (exItem != null) { db.Entry(exItem).CurrentValues.SetValues(item); } else { db.Evaluations.Add(item); } } } if (row.Diagnoses != null) { foreach (var item in row.Diagnoses) { var exItem = db.Diagnoses.Find(item.SourceRecordIdentifier); if (exItem != null) { db.Entry(exItem).CurrentValues.SetValues(item); } else { db.Diagnoses.Add(item); } } } if (row.Discharge != null) { var exItem = db.Discharges.Find(row.Discharge.SourceRecordIdentifier); if (exItem != null) { db.Entry(exItem).CurrentValues.SetValues(row.Discharge); } else { db.Discharges.Add(row.Discharge); } if (row.Discharge.Diagnoses != null) { foreach (var dx in row.Discharge.Diagnoses) { var exDx = db.Diagnoses.Find(dx.SourceRecordIdentifier); if (exDx != null) { db.Entry(exDx).CurrentValues.SetValues(dx); } else { db.Diagnoses.Add(dx); } } } if (row.Discharge.Evaluations != null) { foreach (var eval in row.Discharge.Evaluations) { var exEval = db.Evaluations.Find(eval.SourceRecordIdentifier); if (exEval != null) { db.Entry(exEval).CurrentValues.SetValues(eval); } else { db.Evaluations.Add(eval); } } } } } } } db.SaveChanges(); } }