USE [Arizona]
GO

/****** Object:  View [dbo].[v_Sync_V_PH_Insurance]    Script Date: 25.11.2022 15:31:31 ******/
IF OBJECT_ID('[dbo].[v_Sync_V_PH_Insurance]') IS NOT NULL 
    DROP VIEW [dbo].[v_Sync_V_PH_Insurance]
GO

/****** Object:  View [dbo].[v_Sync_V_PH_Insurance]    Script Date: 25.11.2022 15:31:31 ******/
SET ANSI_NULLS OFF
GO

SET QUOTED_IDENTIFIER OFF
GO

CREATE  VIEW [dbo].[v_Sync_V_PH_Insurance]
AS
/*===========================================================================
   
  Vue utilisee dans les synchro verticales pour la sp 'aps_Sync_V_Template_3'
  permettant de selectionner la subsidiary d'une table detail dans sa table 
  master.

        ******************************************************
        *    Attention le nom de la vue doit respecter       *
        *    le standard 'v_Sync_V_nom_de_la_table'          *
        ******************************************************

  Creation: 17.06.03 / rc
 
  Modifications:
    21.01.21 / spe : #TFS63351# Modify SyncV view and configuration to avoid CERES pharmacy_code problems on pharmacies
    25.11.22 / TSC : OCTPDBA-411: Create new field in DB to represent the string value of special insurance contracts
    
============================================================================*/
SELECT adk.ADK_subsidiary 'calc_subsidiary_id',
       phin.PH_insurance_GUID,
       phin.PHIN_address,
       phin.PHIN_key,
       phin.PHIN_EAN_key,
       phin.PHIN_type,
       phin.PHIN_invoice_type,
       phin.PHIN_name_french,
       phin.PHIN_name_german,
       phin.PHIN_name_italian,
       phin.PHIN_slogan_french,
       phin.PHIN_slogan_german,
       phin.PHIN_slogan_italian,
       phin.PHIN_type_of_proof,
       phin.PHIN_plan_LS,
       phin.PHIN_plan_HL,
       phin.PHIN_plan_MC,
       phin.PHIN_plan_LPPA,
       phin.PHIN_plan_FHLN,
       phin.PHIN_check_physician_number,
       phin.PHIN_address_1,
       phin.PHIN_address_2,
       phin.PHIN_zip_code,
       phin.PHIN_location,
       phin.PHIN_language,
       phin.PHIN_telephone,
       phin.PHIN_fax,
       phin.PHIN_IN_minimum_length,
       phin.PHIN_IN_maximum_length,
       phin.PHIN_IN_type,
       phin.PHIN_IN_alignment,
       phin.PHIN_IN_start_position,
       phin.PHIN_IN_end_position,
       phin.PHIN_IN_check_digit_ref,
       phin.PHIN_ISO_key,
       phin.PHIN_section_minimum_length,
       phin.PHIN_section_maximum_length,
       phin.PHIN_section_type,
       phin.PHIN_section_alignment,
       phin.PHIN_invoicing_method,
       phin.PHIN_origin,
       phin.PHIN_invoice_transmission,
       phin.PHIN_APS_TS,
       phin.PHIN_TS,
       phin.PHIN_VGUID,
       phin.PHIN_master_ID,
       phin.PHIN_bill_to,
       phin.PHIN_status,
       phin.PHIN_renewable_bonus_factor,
       phin.PHIN_insurance_bonus_factor,
       phin.PHIN_recipient_EAN_key,
       phin.PHIN_Invoice_delay,
       phin.PHIN_Invoice_gap,
       phin.PHIN_view_prescription_image,
       phin.PHIN_hl_accept_limited_coverage,
       phin.PHIN_mc_accept_limited_coverage,
       phin.PHIN_code_model,
       phin.PHIN_benefit_number,
       phin.PHIN_tp_min_amount,
       phin.PHIN_tp_min_amount_invoice,
       phin.PHIN_assignment_of_claim,
       phin.PHIN_rowguid,
       [phin].[PHIN_contract_name]
  FROM PH_insurance phin (NOLOCK)
  LEFT OUTER JOIN Address_key adk (NOLOCK) 
    ON adk.ADK_address = phin.PHIN_address
   AND adk.ADK_type = 1
GO


