diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..5cb1f68 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,421 @@ +# Starter pipeline + + +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +pool: + vmImage: ubuntu-latest + +steps: +- task: SqlDacpacDeploymentOnMachineGroup@0 + displayName: _D03091 - INDEX - Load items CDS and prescribers from PharmIndex to Arizona - Central + inputs: + TaskType: 'sqlInline' + InlineSql: | + /* step 1 - Check download from Pharmindex is finished */ + use pharmindexTP + GO + + + + + declare @today datetime; + + select @today = convert(datetime, convert(varchar(20), getdate(),102)) + + if not exists ( select top 1 * + from BatchImportHistory bih + where bih.Success = 1 + and bih.EndImportDate > @today) + begin /* Download not OK */ + + raiserror('Pharmindex download in process, job not executed', 16,1) + + end; + + GO + + /* step 2 - INDEX - Transfert PharmIndexTP to Arizona items, Prescriber using Checksum */ + begin try + + declare @out_param_int_1 int + execute[dbo].[pdx_loading] + @in_job_type = 20 + ,@skip_mapping = 0 + ,@in_subsidiary = 100 + ,@in_table_name = null + ,@in_debug = 0 + ,@out_param_int_1 = @out_param_int_1 output + + end try + begin catch + declare + @mail_message nvarchar(2000), + @mail_subject nvarchar(255); + set @mail_message = '

Résumé des erreurs dans le tableau ci-dessous :

' +' + + + + + + + + + ' + ' + + + + + + + '+ ' +
ErrorNumberErrorSeverityErrorStateErrorProcedureErrorLineErrorMessage
' + isnull(convert(varchar, ERROR_NUMBER()), '') + '' + isnull(convert(varchar, ERROR_SEVERITY()), '') + '' + isnull(convert(varchar, ERROR_STATE()), '') + '' + isnull(ERROR_PROCEDURE(), '') + '' + isnull(convert(varchar, ERROR_LINE()), '') + '' + isnull(ERROR_MESSAGE(), '') + '
+ + '; + + set @mail_subject = 'INDEX - Transfert PharmIndex to PHGD_xx for items using checksum (Instance ' + @@SERVERNAME + ') - Job _D01941 - INDEX'; + + /* envoi du mail */ + exec Arizona.dbo.aps_Send_Mail_with_template + @in_param_varchar_2 = 'HCI_PharmIndex;HCI_DataManagement', + @in_param_varchar_3 = @mail_message, + @in_param_subject = @mail_subject, + @in_job_type = 4; + + end catch + go + + /* step 3 - INDEX - Control if exist prescribers with same contract number than an OU */ + use Arizona + + declare @subject varchar(8000) + , @errmsg varchar(8000) + + select @errmsg = 'Les pharmacies suivantes ont un concordat identique à celui d''un prescripteur actif' + + select @errmsg = @errmsg + char(13) + char(10) + ou1.OU_code + char(9) + ou1.OU_short_name + char(9) + pr1.PHPR_contract_number + from PH_prescriber pr1 with (nolock) + join PH_prescriber pr2 with (nolock) + on pr2.PH_prescriber_GUID <> pr1.PH_prescriber_GUID + and pr2.PHPR_contract_number = pr1.PHPR_contract_number + and pr2.PHPR_status = pr1.PHPR_status + join Organizational_unit ou1 with (nolock) + on ou1.OU_address = pr1.PHPR_address + left outer join Organizational_unit ou2 with (nolock) + on ou2.OU_address = pr2.PHPR_address + where pr1.PHPR_status = 1 + and ou2.Organizational_unit_ID is null + and exists(select 1 + from OU_store_history oust with (nolock) + where oust.OUSH_organizational_unit = ou1.Organizational_unit_ID + and (oust.OUSH_end_date is null or oust.OUSH_end_date >= getdate())) + order by ou1.OU_code + + if @@ROWCOUNT > 0 + begin + + select @subject = QUOTENAME(OBJECT_SCHEMA_NAME(@@PROCID)) + +'.'+QUOTENAME(OBJECT_NAME(@@PROCID)) + + exec aps_Send_Mail_with_template + @in_param_varchar_2 = 'HCI_PharmIndex;HCI_DataManagement', + @in_param_varchar_3 = @errmsg, + @in_param_subject = @subject, + @in_job_type = 4; + + end + + go + + + /* step 4 - Update PEXF */ + declare @cvPHGDPriceCodePEXF int, + @SubsidiaryId int, + @w_date date + + select @SubsidiaryId = 1000, + @cvPHGDPriceCodePEXF = NULL, + @w_date = getdate() + + exec arizona.dbo.sp_bmc_Bmc_Applic_Default + @in_job_type = 3, + @in_param_int_1 = NULL, + @in_param_int_2 = @SubsidiaryId, + @in_param_varchar_1 = 'cvPHGDPriceCodePSL1', + @out_default_value = @cvPHGDPriceCodePEXF output, + @out_param_int_1 = null + + + if @cvPHGDPriceCodePEXF is null + begin + select @SubsidiaryId = 100 + + exec arizona.dbo.sp_bmc_Bmc_Applic_Default + @in_job_type = 3, + @in_param_int_1 = NULL, + @in_param_int_2 = @SubsidiaryId, + @in_param_varchar_1 = 'cvPHGDPriceCodePSL1', + @out_default_value = @cvPHGDPriceCodePEXF output, + @out_param_int_1 = null + end + + /*------------- + Fermeture des PEXF sans Adresse pour les articles avec insurance code not in (10, 11) + ------------------*/ + + Update top(5000) FP set fp.fp_end_date = DATEADD(d,-1,@w_date) + from subsidiary SUB with (nolock) + + join price_code PRC with (nolock) + on prc.prc_subsidiary = sub.subsidiary_id + and prc.price_code_id = @cvPHGDPriceCodePEXF + + join Fixed_price FP with (nolock) + on FP.FP_price_code = prc.price_code_id + and FP.fp_subsidiary = sub.subsidiary_id + and FP.FP_address is null + and FP.FP_start_date < GETDATE() + and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE() + + join Item_key ITK with (nolock) + on itk.ITK_item = fp.fp_item + and ITK.ITK_subsidiary = SUB.Subsidiary_ID + and ITK.ITK_type = 1 + + join PH_item phit with (nolock) + on phit.PHIT_item = ITK.ITK_item + and phit.PHIT_insurance_code not in ('10', '11') + + where SUB.subsidiary_id = @SubsidiaryId + + /*--------------------------------------- + Clôture du PEXF sans adresse à la date -1 de la start_date du prix PEXF avec adresse + pour les articles LS. + + Nous recréons un PEXF avec la bonne start_date et le bon prix afin que la facturation aux caisse maladie soit OK + --------------*/ + + Update top(5000) FP1 set fp1.fp_end_date = DATEADD(d,-1,fp.FP_start_date) + from subsidiary SUB with (nolock) + join price_code PRC with (nolock) + on prc.prc_subsidiary = sub.subsidiary_id + and prc.price_code_id = @cvPHGDPriceCodePEXF + + join Fixed_price FP with (nolock) + on FP.FP_price_code = prc.price_code_id + and FP.fp_subsidiary = sub.subsidiary_id + and FP.FP_address is not null + and FP.FP_start_date < GETDATE() + and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE() + and FP.fixed_price_id = (select top 1 fp2.fixed_price_id from Fixed_price FP2 with (nolock) + where FP2.FP_item = FP.FP_item + and FP2.FP_price_code = fp.FP_price_code + and FP2.fp_subsidiary = FP.fp_subsidiary + and FP2.FP_address is not null + and FP2.FP_start_date < GETDATE() + and ISNULL(FP2.fp_end_date, '2099-12-31') > GETDATE() + + order by FP2.FP_start_date desc + ) + + join Item_key ITK with (nolock) + on itk.ITK_item = fp.fp_item + and ITK.ITK_subsidiary = SUB.Subsidiary_ID + and ITK.ITK_type = 1 + + join PH_item phit with (nolock) + on phit.PHIT_item = ITK.ITK_item + and phit.PHIT_insurance_code in ('10', '11') + + join Fixed_price FP1 with (nolock) + on FP1.FP_price_code = prc.price_code_id + and FP1.fp_subsidiary = sub.subsidiary_id + and FP1.FP_address is null + and FP1.FP_start_date < GETDATE() + and ISNULL(FP1.fp_end_date, '2099-12-31') > GETDATE() + and FP1.FP_item = FP.FP_item + + where SUB.subsidiary_id = @SubsidiaryId + and isnull(FP.FP_tax_free_price_per_unit,0) <> isnull(FP1.FP_tax_free_price_per_unit,0) + + /*---------- + + Creation PEXF sans adresse avec start_date et prix du PEXF avec Adresse pour LS (Le plus récent) + + ------------*/ + + declare + + @New_fixed_price_ID int, + @nb_fixed_price int , + @fp_subsidiary int, + @fp_tariff_type int, + @fp_item int, + @fp_currency int, + @fp_price_code int, + @fp_sales_tax_code int, + @FP_start_date datetime, + @FP_tax_free_price_per_unit dec(14,2) + + + SELECT @nb_fixed_price = 1 + + /*-- Declaration du curseur c_external_item --*/ + declare c_FP cursor local forward_only read_only static for + + select FP.fp_subsidiary, + FP.fp_tariff_type, + FP.fp_item, + FP.fp_currency, + FP.fp_price_code, + FP.fp_sales_tax_code, + FP.FP_start_date, + FP.FP_tax_free_price_per_unit + + from subsidiary SUB with (nolock) + + join price_code PRC with (nolock) + on prc.prc_subsidiary = sub.subsidiary_id + and prc.price_code_id = @cvPHGDPriceCodePEXF + + join Fixed_price FP with (nolock) + on FP.FP_price_code = prc.price_code_id + and FP.fp_subsidiary = sub.subsidiary_id + and FP.FP_address is not null + and FP.FP_start_date < GETDATE() + and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE() + and FP.fixed_price_id = (select top 1 fp2.fixed_price_id from Fixed_price FP2 with (nolock) + where FP2.FP_item = FP.FP_item + and FP2.FP_price_code = fp.FP_price_code + and FP2.fp_subsidiary = FP.fp_subsidiary + and FP2.FP_address is not null + and FP2.FP_start_date < GETDATE() + and ISNULL(FP2.fp_end_date, '2099-12-31') > GETDATE() + order by FP2.FP_start_date desc + ) + + join Item_key ITK with (nolock) + on itk.ITK_item = fp.fp_item + and ITK.ITK_subsidiary = SUB.Subsidiary_ID + and ITK.ITK_type = 1 + + join PH_item phit with (nolock) + on phit.PHIT_item = ITK.ITK_item + and phit.PHIT_insurance_code in ('10', '11') + + left outer join Fixed_price FP1 with (nolock) + on FP1.FP_price_code = prc.price_code_id + and FP1.fp_subsidiary = sub.subsidiary_id + and FP1.FP_address is null + and FP1.FP_start_date < GETDATE() + and ISNULL(FP1.fp_end_date, '2099-12-31') > GETDATE() + and FP1.FP_item = FP.FP_item + + where SUB.subsidiary_id = @SubsidiaryId + and FP1.Fixed_price_ID is null + + order by 1 + + open c_FP; + + fetch next from c_FP + into @fp_subsidiary , + @fp_tariff_type , + @fp_item , + @fp_currency , + @fp_price_code , + @fp_sales_tax_code , + @FP_start_date , + @FP_tax_free_price_per_unit + + while (@@fetch_status <> -1 ) + begin + + if (@@fetch_status <> -2 ) + begin + + /*----- Recherche dernier ID pour Fixed_Price -----*/ + select @New_fixed_price_ID = null + + exec sp_bmc_GetNextID + @in_key = 'fixed_price', + @in_id_column = 'fixed_price_id', + @in_nbr_of_record = @nb_fixed_price, + @out_id = @New_fixed_price_id output + + insert fixed_price + (fixed_price_id, + + fp_subsidiary, + fp_tariff_type, + fp_item, + fp_currency, + fp_price_code, + fp_sales_tax_code, + fp_start_date, + fp_tax_free_price_per_unit , + + fp_unit_code, + FP_price_per_unit_unit_code, + fp_final_discount_possible, + FP_discount_level_1_possible, + FP_discount_level_2_possible, + FP_origin, + FP_remark + + ) + select + @New_fixed_price_id, + + @fp_subsidiary , + @fp_tariff_type , + @fp_item , + @fp_currency , + @fp_price_code , + @fp_sales_tax_code , + @FP_start_date , + @FP_tax_free_price_per_unit, + 1, + 1, + 1, + 1, + 1, + 1, + 'Automatic Insert PEXF ' + + /*----- fin du curseur -----*/ + + + end /* (@@fetch_status <> -2 ) */ + + fetch next from c_FP + into @fp_subsidiary , + @fp_tariff_type , + @fp_item , + @fp_currency , + @fp_price_code , + @fp_sales_tax_code , + @FP_start_date , + @FP_tax_free_price_per_unit + + end /* (@@fetch_status <> -1 ) */ + + close c_FP; + deallocate c_FP; + + ServerName: 'localhost' + DatabaseName: 'master' + AuthScheme: 'windowsAuthentication' + +- script: echo Hello, world! + displayName: 'Run a one-line script' + +- script: | + echo Add other tasks to build, test, and deploy your project. + echo See https://aka.ms/yaml + displayName: 'Run a multi-line script'