' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Imports System.Xml
Imports System.IO
Imports System.Text
Imports System.Drawing.Drawing2D

Module declarations

#Region "FONCTIONS SESAM VITALE"
    'fonctions SGD techniques
    Public Declare Function SGD_ReserverSession Lib "sgdw32.dll" (ByVal Taille As UInt32, ByRef NumeroSession As UInt16) As UInt16
    Public Declare Function SGD_RedimensionnerBuffer Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal Taille As UInt32) As UInt16
    Public Declare Function SGD_LibererSession Lib "sgdw32.dll" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SGD_InitTrace Lib "sgdw32.dll" (ByVal NomFichier As String, ByVal ModeOuverture As String, ByVal Module_ As UInt16, ByVal niveau As Byte) As UInt16

    'fonctions SGD de constitution des données en entrée
    Public Declare Function SGD_AjouterGroupe Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16) As UInt16
    Public Declare Function SGD_AjouterChamp Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal ValeurChamp As String) As UInt16
    Public Declare Function SGD_AjouterChampBin Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal ValeurChamp As String, ByVal TailleMax As UInt32) As UInt16
    Public Declare Function SGD_AjouterChampFichier Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal NomFichier As String) As UInt16


    'fonctions SGD d’extraction des données restituées
    Public Declare Function SGD_LireGroupeSuivant Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupeCourant As UInt16, ByVal OccurrenceGroupeCourant As UInt16, ByRef IdGroupeSuivant As UInt16, ByRef OccurrenceGroupeSuivant As UInt16) As UInt16
    Public Declare Function SGD_LireChamp Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal OccurrenceGroupe As UInt16, ByVal NumeroChamp As UInt16, ByVal ValeurChamp As String, ByRef TailleMax As UInt32) As UInt16
    Public Declare Function SGD_LireChampBin Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal OccurrenceGroupe As UInt16, ByVal NumeroChamp As UInt16, ByVal ValeurChamp As String, ByRef TailleMax As UInt32) As UInt16
    Public Declare Function SGD_LireChampFichier Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal OccurrenceGroupe As UInt16, ByVal NumeroChamp As UInt16, ByVal NomFichier As String) As UInt16


    'fonctions SSV techniques
    Public Declare Function SSV_InitLIB Lib "SSVW32.DLL" () As UInt16
    Public Declare Function SSV_TermLIB Lib "SSVW32.DLL" () As UInt16
    Public Declare Function SSV_AllouerZoneMem Lib "SSVW32.DLL" (ByRef ZDonneesSortie As Integer, ByVal TailleDonneesEntree As UInt32) As UInt16

    'fonctions SIS techniques
    Public Declare Function SIS_InitTrace Lib "SSvW32.DLL" (ByVal NomFichier As String, ByVal ModeOuverture As String, ByVal Module_ As UInt16, ByVal niveau As Byte) As UInt16


    'fonctions SIS d’accès aux données
    Public Declare Function SIS_LireCartePS Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_LireDroitsVitale Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal DateConsultation As String, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_FormaterFactures Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal FacturesACreer As Char, ByVal ModeSecur As Char, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_FormaterLot Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_FormaterFichier Lib "SSvW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_TraduireARL Lib "SSvW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_SecuriserFacture Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal NologSituation As Char, ByVal NumFacturation As String, ByVal NumeroSession As UInt16) As UInt16

    'fonctions STS
    Public Declare Function STS_InitLIB Lib "STSW32.DLL" () As UInt16
    Public Declare Function STS_InitTrace Lib "STSW32.DLL" (ByVal NomFichier As String, ByVal ModeOuverture As String, ByVal Module_ As UInt16, ByVal niveau As Byte) As UInt16
    Public Declare Function STS_Tarification_S Lib "STSW32.DLL" (ByVal MotifAppel As Char, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function STS_Assistance_S Lib "STSW32.DLL" (ByVal MotifAppel As Char, ByVal PorteeAppel As UInt16, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function STS_LireVersion_S Lib "STSW32.DLL" (ByVal NumeroSession As UInt16) As UInt16

    'fonctions SRT
    Public Declare Function SRT_InitLIB Lib "SRTW32.DLL" () As UInt16
    Public Declare Function SRT_ControleComplet_S Lib "SRTW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SRT_LireVersion_S Lib "SRTW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SRT_ConsulterDonnee_S Lib "SRTW32.DLL" (ByVal Identifiant As String, ByVal DateReference As String, ByVal NumeroSession As UInt16) As UInt16

    'Fonctions de gestion de configuration
    Public Declare Function SIS_LireConfig Lib "SSvW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_LireDateLecteur Lib "SSvW32.DLL" (ByVal NomRessourceLecteur As String, ByVal DateHeure As String) As UInt16
    Public Declare Function SIS_MajDateLecteur Lib "SSvW32.DLL" (ByVal NomRessourceLecteur As String, ByVal DateHeure As String) As UInt16
    Public Declare Function SIS_ChargerAppli Lib "SSvW32.DLL" (ByVal NomRessourceLecteur As String, ByVal NumeroSession As UInt16) As UInt16

#End Region
#Region "MY FONCTIONS SESAM VITALE"
    Public Trace_Compteur_Groupe As Integer
    Public Trace_Compteur_Champs_dans_groupe As Integer
    Public Trace_Compteur_Champs_total As Integer
    Public FichierTrace As String
    Public Sub Trace_Reset_compteur()
        Trace_Compteur_Groupe = 0
        Trace_Compteur_Champs_dans_groupe = 0
        Trace_Compteur_Champs_total = 0
    End Sub


    Public Function SGD_AjouterGroupe_Tracé(ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal Visu_API As Boolean, ByVal Fichier_Trace As String) As UInt16
        Dim rep As String = Mid(Fichier_Trace, 1, InStrRev(Fichier_Trace, "\") - 1)
        If My.Computer.FileSystem.DirectoryExists(rep) = False Then
            My.Computer.FileSystem.CreateDirectory(rep)
        End If
        Trace_Compteur_Groupe = Trace_Compteur_Groupe + 1
        Trace_Compteur_Champs_dans_groupe = 0
        current_Groupe = IdGroupe
        If Visu_API = True Then 'avec trace
            Using sw As New StreamWriter(Fichier_Trace, True, Encoding.Default)
                Dim line As String
                line = "Groupe " + IdGroupe.ToString
                While line.Length < 15
                    line = line + " "
                End While
                line = line + "(" + Trace_Compteur_Groupe.ToString + ")"
                sw.WriteLine()
                sw.WriteLine(line)
                Return SGD_AjouterGroupe(NumeroSession, IdGroupe)
            End Using
        Else 'sans trace
            Return SGD_AjouterGroupe(NumeroSession, IdGroupe)
        End If
    End Function

    Public Function SGD_AjouterChamp_Tracé(ByVal NumeroSession As UInt16, ByRef ValeurChamp As String, ByVal Visu_API As Boolean, ByVal Fichier_Trace As String, Optional ByVal NumPrestation As Integer = 0) As UInt16
        Trace_Compteur_Champs_dans_groupe = Trace_Compteur_Champs_dans_groupe + 1
        Trace_Compteur_Champs_total = Trace_Compteur_Champs_total + 1
        Dim from_sts As Boolean = False
        Dim tops As String = ""
        If Tab_Valeur_STS.Length > 1 Then
            For i = 0 To Tab_Valeur_STS.Length - 1
                If NumPrestation = 0 Then
                    If Tab_Valeur_STS(i).groupe = current_Groupe And Tab_Valeur_STS(i).champ = Trace_Compteur_Champs_dans_groupe Then
                        ValeurChamp = Tab_Valeur_STS(i).valeur
                        from_sts = True
                        tops = Tab_Valeur_STS(i).affichage + Tab_Valeur_STS(i).modification
                        Exit For
                    End If
                Else
                    If Tab_Valeur_STS(i).groupe = current_Groupe And Tab_Valeur_STS(i).champ = Trace_Compteur_Champs_dans_groupe And Tab_Valeur_STS(i).NumPrestation = NumPrestation Then
                        ValeurChamp = Tab_Valeur_STS(i).valeur
                        from_sts = True
                        tops = Tab_Valeur_STS(i).affichage + Tab_Valeur_STS(i).modification
                        Exit For
                    End If
                End If
            Next
        End If

        If Visu_API = True Then 'avec trace
            Using sw As New StreamWriter(Fichier_Trace, True, Encoding.Default)
                Dim line As String
                line = Trace_Compteur_Champs_dans_groupe.ToString
                While line.Length < 2
                    line = " " + line
                End While
                line = line + ": " + ValeurChamp
                While line.Length < 25
                    line = line + " "
                End While
                line = line + "(" + Trace_Compteur_Champs_total.ToString + ")"
                If from_sts = True Then
                    line = line + "(sts)" + tops
                End If
                sw.WriteLine(line)
                Return SGD_AjouterChamp(NumeroSession, ValeurChamp)
            End Using
        Else 'sans trace
            Return SGD_AjouterChamp(NumeroSession, ValeurChamp)
        End If
    End Function
    Public Function SGD_AjouterChampBin_Tracé(ByVal NumeroSession As UInt16, ByRef MyByte As Byte, ByVal Visu_API As Boolean, ByVal Fichier_Trace As String, Optional ByVal NumPrestation As Integer = 0) As UInt16
        Trace_Compteur_Champs_dans_groupe = Trace_Compteur_Champs_dans_groupe + 1
        Trace_Compteur_Champs_total = Trace_Compteur_Champs_total + 1

        If Visu_API = True Then 'avec trace
            Using sw As New StreamWriter(Fichier_Trace, True, Encoding.Default)
                Dim line As String
                line = Trace_Compteur_Champs_dans_groupe.ToString
                While line.Length < 2
                    line = " " + line
                End While
                line = line + ": Binaire"
                While line.Length < 25
                    line = line + " "
                End While
                line = line + "(" + Trace_Compteur_Champs_total.ToString + ")"

                sw.WriteLine(line)
                Return SGD_AjouterChampBin(NumeroSession, MyByte, 1)
            End Using
        Else 'sans trace
            Return SGD_AjouterChampBin(NumeroSession, MyByte, 1)
        End If
    End Function
#End Region
#Region "Variables"

    Public Chemin_application As String 'chemin du repertoire de l'application

    Public Visu_API As Boolean 'issu de CNDA.xml 

    Public NomRessourcePS As String
    Public NomRessourceLecteur As String

    Public NumeroSessionCPS As UInt16
    Public Occurence_Grp2 As UInt16
    Public NumeroSessionVitale As UInt16
    Public NumeroSessionFacture As UInt16
    Public NumeroSessionLot As UInt16
    Public NumeroSessionFichier As UInt16
    Public NumeroSessionARL As UInt16
    Public NuméroSessionSTS As UInt16
    Public NuméroSessionSRT As UInt16

    Public ValeurChamp As String
    Public TailleMax As UInt32

    'Tables
    Public FicCodesSpecialités As String

    Public CurrentBenéficiaire As Benéficiaire
    Public CurrentFactureVitale As FactureVitale
    Public CurrentFactureVenteDirecte As FactureVenteDirecte
    Public CurrentConvention As Convention

    Public tab_Lignes_Vente() As Ligne_Vente

    'tableau code spécialité
    Public tabCodeSpécialité() As CodeSpécialité


#End Region
#Region "DECLARATIONS DE TYPES"
    'type code spécialité
    Public Structure CodeSpécialité
        Dim valeur As String
        Dim signification As String
    End Structure

    'type prestation
    Public Structure Prestation
        Dim Code As String
        Dim Libellé As String
        Dim TauxAMO As Integer
        Dim TauxAMC As Integer
    End Structure

    'type FactureVitale
    Public Structure FactureVitale
        Public Sub Clear(ByVal Clear_DETAIL_Ligne_Vente As Boolean)
            num = 0
            Bénéficiaire = ""
            Assuré = ""
            CRLdeFSE = ""
            CRLdeDRE = ""

            G1110C1 = ""
            G1110C2 = ""
            G1110C3 = ""
            G1110C4 = ""
            G1110C5 = ""
            G1110C6 = ""

            G1120C1 = ""
            G1120C2 = ""
            G1120C3 = ""
            G1120C4 = ""
            G1120C5 = ""
            G1120C6 = ""
            G1120C7 = ""
            G1120C8 = ""
            G1120C9 = ""
            G1120C10 = ""
            G1120C11 = ""
            G1120C12 = ""
            G1120C13 = ""
            G1120C14 = ""

            G1130C1 = ""
            G1130C2 = ""
            G1130C3 = ""
            G1130C4 = ""
            G1130C5 = ""
            G1130C6 = ""
            G1130C7 = ""
            G1130C8 = ""
            G1130C9 = ""

            G1140C1 = ""
            G1140C2 = ""
            G1140C3 = ""

            G1150C1 = ""
            G1150C2 = ""
            G1150C3 = ""
            G1150C4 = ""
            G1150C5 = ""

            G1160C1 = ""
            G1160C2 = ""

            G1170C1 = ""

            G1211C1 = ""
            G1211C2 = ""
            G1211C3 = ""
            G1211C4 = ""
            G1211C5 = ""
            G1211C6 = ""
            G1211C7 = ""

            G1213C1 = ""
            G1213C2 = ""
            G1213C3 = ""
            G1213C4 = ""
            G1213C5 = ""
            G1213C6 = ""
            G1213C7 = ""
            G1213C8 = ""

            G1214C1 = ""
            G1214C2 = ""
            G1214C3 = ""
            G1214C4 = ""
            G1214C5 = ""
            G1214C6 = ""
            G1214C7 = ""
            G1214C8 = ""

            G1230C1 = ""

            G1310C1 = ""
            G1310C2 = ""
            G1310C3 = ""
            G1310C4 = ""
            G1310C5 = ""

            G1321C1 = ""
            G1321C2 = ""
            G1321C3 = ""
            G1321C4 = ""
            G1321C5 = ""
            G1321C6 = ""
            G1321C7 = ""
            G1321C8 = ""
            G1321C9 = ""
            G1321C10 = ""
            G1321C11 = ""
            G1321C12 = ""
            G1321C13 = ""

            G1330C1 = ""
            G1330C2 = ""
            G1330C3 = ""

            G1410C1 = ""
            G1410C2 = ""

            G1420C1 = ""
            G1420C2 = ""
            G1420C3 = ""

            G1440C1 = ""
            G1440C2 = ""
            G1440C3 = ""

            G1511C1 = ""
            G1511C2 = ""

            G1512C1 = ""

            G1513C1 = ""
            G1513C2 = ""
            G1513C3 = ""

            G1514C1 = ""
            G1514C2 = ""
            G1514C3 = ""
            G1514C4 = ""

            G1515C1 = ""

            G1910C1 = 0
            G1910C2 = 0
            G1910C3 = 0
            G1910C4 = 0
            G1910C5 = 0
            G1910C6 = 0

            G3700C1 = ""
            G3700C2 = ""

            G3730C1 = ""

            IDPrescripteur = ""
            FactureAcree = ""
            ModeSecur = ""
            ReDim TabLigneFacture(0)
            TP_AMO = False
            TP_AMC = False
            TOP_CMU = False
            Sortant_CMU = False
            'GestionUnique = False
            Mode_Gestion = ""

            If Clear_DETAIL_Ligne_Vente = True Then
                ReDim G1840(0)
                PEC.clear()
                ReDim G1740C7(0)
                ReDim Forçage_Part_AMO(0)
                ReDim G1741(0)
            End If

        End Sub
        Dim num As Integer
        Dim Bénéficiaire As String
        Dim Assuré As String
        Dim CRLdeFSE As String
        Dim CRLdeDRE As String

        Dim G1110C1 As String 'N° de facture
        Dim G1110C2 As String
        Dim G1110C3 As String
        Dim G1110C4 As String
        Dim G1110C5 As String
        Dim G1110C6 As String

        Dim G1120C1 As String
        Dim G1120C2 As String
        Dim G1120C3 As String
        Dim G1120C4 As String
        Dim G1120C5 As String
        Dim G1120C6 As String
        Dim G1120C7 As String
        Dim G1120C8 As String
        Dim G1120C9 As String
        Dim G1120C10 As String
        Dim G1120C11 As String
        Dim G1120C12 As String
        Dim G1120C13 As String
        Dim G1120C14 As String

        Dim G1130C1 As String
        Dim G1130C2 As String
        Dim G1130C3 As String
        Dim G1130C4 As String
        Dim G1130C5 As String
        Dim G1130C6 As String
        Dim G1130C7 As String
        Dim G1130C8 As String
        Dim G1130C9 As String

        Dim G1140C1 As String
        Dim G1140C2 As String
        Dim G1140C3 As String

        Dim G1150C1 As String
        Dim G1150C2 As String
        Dim G1150C3 As String
        Dim G1150C4 As String
        Dim G1150C5 As String

        Dim G1160C1 As String
        Dim G1160C2 As String

        Dim G1170C1 As String

        Dim G1211C1 As String
        Dim G1211C2 As String
        Dim G1211C3 As String
        Dim G1211C4 As String
        Dim G1211C5 As String
        Dim G1211C6 As String
        Dim G1211C7 As String

        Dim G1213C1 As String
        Dim G1213C2 As String
        Dim G1213C3 As String
        Dim G1213C4 As String
        Dim G1213C5 As String
        Dim G1213C6 As String
        Dim G1213C7 As String
        Dim G1213C8 As String

        Dim G1214C1 As String
        Dim G1214C2 As String
        Dim G1214C3 As String
        Dim G1214C4 As String
        Dim G1214C5 As String
        Dim G1214C6 As String
        Dim G1214C7 As String
        Dim G1214C8 As String

        Dim G1230C1 As String

        Dim G1310C1 As String
        Dim G1310C2 As String
        Dim G1310C3 As String
        Dim G1310C4 As String
        Dim G1310C5 As String

        Dim G1321C1 As String
        Dim G1321C2 As String
        Dim G1321C3 As String
        Dim G1321C4 As String
        Dim G1321C5 As String
        Dim G1321C6 As String
        Dim G1321C7 As String
        Dim G1321C8 As String
        Dim G1321C9 As String
        Dim G1321C10 As String
        Dim G1321C11 As String
        Dim G1321C12 As String
        Dim G1321C13 As String

        Dim G1330C1 As String
        Dim G1330C2 As String
        Dim G1330C3 As String

        Dim G1410C1 As String
        Dim G1410C2 As String

        Dim G1420C1 As String
        Dim G1420C2 As String
        Dim G1420C3 As String

        Dim G1440C1 As String
        Dim G1440C2 As String
        Dim G1440C3 As String

        Dim G1450C1 As String
        Dim G1450C2 As String

        Dim G1511C1 As String
        Dim G1511C2 As String

        Dim G1512C1 As String

        Dim G1513C1 As String
        Dim G1513C2 As String
        Dim G1513C3 As String

        Dim G1514C1 As String
        Dim G1514C2 As String
        Dim G1514C3 As String
        Dim G1514C4 As String

        Dim G1515C1 As String

        'Dim G1850C2 As String

        Dim G1910C1 As Single
        Dim G1910C2 As Single
        Dim G1910C3 As Single
        Dim G1910C4 As Single
        Dim G1910C5 As Single
        Dim G1910C6 As Single

        Dim G3700C1 As String
        Dim G3700C2 As String

        Dim G3730C1 As String

        Dim IDPrescripteur As String
        Dim FactureAcree As String
        Dim ModeSecur As String
        Dim TabLigneFacture() As LigneFactureVitale
        Dim G1840 As G1840()
        Dim G1740C7() As String
        Dim TP_AMO As Boolean
        Dim TP_AMC As Boolean
        Dim TOP_CMU As Boolean
        Dim Sortant_CMU As Boolean
        'Dim GestionUnique As Boolean
        Dim Mode_Gestion As String
        Dim PEC As PEC
        Dim Forçage_Part_AMO() As Forçage_Part_AMO
        Dim G1741() As G1741

    End Structure
    Public Structure LigneFactureVitale

        Dim G1610C1 As String
        Dim G1610C2 As String
        Dim G1610C3 As String
        Dim G1610C4 As String
        Dim G1610C5 As String
        Dim G1610C6 As Single
        Dim G1610C7 As String
        Dim G1610C8 As String
        Dim G1610C9 As String
        Dim G1610C10 As String
        Dim G1610C11 As Single
        Dim G1610C12 As Single
        Dim G1610C13 As Single
        Dim G1610C14 As Single
        Dim G1610C15 As Single
        Dim G1610C16 As Single

        Dim DétailLpp As DétailLpp()
        Dim DétailCodeCIP As DétailCodeCIP

        Dim G1820C2 As String

        Dim G1840C2 As String
        Dim G1840C3 As String
        Dim G1840C4 As String

        Dim G1850C2 As String

        Dim G2000C2 As String

        Dim G2010C2 As String

        Dim G2030C2 As String
        Dim G2030C3 As String

        Dim G3710C2 As String
        Dim G3710C3 As String
        Dim G3710_Paramètes As String
    End Structure
    Public Structure PEC_Montant_Acte
        Dim Num_Acte As Integer
        Dim Montant As Integer
    End Structure
    Public Structure PEC
        Dim MontantGlobal As Integer
        Dim Reste_Ventilation_Montant_Global As Integer
        Dim Reste_Ventilation_Montant_Global_STS As Integer
        Dim Montants_Actes() As PEC_Montant_Acte
        Public Sub clear()
            MontantGlobal = 0
            Reste_Ventilation_Montant_Global = 0
            Reste_Ventilation_Montant_Global_STS = 0
            ReDim Montants_Actes(0)
        End Sub
    End Structure
    Public Structure G1840 'ENTENTE PREALABLE
        Dim G1840C1 As Integer 'N° de la prestation (de rattachement)
        Dim G1840C2 As String 'Code accord entente préalable
        Dim G1840C3 As String 'Date d’envoi de la demande d’entente préalable
    End Structure
    Public Structure Forçage_Part_AMO
        Dim Num_Acte As Integer
        Dim Montant As Integer
    End Structure
    Public Structure G1741
        Dim G1741C1 As Integer
        Dim G1741C2 As Integer
        Dim G1741C3 As String
        Dim G1741C4 As String
        Dim G1741C5 As String
        Dim G1741C6 As String
    End Structure




    'type FactureVenteDirecte
    Public Structure FactureVenteDirecte
        Public Sub Clear()
            NumVenteDirecte = 0
            Nir = ""
            Nom = ""
            Prénom = ""
            Date_ = ""
            Total = 0
            ReDim lignes(0)
        End Sub
        Dim NumVenteDirecte As Integer
        Dim Nir As String
        Dim Nom As String
        Dim Prénom As String
        Dim Date_ As String
        Dim Total As Single
        Dim lignes As LigneFactureVenteDirecte()
    End Structure
    Public Structure LigneFactureVenteDirecte
        Dim NumActe As Integer
        Dim CIP As String
        Dim EAN13 As String
        Dim PrixUnitaire As Double
        Dim Quantité As Integer
        Dim Remise As Double
        Dim Total As Double

    End Structure

    'type DétailLpp
    Public Structure DétailLpp
        Dim G1730C1 As String
        Dim G1730C2 As String
        Dim G1730C3 As String
        Dim G1730C4 As String
        Dim G1730C5 As String
        Dim G1730C6 As String
        Dim G1730C7 As String
        Dim G1730C8 As String
        Dim G1730C9 As String
        Dim G1730C10 As String
        Dim G1730C11 As String
    End Structure

    'type DétailCodeCIP
    Public Structure DétailCodeCIP

        Dim G1740C1 As String
        Dim G1740C2 As String
        Dim G1740C3 As String
        Dim G1740C4 As Single
        Dim G1740C5 As String
        Dim G1740C6 As String
        Dim G1740C7 As String
        Dim G1740C8 As String
        Dim G1740C9 As String
        Dim G1740C10 As String
        Dim G1740C11 As String
        Dim G1740C12 As String
        Dim G1740C13 As String
        Dim G1740C14 As String
        Dim G1740C15 As String

    End Structure

    'Benéficiaire
    Public Structure Benéficiaire

        Public Sub clear()
            G101C1 = ""
            G101C2 = ""
            G101C3 = ""
            G101C4 = ""
            G101C5 = ""
            G101C6 = ""
            G101C7 = ""
            G101C8 = ""
            G101C9 = ""
            G101C10 = ""
            G101C11 = ""
            G101C12 = ""
            G101C13 = ""
            G101C14 = ""
            G102C1 = ""
            G102C2 = ""
            G102C3 = ""
            G103C1 = ""
            G103C2 = ""
            G103C3 = ""
            G103C4 = ""
            G103C5 = ""
            G103C6 = ""
            G103C7 = ""
            G103C8 = ""
            G103C9 = ""
            G104C1 = ""
            G104C2 = ""
            G104C3 = ""
            G104C4 = ""
            G104C5 = ""
            G104C6 = ""
            G104C7 = ""
            G104C8 = ""
            G104C9 = ""
            G104C10 = ""
            G104C11 = ""
            G104C12 = ""
            G104C13 = ""
            G104C14 = ""
            G104C15 = ""
            G104C16 = ""
            G104C17 = ""
            G104C18 = ""
            G107C1 = ""
            G107C2 = ""
            G107C3 = ""
            G107C4 = ""
            G107C5 = ""
            G107C6 = ""
            G109C1 = ""
            G109C2 = ""
            G109C3 = ""
            G109C4 = ""
            G109C5 = ""
            G109C6 = ""
            G109C7 = ""
            G109C8 = ""
            G109C9 = ""
            G109C10 = ""
            G109C11 = ""
            G109C12 = ""
            G111C1 = ""
            IDPrescripteur = ""
            AMC_NumOrganisme = ""
            AMC_NumAdherent = ""
            AMC_DateDébut = ""
            AMC_DateFin = ""
            AMC_Piecejustificative = ""
            AMC_TypeContrat = ""
            AMC_NumMutuelle = ""
            AMC_IDassure = ""
            AMC_Code_Aiguillage_STS = ""
            AMC_Indicateurdetrairement = ""
            AMC_CodeRoutage = ""
            AMC_IdHote = ""
            AMC_NomDomaine = ""
            AMC_Type_Convention = ""
            AMC_Critère_secondaire = ""
            AMC_IdentifiantAMC = ""
            ReDim G105C1(0)
            ReDim G105C2(0)
            ReDim G106C1(0)
            ReDim G106C2(0)
            ReDim G106C3(0)
            ReDim G106C4(0)
            ReDim G108C1(0)
            ReDim G108C2(0)
            Assuré = ""
            G1420C1 = ""
            G1420C2 = ""
            G1420C3 = ""
            G1511C2 = ""
        End Sub

        'Groupe 101
        Dim G101C1 As String 'Type de carte Vitale
        Dim G101C2 As String 'N° de série de la carte Vitale
        Dim G101C3 As String 'Date de fin de validité carte Vitale
        Dim G101C4 As String 'Données administration carte RUF1
        Dim G101C5 As String 'Données administration carte RUF2
        Dim G101C6 As String 'Données RUF administration
        Dim G101C7 As String 'Type d'identification du porteur de la carte
        Dim G101C8 As String 'NIR
        Dim G101C9 As String 'Clé du NIR
        Dim G101C10 As String 'Code régime
        Dim G101C11 As String 'Caisse gestionnaire
        Dim G101C12 As String 'Centre gestionnaire
        Dim G101C13 As String 'Code gestion
        Dim G101C14 As String 'Données RUF Famille

        'Groupe 102
        Dim G102C1 As String 'Code service AMO Famille
        Dim G102C2 As String 'Date de début du service AMO Famille
        Dim G102C3 As String 'Date de fin du service AMO Famille

        'Groupe 103
        Dim G103C1 As String 'Organisme gestionnaire du risque AT
        Dim G103C2 As String 'Code AT BGDH
        Dim G103C3 As String 'Identifiant AT
        Dim G103C4 As String 'Organisme gestionnaire AT1
        Dim G103C5 As String 'Code AT1 BGDH
        Dim G103C6 As String 'Identifiant AT1
        Dim G103C7 As String 'Organisme gestionnaire AT2
        Dim G103C8 As String 'Code AT2 BGDH
        Dim G103C9 As String 'Identifiant AT2

        'Groupe 104
        Dim G104C1 As String 'Nom usuel du bénéficiaire
        Dim G104C2 As String 'Nom de famille du bénéficiaire
        Dim G104C3 As String 'Prénom du bénéficiaire
        Dim G104C4 As String 'Adresse ligne 1
        Dim G104C5 As String 'Adresse ligne 2
        Dim G104C6 As String 'Adresse ligne 3
        Dim G104C7 As String 'Adresse ligne 4
        Dim G104C8 As String 'Adresse ligne 5
        Dim G104C9 As String 'NIR certifié
        Dim G104C10 As String 'Clé NIR certifié
        Dim G104C11 As String 'Date de certification du NIR
        Dim G104C12 As String 'Date de naissance du bénéficiaire
        Dim G104C13 As String 'Rang de naissance
        Dim G104C14 As String 'Qualité
        Dim G104C15 As String 'Code service AMO bénéficiaire
        Dim G104C16 As String 'Date de début du service AMO bénéficiaire
        Dim G104C17 As String 'Date de fin du service AMO bénéficiaire
        Dim G104C18 As String 'Données RUF AMO bénéficiaire

        'Groupe 105
        Dim G105C1() As String 'Date de début droits AMO
        Dim G105C2() As String 'Date de fin droits AMO

        'Groupe 106
        Dim G106C1() As String 'Date de début code couverture
        Dim G106C2() As String 'Date de fin code couverture
        Dim G106C3() As String 'Code ALD
        Dim G106C4() As String 'Code situation

        'Groupe 107
        Dim G107C1 As String 'Identification Mutuelle
        Dim G107C2 As String 'Garanties effectives
        Dim G107C3 As String 'Indicateur de traitement mutuelle
        Dim G107C4 As String 'Type de services associés
        Dim G107C5 As String 'Services associés au contrat
        Dim G107C6 As String 'Code aiguillage STS

        'Groupe 108
        Dim G108C1() As String 'Date de début droits mutuelle
        Dim G108C2() As String 'Date de fin droits mutuelle

        'Groupe 109
        Dim G109C1 As String 'N° de complémentaire B2
        Dim G109C2 As String 'N° de complémentaire EDI
        Dim G109C3 As String 'N° d’adhérent AMC
        Dim G109C4 As String 'Indicateur de traitement AMC
        Dim G109C5 As String 'Date de début de validité de présence des données AMC
        Dim G109C6 As String 'Date de fin de validité de présence des données AMC
        Dim G109C7 As String 'Code de routage flux AMC
        Dim G109C8 As String 'Identifiant d’hôte
        Dim G109C9 As String 'Nom de domaine AMC
        Dim G109C10 As String 'Code aiguillage STS
        Dim G109C11 As String 'Type de services associés
        Dim G109C12 As String 'Services associés au contrat

        'Groupe 111
        Dim G111C1 As String 'Données RUF bénéficiaire complémentaire

        'Prescripteur
        Dim IDPrescripteur As String

        'données AMC 
        Dim AMC_NumOrganisme As String
        Dim AMC_NumAdherent As String
        Dim AMC_DateDébut As String
        Dim AMC_DateFin As String
        Dim AMC_Piecejustificative As String
        Dim AMC_TypeContrat As String
        Dim AMC_Indicateurdetrairement As String
        Dim AMC_NumMutuelle As String
        Dim AMC_IDassure As String
        Dim AMC_Code_Aiguillage_STS As String
        Dim AMC_CodeRoutage As String
        Dim AMC_IdHote As String
        Dim AMC_NomDomaine As String
        Dim AMC_Type_Convention As String
        Dim AMC_Critère_secondaire As String
        Dim AMC_IdentifiantAMC As String

        'Assuré(nom prénom)
        Dim Assuré As String

        'Groupe1420 Identification de pièce justificative pour l’AMO (pour mode dégradé)
        Dim G1420C1 As String 'Nature de la pièce justificative
        Dim G1420C2 As String 'Date de validité de la pièce
        Dim G1420C3 As String 'Origine de la pièce justificative

        'Indicateur Régime Alsace - Moselle(
        Dim G1511C2 As String
    End Structure

    'ligne vente
    Public Structure Ligne_Vente

        Dim Ligne_traitée As Boolean

        Dim liste As String
        Dim deconditionement As Boolean
        Dim deconditionement_prix_unitaire As Integer
        Dim deconditionement_quantité As Integer
        Dim deconditionement_NmbreBoites As Integer

        'Entente Préalable G1840 optionel
        Dim Entente_Préalable_code_accord As String
        Dim Entente_Préalable_date_envoi_demande As String

    End Structure

    'type convention
    Public Structure Convention
        Public Sub clear()
            selected = False
            Code_action = ""
            Code_catégorie = ""
            Spécialité = ""
            Référence_de_convention = ""
            Message = ""
            Identifiant_org_signataire = ""
            Libellé_org_signataire = ""
            indicateur_convention_groupée = ""
            type_Identifiant_org_signataire = ""
            critère_secondaire = ""
            type_Accord = ""
            Num_AMC = ""
            libellé_Org_complémentaire = ""
            indic_desactivation_STS = ""
            Code_aiguillage_STS = ""
            usage_attestation_papier = ""
            Accepatation_DRE_Annulation = ""
            Acceptation_DRE_Rectification = ""
            Identifiant_Opérateur_règlement = ""
            Code_routage = ""
            identifiant_hôte = ""
            nom_domaine = ""
        End Sub
        Dim selected As Boolean
        Dim Code_action As String
        Dim Code_catégorie As String
        Dim Spécialité As String
        Dim Référence_de_convention As String
        Dim Message As String
        Dim Identifiant_org_signataire As String
        Dim Libellé_org_signataire As String
        Dim indicateur_convention_groupée As String
        Dim type_Identifiant_org_signataire As String
        Dim critère_secondaire As String
        Dim type_Accord As String
        Dim Num_AMC As String
        Dim libellé_Org_complémentaire As String
        Dim indic_desactivation_STS As String
        Dim Code_aiguillage_STS As String
        Dim usage_attestation_papier As String
        Dim Accepatation_DRE_Annulation As String
        Dim Acceptation_DRE_Rectification As String
        Dim Identifiant_Opérateur_règlement As String
        Dim Code_routage As String
        Dim identifiant_hôte As String
        Dim nom_domaine As String


    End Structure


#Region "STS"
    Public current_Groupe As Integer

    Public Structure Valeur_STS
        Dim groupe As Integer
        Dim occurence As Integer
        Dim champ As Integer
        Dim valeur As String
        Dim affichage As String
        Dim modification As String
        Dim NumPrestation As Integer
    End Structure
    Public Tab_Valeur_STS() As Valeur_STS

    Public Structure formule_STS
        Dim selected As Boolean
        Dim Numéro As String
        Dim Libellé As String
        Dim nombre_de_paramètres As Integer
        Dim paramètres() As Paramètre_formule_STS
        Dim num_prestation_de_rattachement As String
        Dim pour_toutes_prestations As Boolean

        Public Structure Paramètre_formule_STS
            Dim numéro As Integer
            Dim Libellé As String
            Dim Type As String
            Dim valeur_par_defaut As String
            Dim valeur_affectée As String
        End Structure

        Public Sub Clear()
            selected = False
            Numéro = ""
            Libellé = ""
            nombre_de_paramètres = 0
            ReDim paramètres(-1)
            num_prestation_de_rattachement = ""
            pour_toutes_prestations = False
        End Sub

    End Structure
    Public current_formule_STS As formule_STS
    Public tab_current_formule_STS() As formule_STS
#End Region


    'Accident Travail g103- As string g1310, g1513
    Public Structure AccidentDuTravail
        Dim DateAT As String
        Dim NumAT As String
        Dim CléAT As String
        Dim CodeRégime, CaisseGest, CentreGest As String
        Dim selected As Boolean
        Public Sub clear()
            DateAT = ""
            NumAT = ""
            CléAT = ""
            CodeRégime = ""
            CaisseGest = ""
            CentreGest = ""
            selected = False
        End Sub
    End Structure
    Public current_AT As AccidentDuTravail


    'CONFIG
    Public Structure Configuration

        Dim Logiciel_ModeFonctionement As String ' Demo, Test, Réel

        Dim SMTP_From As String
        Dim SMTP_VersionCDC As String
        Dim SMTP_CheminSource As String
        Dim SMTP_CheminDepot As String
        Dim SMTP_CheminSauvegarde As String
        Dim SMTP_Message_ID As String
        Dim SMTP_TypeEmetteurFichier As String
        Dim SMTP_NumEmetteurFichier As String
        Dim SMTP_MessageFormatFichier As String
        Dim SMTP_CompresserDonnees As String
        Dim SMTP_Postmaster As String
        Dim SMTP_Activer_Serveur_Local As Boolean
        Dim SMTP_Serveur_Externe As String
        Dim SMTP_Serveur_Externe_port As Integer

        Dim POP3_Serveur As String
        Dim POP3_Port As String
        Dim POP3_User As String
        Dim POP3_Password As String
        Dim POP3_RepBAL As String

        Dim OCT_UtilisationOCT As Boolean
        Dim OCT_AdressemailOCT As String
        Dim OCT_TypeDestinataire As String
        Dim OCT_Application As String
        Dim OCT_FSEenrichies As Boolean
        Dim OCT_FSE_FichierUnique As Boolean
        Dim OCT_FSE_Eclatement_Source As Boolean


        Dim GALSS_NomRessourcePS As String
        Dim GALSS_NomRessourceLecteur As String

        Dim Configuration_Desynchroniser As Boolean

        Dim Repertoires_RepertoireFichiers As String
        Dim Repertoires_RepertoirePickup As String

        Dim Data_PMSS As String
        Dim Data_ContaceptifUrgence_NIR As String
        Dim Data_ContaceptifUrgence_cle As String
        Dim Data_ContaceptifUrgence_datenaissance As String
        Dim Data_ContaceptifUrgence_NumPrecripteur As String
        Dim Data_ContaceptifUrgence_CleNumPrecripteur As String
        Dim Data_ContaceptifUrgence_ContraceptifCIP As String
        Dim Data_ContaceptifUrgence_CaisseGest As String
        Dim Data_ContaceptifUrgence_CentreGest As String

        Dim Conventions_Activer As Boolean

        Dim STS_Activer As Boolean
        Dim STS_AfficheDiagNiv1 As Boolean

        Dim Titulaire_Num_Id_Nat As String
        Dim Titulaire_Cle_Num_Id_Nat As String
        Dim Titulaire_Num_Id_Facturation As String
        Dim Titulaire_Cle_Num_Id_Facturation As String
        Dim Titulaire_Nom As String
        Dim Titulaire_Prenom As String
        Dim Titulaire_Code_Conventionnel As String
        Dim Titulaire_Code_specialite As String
        Dim Titulaire_Code_Zone_tarifaire As String
        Dim Titulaire_Code_Zone_IK As String
        Dim Titulaire_Code__Agrement_1 As String
        Dim Titulaire_Code__Agrement_2 As String
        Dim Titulaire_Code__Agrement_3 As String
        Dim Titulaire_Condition_Exercice As String
        Dim Titulaire_Num_RPPS As String
        Dim Titulaire_Cle_Num_RPPS As String
        Dim Titulaire_raison_sociale As String
        Dim Titulaire_Num_log_situ_fact As Byte
        Dim Activer_Session_Remplacement As Boolean
        Dim Remplacant_Num_Id_Nat As String
        Dim Remplacant_Cle_Num_Id_Nat As String
        Dim Remplacant_Num_Id_Facturation As String
        Dim Remplacant_Cle_Num_Id_Facturation As String

        Dim MessageFormatFichier As String
        Dim Type_émetteur_fichier As String
        Dim num_émetteur_fichier As String

        'LOI
        Dim LOI_Pop3_Serveur As String
        Dim LOI_Pop3_Port As String
        Dim LOI_Pop3_User As String
        Dim LOI_Pop3_Password As String
        Dim LOI_Pop3_BAL As String
        Dim LOI_Pop3_RepBAL As String
        Dim LOI_Distr_OCT As String
        Dim LOI_Distr_horsOCT As String
        Dim LOI_Activer As Boolean
        Dim LOI_Ref As String
        Dim LOI_NB_JOUR_Max As Integer
        Dim LOI_Demande_Auto As Boolean
        Dim LOI_Controle_MAJ_mensuel As Boolean
        Dim LOI_Verif_InReply_To As Boolean
        Dim LOI_Controle_Correspondance As Boolean
        Dim LOI_code_resultat_incr_prec As String
        Dim LOI_smtp_serveur As String
        Dim LOI_smtp_serveur_port As Integer
        Dim LOI_cert_nums As String
        Dim LOI_clé_GIP_CPS As String




        Public Sub Load_Config_File()
            Dim ConfigXml As New XmlDocument
            Dim ConfigXMLelementliste As XmlNodeList
            ConfigXml.Load("config.xml")

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("SMTP")
            SMTP_From = ConfigXMLelementliste.Item(0).Item("From").InnerText
            SMTP_VersionCDC = ConfigXMLelementliste.Item(0).Item("VersionCDC").InnerText
            SMTP_CheminSource = ConfigXMLelementliste.Item(0).Item("CheminSource").InnerText
            SMTP_CheminDepot = ConfigXMLelementliste.Item(0).Item("CheminDepot").InnerText
            SMTP_CheminSauvegarde = ConfigXMLelementliste.Item(0).Item("CheminSauvegarde").InnerText
            SMTP_Message_ID = ConfigXMLelementliste.Item(0).Item("Message_ID").InnerText
            SMTP_TypeEmetteurFichier = ConfigXMLelementliste.Item(0).Item("TypeEmetteurFichier").InnerText
            SMTP_NumEmetteurFichier = ConfigXMLelementliste.Item(0).Item("NumEmetteurFichier").InnerText
            SMTP_MessageFormatFichier = ConfigXMLelementliste.Item(0).Item("MessageFormatFichier").InnerText
            SMTP_CompresserDonnees = ConfigXMLelementliste.Item(0).Item("CompresserDonnees").InnerText
            SMTP_Postmaster = ConfigXMLelementliste.Item(0).Item("Postmaster").InnerText
            MessageFormatFichier = ConfigXMLelementliste.Item(0).Item("MessageFormatFichier").InnerText
            Type_émetteur_fichier = ConfigXMLelementliste.Item(0).Item("TypeEmetteurFichier").InnerText
            num_émetteur_fichier = ConfigXMLelementliste.Item(0).Item("NumEmetteurFichier").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer_Serveur_Local").InnerText) = "OUI" Then
                SMTP_Activer_Serveur_Local = True
            Else
                SMTP_Activer_Serveur_Local = False
            End If
            SMTP_Serveur_Externe = ConfigXMLelementliste.Item(0).Item("Serveur_Externe").InnerText
            SMTP_Serveur_Externe_port = Val(ConfigXMLelementliste.Item(0).Item("Serveur_Externe_port").InnerText)

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Pop3")
            POP3_Serveur = ConfigXMLelementliste.Item(0).Item("Serveur").InnerText
            POP3_Port = ConfigXMLelementliste.Item(0).Item("Port").InnerText
            POP3_User = ConfigXMLelementliste.Item(0).Item("User").InnerText
            POP3_Password = ConfigXMLelementliste.Item(0).Item("Password").InnerText
            POP3_RepBAL = ConfigXMLelementliste.Item(0).Item("RepBAL").InnerText

            'OCT
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("OCT")
            If UCase(ConfigXMLelementliste.Item(0).Item("UtilisationOCT").InnerText) = "OUI" Then
                OCT_UtilisationOCT = True
            Else
                OCT_UtilisationOCT = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("FSEenrichies").InnerText) = "OUI" Then
                OCT_FSEenrichies = True
            Else
                OCT_FSEenrichies = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("FSE_FichierUnique").InnerText) = "OUI" Then
                OCT_FSE_FichierUnique = True
            Else
                OCT_FSEenrichies = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("FSE_Eclatement_Source").InnerText) = "OUI" Then
                OCT_FSE_Eclatement_Source = True
            Else
                OCT_FSE_Eclatement_Source = False
            End If
            OCT_AdressemailOCT = ConfigXMLelementliste.Item(0).Item("AdressemailOCT").InnerText
            OCT_TypeDestinataire = ConfigXMLelementliste.Item(0).Item("TypeDestinataire").InnerText
            OCT_Application = ConfigXMLelementliste.Item(0).Item("Application").InnerText

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("GALSS")
            GALSS_NomRessourcePS = ConfigXMLelementliste.Item(0).Item("NomRessourcePS").InnerText
            GALSS_NomRessourceLecteur = ConfigXMLelementliste.Item(0).Item("NomRessourceLecteur").InnerText

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Configuration")
            Config.Logiciel_ModeFonctionement = ConfigXMLelementliste.Item(0).Item("ModeFonctionnement").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("Desynchroniser").InnerText) = "OUI" Then
                Configuration_Desynchroniser = True
            Else
                Configuration_Desynchroniser = False
            End If

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Repertoires")
            Repertoires_RepertoireFichiers = ConfigXMLelementliste.Item(0).Item("RepertoireFichiers").InnerText
            Repertoires_RepertoirePickup = ConfigXMLelementliste.Item(0).Item("RepertoirePickup").InnerText

            'Data
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Data")
            Data_PMSS = ConfigXMLelementliste.Item(0).Item("PMSS").InnerText

            'ContaceptifUrgence
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("ContaceptifUrgence")
            Data_ContaceptifUrgence_NIR = ConfigXMLelementliste.Item(0).Item("NIR").InnerText
            Data_ContaceptifUrgence_cle = ConfigXMLelementliste.Item(0).Item("cle").InnerText
            Data_ContaceptifUrgence_datenaissance = ConfigXMLelementliste.Item(0).Item("datenaissance").InnerText
            Data_ContaceptifUrgence_NumPrecripteur = ConfigXMLelementliste.Item(0).Item("NumPrecripteur").InnerText
            Data_ContaceptifUrgence_CleNumPrecripteur = ConfigXMLelementliste.Item(0).Item("CleNumPrecripteur").InnerText
            Data_ContaceptifUrgence_ContraceptifCIP = ConfigXMLelementliste.Item(0).Item("ContraceptifCIP").InnerText
            Data_ContaceptifUrgence_CaisseGest = ConfigXMLelementliste.Item(0).Item("CaisseGest").InnerText
            Data_ContaceptifUrgence_CentreGest = ConfigXMLelementliste.Item(0).Item("CentreGest").InnerText


            'Conventions
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Conventions")
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" Then
                Conventions_Activer = True
            Else
                Conventions_Activer = False
            End If

            'STS
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("STS")
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" Then
                STS_Activer = True
            Else
                STS_Activer = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("AfficheDiagNiv1").InnerText) = "OUI" Then
                STS_AfficheDiagNiv1 = True
            Else
                STS_AfficheDiagNiv1 = False
            End If

            'remplacement
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Remplacement")
            Titulaire_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_Id_Nat").InnerText
            Titulaire_Cle_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Titulaire_Cle_Num_Id_Nat").InnerText
            Titulaire_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_Id_Facturation").InnerText
            Titulaire_Cle_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Titulaire_Cle_Num_Id_Facturation").InnerText
            Titulaire_Nom = ConfigXMLelementliste.Item(0).Item("Titulaire_Nom").InnerText
            Titulaire_Prenom = ConfigXMLelementliste.Item(0).Item("Titulaire_Prenom").InnerText
            Titulaire_Code_Conventionnel = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_Conventionnel").InnerText
            Titulaire_Code_specialite = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_specialite").InnerText
            Titulaire_Code_Zone_tarifaire = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_Zone_tarifaire").InnerText
            Titulaire_Code_Zone_IK = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_Zone_IK").InnerText
            Titulaire_Code__Agrement_1 = ConfigXMLelementliste.Item(0).Item("Titulaire_Code__Agrement_1").InnerText
            Titulaire_Code__Agrement_2 = ConfigXMLelementliste.Item(0).Item("Titulaire_Code__Agrement_2").InnerText
            Titulaire_Code__Agrement_3 = ConfigXMLelementliste.Item(0).Item("Titulaire_Code__Agrement_3").InnerText
            Titulaire_Condition_Exercice = ConfigXMLelementliste.Item(0).Item("Titulaire_Condition_Exercice").InnerText
            Titulaire_Num_RPPS = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_RPPS").InnerText
            Titulaire_Cle_Num_RPPS = ConfigXMLelementliste.Item(0).Item("Titulaire_Cle_Num_RPPS").InnerText
            Titulaire_raison_sociale = ConfigXMLelementliste.Item(0).Item("Titulaire_raison_sociale").InnerText
            Titulaire_Num_log_situ_fact = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_log_situ_fact").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer_Session_Remplacement").InnerText) = "OUI" Then
                Activer_Session_Remplacement = True
            Else
                Activer_Session_Remplacement = False
            End If
            Remplacant_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Remplacant_Num_Id_Nat").InnerText
            Remplacant_Cle_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Remplacant_Cle_Num_Id_Nat").InnerText
            Remplacant_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Remplacant_Num_Id_Facturation").InnerText
            Remplacant_Cle_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Remplacant_Cle_Num_Id_Facturation").InnerText

            'LOI
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("LOI")
            LOI_Pop3_Serveur = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_Serveur").InnerText
            LOI_Pop3_Port = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_Port").InnerText
            LOI_Pop3_User = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_User").InnerText
            LOI_Pop3_Password = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_Password").InnerText
            LOI_Pop3_BAL = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_BAL").InnerText
            LOI_Pop3_RepBAL = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_RepBAL").InnerText
            LOI_Distr_OCT = ConfigXMLelementliste.Item(0).Item("LOI_Distr_OCT").InnerText
            LOI_Distr_horsOCT = ConfigXMLelementliste.Item(0).Item("LOI_Distr_horsOCT").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Activer").InnerText) = "OUI" Then
                LOI_Activer = True
            Else
                LOI_Activer = False
            End If
            LOI_Ref = ConfigXMLelementliste.Item(0).Item("LOI_Ref").InnerText
            LOI_NB_JOUR_Max = Val(ConfigXMLelementliste.Item(0).Item("LOI_NB_JOUR_Max").InnerText)
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Demande_Auto").InnerText) = "OUI" Then
                LOI_Demande_Auto = True
            Else
                LOI_Demande_Auto = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Controle_MAJ_mensuel").InnerText) = "OUI" Then
                LOI_Controle_MAJ_mensuel = True
            Else
                LOI_Controle_MAJ_mensuel = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Verif_InReply_To").InnerText) = "OUI" Then
                LOI_Verif_InReply_To = True
            Else
                LOI_Verif_InReply_To = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Controle_Correspondance").InnerText) = "OUI" Then
                LOI_Controle_Correspondance = True
            Else
                LOI_Controle_Correspondance = False
            End If
            LOI_code_resultat_incr_prec = ConfigXMLelementliste.Item(0).Item("LOI_code_resultat_incr_prec").InnerText
            LOI_smtp_serveur = ConfigXMLelementliste.Item(0).Item("LOI_smtp_serveur").InnerText
            LOI_smtp_serveur_port = Val(ConfigXMLelementliste.Item(0).Item("LOI_smtp_serveur_port").InnerText)
            LOI_cert_nums = ConfigXMLelementliste.Item(0).Item("LOI_cert_nums").InnerText
            LOI_clé_GIP_CPS = ConfigXMLelementliste.Item(0).Item("LOI_cle_GIP_CPS").InnerText
        End Sub

    End Structure
    Public Config As Configuration
#End Region
#Region "FONCTIONS"



#Region "Formats des dates"

    Public Function DateString_To_DateVitale(ByVal MyDateString) As String 'date en entrée au format jj/MM/aaaa, date en sortie au format aaaaMMjj0000
        If MyDateString = "" Or MyDateString = "  /  /" Then
            Return ""
        End If
        Return Mid(MyDateString, 7, 4) & Mid(MyDateString, 4, 2) & Mid(MyDateString, 1, 2) & "0000"
    End Function

    Public Function DateVitale_To_DateString(ByVal DateVitale) As String 'date en entrée au format aaaaMMjj0000, date en sortie au format jj/MM/aaaa
        Return Mid(DateVitale, 7, 2) & "/" & Mid(DateVitale, 5, 2) & "/" & Mid(DateVitale, 1, 4)
    End Function

#End Region

    'Clear les GroupBox
    Public Sub ClearGroupBox(ByVal myGroupBox As System.Windows.Forms.GroupBox, ByVal Vider_Combobox As Boolean)
        For Each truc In myGroupBox.Controls
            Select Case truc.GetType.ToString
                Case "System.Windows.Forms.TextBox"
                    truc.Clear()
                Case "System.Windows.Forms.ComboBox"
                    If Vider_Combobox = True Then
                        truc.Items.Clear()
                    End If
            End Select

        Next
    End Sub

    'Arrete GALSVW32.EXE
    Public Sub killgalss()
        Dim myProcesses() As Process
        Dim myProcess As Process
        ' Returns array containing all instances of "GALSVW32".
        myProcesses = Process.GetProcessesByName("GALSVW32")
        For Each myProcess In myProcesses
            myProcess.Kill()
        Next
    End Sub

    ' Code Erreur
    Public Sub AfficheErreur(ByVal CodeErreur As UInt16, Optional ByVal message As String = "")
        If message <> "" And CodeErreur <> 0 Then
            MsgBox(message)
        End If
        Select Case CodeErreur
            Case 0
            Case 1024
                MsgBox("Absence de réponse du lecteur lors d'un échange" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Information)
            Case 61441
                MsgBox("La Carte du Professionnel de Santé est absente du lecteur" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Information)
            Case 61442
                MsgBox("Carte du Professionnel de Santé bloquée" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61443
                MsgBox("Le code porteur présenté est erroné" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61444
                MsgBox("Carte du Professionnel de Santé est non valide ou inexploitable par le Logiciel Lecteur." + Chr(10) + "• La CPS n’a pas de DAM (Domaine d’Assurance Maladie)." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61445
                MsgBox("La Carte du Professionnel de Santé est retirée du lecteur" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61446
                MsgBox("Carte du Professionnel de Santé n’est pas habilitée à formater une Facture ou un lot de Factures." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61447
                MsgBox("Carte du Professionnel de Santé est inaccessible." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61457
                MsgBox("La carte Vitale est absente." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61460
                MsgBox("Défaut de communication avec la carte Vitale." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61461
                MsgBox("La carte Vitale est retirée du lecteur." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61462
                MsgBox("Code du régime d'assurance maladie inscrit sur la carte Vitale non géré par le lecteur." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61463
                MsgBox("Anomalie de la date d'exonération du ticket modérateur de l'assuré." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61464
                MsgBox("Anomalie de la date d'exonération du ticket modérateur du bénéficiaire." + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61475
                MsgBox("Le numéro national d'immatriculation de l'assuré fourni dans la zone de mémoire présentée en entrée diffère de celui qui figure sur sa carte Vitale." + Chr(10) + "VERIFIER CARTE VITALE" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Critical)
            Case 61476
                MsgBox("La Carte du Professionnel a été changée, veuillez relire les droits CPS" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Information)
            Case 61680
                MsgBox("ERREUR Carte Vitale: Présence simultanée de périodes de droits Mutuelles et AMC" + Chr(10) + CodeErreur.ToString, MsgBoxStyle.Information)
            Case 63136
                MsgBox("liste d’opposition indisponible", MsgBoxStyle.Critical)
            Case 63137
                MsgBox("carte Vitale en opposition", MsgBoxStyle.Exclamation)
            Case 63217
                MsgBox("Le chemin du répertoire de travail est absent du fichier SESAM.INI", MsgBoxStyle.Critical)
            Case Else

                MsgBox("Code Erreur:" + CodeErreur.ToString, MsgBoxStyle.Critical)
        End Select
    End Sub

    'Arrondis
    Public Function Arrondis(ByVal Valeur As Decimal)
        Dim partiedecimale As Decimal
        partiedecimale = Valeur - Int(Valeur)
        If partiedecimale >= 0.5 Then
            Return Int(Valeur) + 1
        Else
            Return Int(Valeur)
        End If
    End Function

    'Code régime
    Public Function TraductionCodeRégime(ByVal CodeRégime As String)
        Select Case CodeRégime
            Case "01"
                Return "Régime général"
            Case "02"
                Return "Régime agricole"
            Case "03"
                Return "Régime des Salariés Indépendants - RSI"
            Case "04"
                Return "Caisses de Prévoyance et de Retraite de la SNCF - CPR SNCF"
            Case "05"
                Return "Régime Spécial de la Régie Autonome des Transports Parisiens- RATP"
            Case "06"
                Return "Etablissement National des Invalides de la Marine - ENIM"
            Case "07"
                Return "Régime minier de Sécurité Sociale"
            Case "08"
                Return "Caisse Nationale Militaire de Sécurité Sociale - CNMSS"
            Case "09"
                Return "Caisse de Prévoyance Maladie de la Banque de France - CPM Banque de France"
            Case "10"
                Return "Caisse de Retraite et de Prévoyance des Clercs et Employés de Notaire - CRPCEN"
            Case "12"
                Return "Chambre de Commerce et d'Industrie de Paris - CCIP"
            Case "14"
                Return "Fonds de sécurité sociale de l'Assemblée Nationale"
            Case "15"
                Return "Caisses autonomes de Sécurité Sociale du Sénat"
            Case "16"
                Return "Caisse de Prévoyance du Personnel titulaire du Port Autonome de Bordeaux"
            Case "17"
                Return "Caisse des français à l'étranger"
            Case "80"
                Return "Ministère des anciens combattants"
            Case "90"
                Return "Caisse d'Assurance Vieillesse, Invalidité et Maladie des Cultes CAVIMAC"
            Case "91"
                Return "Mutuelle Générale de l'Education Nationale - MGEN"
            Case "92"
                Return "Mutuelle Générale des PTT - MGPTT"
            Case "93"
                Return "Mutuelle Générale de la police - MGP"
            Case "94"
                Return "Mutualité de la Fonction Publique - MFP"
            Case "95"
                Return "Mutuelle Nationale des Hospitaliers - MNH"
            Case "96"
                Return "Mutuelle Nationale Aviation Marine - MNAM"
            Case "99"
                Return "Autres mutuelles"
            Case Else
                Return "Code régime Inconnu"
        End Select
    End Function

    'Code gestion
    Public Function TraductionG101C13(ByVal G101C13 As String)
        Select Case G101C13
            Case "A1"
                Return "Salariés assurés obligatoires"
            Case "A2"
                Return "Exploitants assurés obligatoires"
            Case "A3"
                Return "Salariés assurés volontaires"
            Case "A4"
                Return "Exploitants assurés volontaires"
            Case "A5"
                Return "Assurés personnels"
            Case "N1"
                Return "Régime obligatoire"
            Case "N2"
                Return "Gratuit"
            Case "N3"
                Return "Biologistes"
            Case "N5"
                Return "Assurés volontaires"
            Case "N6"
                Return "CEE"
            Case "04"
                Return "SNCF"
            Case "T1"
                Return "Agents actifs"
            Case "M1"
                Return "Agents actifs"
            Case "M2"
                Return "Agents invalides et pensionnés"
            Case "10"
                Return "Régime général"
            Case "11"
                Return "Régime général assurés retraités"
            Case "12"
                Return "Régime général assurés non cotisants"
            Case "13"
                Return "Invalides de guerre"
            Case "18"
                Return "Adultes handicapés"
            Case "20"
                Return "Régime général partiel"
            Case "23"
                Return "Fonctionnaires ouvriers de l'état"
            Case "24"
                Return "EDF-GDF"
            Case "25"
                Return "Etudiants"
            Case "29"
                Return "Collectivités locales"
            Case "34"
                Return "Artistes auteurs"
            Case "40"
                Return "Assurés volontaires"
            Case "70"
                Return "Conventions internationales (CEE et conventions bilatérales)"
            Case "85"
                Return "Assurés personnels"
            Case "86"
                Return "AVIP (Assuré Volontaire Inv. Parental)"
            Case "87"
                Return "RMI (Revenu Minimum d'Insertion)"
            Case "89"
                Return "Assurés bénéficiaires de la Couverture Maladie Universelle"
            Case "90"
                Return "Praticiens sauf biologistes"
            Case Else
                Return "Code Gestion Inconnu"
        End Select
    End Function

#Region "BASE 64"
    Public Sub convert_base64file_to_another_file(ByVal Base64File As String, ByVal DestinationFile As String, ByVal DeleteBase64File As Boolean)
        Dim B64string As String = My.Computer.FileSystem.ReadAllText(Base64File)
        Dim FileBytes() As Byte = Convert.FromBase64String(B64string)
        My.Computer.FileSystem.WriteAllBytes(DestinationFile, FileBytes, True)
        If DeleteBase64File = True Then
            My.Computer.FileSystem.DeleteFile(Base64File)
        End If
    End Sub
#End Region

    'Qualité
    Public Function TraductionG104C14(ByVal G104C14 As String)
        Select Case G104C14
            Case "00" Or "0"
                Return "Assuré"
            Case "01" Or "1"
                Return "Ascendant, descendant, collatéraux ascendants"
            Case "02" Or "2"
                Return "Conjoint"
            Case "03" Or "3"
                Return "Conjoint divorcé"
            Case "04" Or "4"
                Return "Concubin"
            Case "05" Or "5"
                Return "Conjoint séparé"
            Case "06" Or "6"
                Return "Enfant"
            Case "08" Or "8"
                Return "Conjoint veuf"
            Case "09" Or "9"
                Return "Autre ayant-droit"
            Case Else
                Return "Code Qualité Inconnu"
        End Select
    End Function

    'Code service AMO bénéficiaire
    Public Function TraductionG104C15(ByVal G104C15 As String)
        Select Case G104C15
            Case "00" Or "0"
                Return "Le bénéficiaire n'a pas de service AMO spécifique"
            Case "01" Or "1"
                Return "Le bénéficiaire a une CMU complémentaire gérée par une AMO"
            Case "02" Or "2"
                Return "Le bénéficiaire a une CMU complémentaire gérée par une AMC en convention ou en délégation avec une AMO"
            Case "03" Or "3"
                Return "Le bénéficiaire a une CMU complémentaire gérée par une AMC"
            Case "10"
                Return "Le bénéficiaire est sortant de CMU complémentaire"
            Case "11"
                Return "Bénéficiaire du dispositif d’aide à l’acquisition d’une complémentaire"
            Case Else
                Return "Code service AMO bénéficiaire Inconnu"
        End Select
    End Function


    Public Function Traduction_CodeSpécialité_Prescripteur(ByVal CodeSpécialité As String) As String
        Select Case CodeSpécialité
            Case "01"
                Return "Médecine générale"
            Case "02"
                Return "Anesthésie Réanimation"
            Case "03"
                Return "Cardiologie"
            Case "04"
                Return "Chirurgie Générale"
            Case "05"
                Return "Dermato-Vénérologie"
            Case "07"
                Return "Gynécologie-Obstétrique"
            Case "08"
                Return "Gastro-Entéro-Hépatologie"
            Case "09"
                Return "Médecine interne"
            Case "10"
                Return "Neuro-chirurgie"
            Case "11"
                Return "Oto-rhino-laryngologie"
            Case "12"
                Return "Pédiatrie"
            Case "13"
                Return "Pneumologie"
            Case "14"
                Return "Rhumatologie"
            Case "15"
                Return "Ophtalmologie"
            Case "16"
                Return "Chirurgie Urologique"
            Case "17"
                Return "Neuro.Psychiatrie"
            Case "20"
                Return "Réanimation médicale"
            Case "21"
                Return "Sage-femme"
            Case "22"
                Return "Spécialiste en Médecine générale avec diplôme"
            Case "23"
                Return "Spécialiste en Médecine générale reconnu par l’Ordre"
            Case "31"
                Return "Rééducation -Réadaptation fonctionnelle"
            Case "32"
                Return "Neurologie"
            Case "33"
                Return "Psychiatrie"
            Case "34"
                Return "Gériatrie"
            Case "35"
                Return "Néphrologie"
            Case "41"
                Return "Chirurgie orthopédique"
            Case "42"
                Return "Endocrinologie Métabolique"
            Case "43"
                Return "Chirurgie infantile"
            Case "46"
                Return "Chirurgie Plastique et Esthétique"
            Case "47"
                Return "Chirurgie Thoracique et Cardiologie Vasculaire"
            Case "48"
                Return "Chirurgie Vasculaire"
            Case "49"
                Return "Chirurgie Viscérale et Digestive"
            Case "70"
                Return "Gynécologie Médicale"
            Case "71"
                Return "Hématologie"
            Case "72"
                Return "Médecine nucléaire"
            Case "73"
                Return "Oncologie Médicale"
            Case "74"
                Return "Oncologie Radiothérapique"
            Case "75"
                Return "Psychiatrie Infantile"
            Case "77"
                Return "Obstétrique"
            Case "79"
                Return "Gynécologie obstétrique et gynécologie médicale"
            Case "80"
                Return "Santé publique et médecine sociale"
            Case Else
                Return "code spécialité inconnu (" + CodeSpécialité + ")"
        End Select
    End Function
#End Region
#Region "Graphics"
    Public Function GetRoundedRectPath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
        Dim diameter As Integer = 2 * radius
        Dim arcRect As New Rectangle(rect.Location, New Size(diameter, diameter))
        Dim path As New GraphicsPath
        path.AddArc(arcRect, 180, 90)
        arcRect.X = rect.Right - diameter
        path.AddArc(arcRect, 270, 90)
        arcRect.Y = rect.Bottom - diameter
        path.AddArc(arcRect, 0, 90)
        arcRect.X = rect.Left
        path.AddArc(arcRect, 90, 90)
        path.CloseFigure()
        Return path
    End Function
#End Region
End Module
