#ifndef C_BDM_API_H
#define C_BDM_API_H

#include <QObject>
#include <QList>
#include <QDateTime>
#include <QDebug>
#include "../C_BaseCommon.h"
#include "../../MedinTuxTools-QT4/medicabase/C_BDM_ApiVar.h"
#include "../../MedinTuxTools-QT4/medicabase/C_PatientCtx.h"

#include "C_PosologieGrammar.h"
#include "C_InterResultPair.h"

#define getListMedicaments selectProductsList
#define CIP_to_ATC ATC_from_CIP

class QTreeWidget;
class QTextEdit;
class QTreeWidgetItem;
class QTimer;
class QSqlQuery;
class C_PatientCtx;

//=================== C_BDM_SmrListRecord ===================================
/*! \class C_BDM_SmrListRecord
 *  \brief Class to datas access for a smr line record in smr list.
 */

class C_BDM_SmrListRecord
{
public:
    explicit C_BDM_SmrListRecord(){}
     QString id_1()             {return m_id_1;}
     QString id_type_1()        {return m_id_type_1;}
     QString libelle_1()        {return m_libelle_1;}
     QString descrip_1()        {return m_descrip_1;}
     QString id_2()             {return m_id_2;}
     QString id_type_2()        {return m_id_type_2;}
     QString libelle_2()        {return m_libelle_2;}
     QString descrip_2()        {return m_descrip_2;}

     QString level()            {return m_level;}
     QString level_libelle()    {return m_level_libelle;}
     QString cat()              {return m_cat;}
     QString smr_type()         {return m_smr_type;}        // A pour ASMR    S pour SMR
     QString datetime()         {return m_datetime;}
     QString owner()            {return m_owner;}
     QString lang()             {return m_lang;}

     void set_id_1(QString value)          {m_id_1          = value;}
     void set_id_type_1(QString value)     {m_id_type_1     = value;}
     void set_libelle_1(QString value)     {m_libelle_1     = value;}
     void set_descrip_1(QString value)     {m_descrip_1     = value;}
     void set_id_2(QString value)          {m_id_2          = value;}
     void set_id_type_2(QString value)     {m_id_type_2     = value;}
     void set_libelle_2(QString value)     {m_libelle_2     = value;}
     void set_descrip_2(QString value)     {m_descrip_2     = value;}
     void set_level(QString value)         {m_level         = value;}
     void set_level_libelle(QString value) {m_level_libelle = value;}
     void set_cat(QString value)           {m_cat           = value;}
     void set_smr_type(QString value)      {m_smr_type      = value;}
     void set_datetime(QString value)      {m_datetime      = value;}
     void set_owner(QString value)         {m_owner         = value;}
     void set_lang(QString value)          {m_lang          = value;}

private :
        QString m_id_1;
        QString m_id_type_1;
        QString m_libelle_1;
        QString m_descrip_1;
        QString m_id_2;
        QString m_id_type_2;
        QString m_libelle_2;
        QString m_descrip_2;
        QString m_level;
        QString m_level_libelle;
        QString m_cat;
        QString m_smr_type;
        QString m_datetime;
        QString m_owner;
        QString m_lang;
};

//=================== C_BDM_DrugListRecord ===================================
/*! \class C_BDM_DrugListRecord
 *  \brief Class to datas access for a drug line record in drugs list.
 */

class C_BDM_DrugListRecord
{
public:
    explicit C_BDM_DrugListRecord(){}

    C_BDM_DrugListRecord(const QString xmlData)
    {unSerialize(xmlData,this);
    }

    C_BDM_DrugListRecord(QString id,
                         QString id_type,
                         QString commercialName,
                         QString dci_1Name,
                         QString dc2_1Name,
                         QString dc3_1Name,
                         QString owner,
                         QString lang,
                         QString ucd,
                         QString ucd_price,
                         QString atc,
                         QString generique,
                         QString statut
                        )
     {m_id             = id;
      m_id_type        = id_type;
      m_commercialName = commercialName;
      m_dci_1Name      = dci_1Name;
      m_dci_2Name      = dc2_1Name;
      m_dci_3Name      = dc3_1Name;
      m_owner          = owner;
      m_lang           = lang;
      m_ucd            = ucd;
      m_ucd_price      = ucd_price;
      m_atc            = atc;
      m_generique      = generique;
      m_statut         = statut;
     }

     QString id()  const           {return m_id;}
     QString id_type() const       {return m_id_type;}
     QString commercialName()const {return m_commercialName;}
     QString dci_1Name()   const   {return m_dci_1Name;}
     QString dci_2Name() const     {return m_dci_2Name;}
     QString dci_3Name() const     {return m_dci_3Name;}
     QString owner()  const        {return m_owner;}
     QString lang()  const         {return m_lang;}
     QString ucd()   const         {return m_ucd;}
     QString ucd_price() const     {return m_ucd_price;}
     QString atc()   const         {return m_atc;}
     QString generique()  const    {return m_generique;}
     QString statut()   const      {return m_statut;}

     void set_id(QString value)             {m_id             = value;}
     void set_id_type(QString value)        {m_id_type        = value;}
     void set_commercialName(QString value) {m_commercialName = value;}
     void set_dci_1Name(QString value)      {m_dci_1Name      = value;}
     void set_dci_2Name(QString value)      {m_dci_2Name      = value;}
     void set_dci_3Name(QString value)      {m_dci_3Name      = value;}
     void set_owner(QString value)          {m_owner          = value;}
     void set_lang(QString value)           {m_lang           = value;}
     void set_ucd(QString value)            {m_ucd            = value;}
     void set_ucd_price(QString value)      {m_ucd_price      = value;}
     void set_atc(QString value)            {m_atc            = value;}
     void set_generique(QString value)      {m_generique      = value;}
     void set_statut(QString value)         {m_statut         = value;}

     QString serialize() const;
     static QString                serialize(const C_BDM_DrugListRecord *pC_BDM_DrugListRecord);
     static C_BDM_DrugListRecord*  unSerialize(const QString & data, C_BDM_DrugListRecord *obj);
     static C_BDM_DrugListRecord   unSerialize(const QString & data);

protected :
        QString m_id;
        QString m_id_type;
        QString m_commercialName;
        QString m_dci_1Name;
        QString m_dci_2Name;
        QString m_dci_3Name;
        QString m_owner;
        QString m_lang;
        QString m_ucd;
        QString m_ucd_price;
        QString m_atc;
        QString m_generique;
        QString m_statut;
};

//=================== C_OrdoLineRecord ===================================
class C_OrdoLineRecord : public C_BDM_DrugListRecord
{
public:
    explicit C_OrdoLineRecord(){}

    C_OrdoLineRecord(const QString xmlData)
    {unSerialize(xmlData,this);
    }

    C_OrdoLineRecord( const C_BDM_DrugListRecord &bdm_DrugListRecord)
        : C_BDM_DrugListRecord( bdm_DrugListRecord.id(),
                                bdm_DrugListRecord.id_type(),
                                bdm_DrugListRecord.commercialName(),
                                bdm_DrugListRecord.dci_1Name(),
                                bdm_DrugListRecord.dci_2Name(),
                                bdm_DrugListRecord.dci_3Name(),
                                bdm_DrugListRecord.owner(),
                                bdm_DrugListRecord.lang(),
                                bdm_DrugListRecord.ucd(),
                                bdm_DrugListRecord.ucd_price(),
                                bdm_DrugListRecord.atc(),
                                bdm_DrugListRecord.generique(),
                                bdm_DrugListRecord.statut())
    {   /*
        m_id             = ordoLineRecord.id();
        m_id_type        = ordoLineRecord.id_type();
        m_commercialName = ordoLineRecord.commercialName();
        m_dci_1Name      = ordoLineRecord.dci_1Name();
        m_dci_2Name      = ordoLineRecord.dci_2Name();
        m_dci_3Name      = ordoLineRecord.dci_3Name();
        m_owner          = ordoLineRecord.owner();
        m_lang           = ordoLineRecord.lang();
        m_ucd            = ordoLineRecord.ucd();
        m_ucd_price      = ordoLineRecord.ucd_price();
        m_atc            = ordoLineRecord.atc();
        m_generique      = ordoLineRecord.generique();
        m_statut         = ordoLineRecord.statut();
        */
        m_ordo_key               =   "";
        m_numOrdre               =   "";
        m_secureState            =   "";
        m_date_debut             =   QDateTime::currentDateTime();
        m_date_fin               =   QDateTime::currentDateTime();
        m_pk_patient             =   "";
        m_guid_patient           =   "";
        m_code_indication        =   "";
        m_type_code_indication   =   "";
        m_smr                    =   "";
        m_smr_indication         =   "";
        m_voie_admin             =   "";
        m_ald                    =   "";
        m_substituable           =   "";
        m_renouvelable           =   "";
        m_quantite_totale        =   "";
        m_forme_galenique        =   "";
        m_unite_de_prise         =   "";
        m_quantite_par_up        =   "";
        m_unite_quantite         =   "";
        m_note_textuelle_libre   =   "";
        m_schema_posologique     =   "";
    }

    C_OrdoLineRecord( const C_OrdoLineRecord &ordoLineRecord)
        : C_BDM_DrugListRecord( ordoLineRecord.id(),
                                ordoLineRecord.id_type(),
                                ordoLineRecord.commercialName(),
                                ordoLineRecord.dci_1Name(),
                                ordoLineRecord.dci_2Name(),
                                ordoLineRecord.dci_3Name(),
                                ordoLineRecord.owner(),
                                ordoLineRecord.lang(),
                                ordoLineRecord.ucd(),
                                ordoLineRecord.ucd_price(),
                                ordoLineRecord.atc(),
                                ordoLineRecord.generique(),
                                ordoLineRecord.statut())
    {   /*
        m_id             = ordoLineRecord.id();
        m_id_type        = ordoLineRecord.id_type();
        m_commercialName = ordoLineRecord.commercialName();
        m_dci_1Name      = ordoLineRecord.dci_1Name();
        m_dci_2Name      = ordoLineRecord.dci_2Name();
        m_dci_3Name      = ordoLineRecord.dci_3Name();
        m_owner          = ordoLineRecord.owner();
        m_lang           = ordoLineRecord.lang();
        m_ucd            = ordoLineRecord.ucd();
        m_ucd_price      = ordoLineRecord.ucd_price();
        m_atc            = ordoLineRecord.atc();
        m_generique      = ordoLineRecord.generique();
        m_statut         = ordoLineRecord.statut();
        */
        m_ordo_key               =   ordoLineRecord.ordo_key();
        m_numOrdre               =   ordoLineRecord.numOrdre();
        m_secureState            =   ordoLineRecord.secureState();
        m_date_debut             =   ordoLineRecord.date_debut();
        m_date_fin               =   ordoLineRecord.date_fin();
        m_pk_patient             =   ordoLineRecord.pk_patient();
        m_guid_patient           =   ordoLineRecord.guid_patient();
        m_code_indication        =   ordoLineRecord.code_indication();
        m_type_code_indication   =   ordoLineRecord.type_code_indication();
        m_smr                    =   ordoLineRecord.smr();
        m_smr_indication         =   ordoLineRecord.smr_indication();
        m_voie_admin             =   ordoLineRecord.voie_admin();
        m_ald                    =   ordoLineRecord.ald();
        m_substituable           =   ordoLineRecord.substituable();
        m_renouvelable           =   ordoLineRecord.renouvelable();
        m_quantite_totale        =   ordoLineRecord.quantite_totale();
        m_forme_galenique        =   ordoLineRecord.forme_galenique();
        m_unite_de_prise         =   ordoLineRecord.unite_de_prise();
        m_quantite_par_up        =   ordoLineRecord.quantite_par_up();
        m_unite_quantite         =   ordoLineRecord.unite_quantite();
        m_note_textuelle_libre   =   ordoLineRecord.note_textuelle_libre();
        m_schema_posologique     =   ordoLineRecord.schema_posologique();
    }

    C_OrdoLineRecord    (QString   id,
                         QString   id_type,
                         QString   commercialName,
                         QString   dci_1Name,
                         QString   dci_2Name,
                         QString   dci_3Name,
                         QString   owner,
                         QString   lang,
                         QString   ucd,
                         QString   ucd_price,
                         QString   atc,
                         QString   generique,
                         QString   statut,

                         QString   ordo_key,
                         QString   numOrdre,
                         QString   secureState,
                         QDateTime date_debut,
                         QDateTime date_fin,
                         QString   pk_patient,
                         QString   guid_patient,
                         QString   code_indication,
                         QString   type_code_indication,
                         QString   smr,
                         QString   smr_indication,
                         QString   voie_admin,
                         QString   ald,
                         QString   substituable,
                         QString   renouvelable,
                         QString   quantite_totale,
                         QString   forme_galenique,
                         QString   unite_de_prise,
                         QString   quantite_par_up,
                         QString   unite_quantite,
                         QString   note_textuelle_libre,
                         QString   schema_posologique
                        )
                            : C_BDM_DrugListRecord( id,
                                                    id_type,
                                                    commercialName,
                                                    dci_1Name,
                                                    dci_2Name,
                                                    dci_3Name,
                                                    owner,
                                                    lang,
                                                    ucd,
                                                    ucd_price,
                                                    atc,
                                                    generique,
                                                    statut)
    {m_ordo_key               =   ordo_key;
     m_numOrdre               =   numOrdre;
     m_secureState            =   secureState;
     m_date_debut             =   date_debut;
     m_date_fin               =   date_fin;
     m_pk_patient             =   pk_patient;
     m_guid_patient           =   guid_patient;
     m_code_indication        =   code_indication;
     m_type_code_indication   =   type_code_indication;
     m_smr                    =   smr;
     m_smr_indication         =   smr_indication;
     m_voie_admin             =   voie_admin;
     m_ald                    =   ald;
     m_substituable           =   substituable;
     m_renouvelable           =   renouvelable;
     m_quantite_totale        =   quantite_totale;
     m_forme_galenique        =   forme_galenique;
     m_unite_de_prise         =   unite_de_prise;
     m_quantite_par_up        =   quantite_par_up;
     m_unite_quantite         =   unite_quantite;
     m_note_textuelle_libre   =   note_textuelle_libre;
     m_schema_posologique     =   schema_posologique;
    }

    //.......... methodes ..............
     void   set_ordo_key(const QString &value)                  {  m_ordo_key    = value;}
     void   set_numOrdre(const QString &value)                  {  m_numOrdre    = value;}
     void   set_secureState(const QString &value)               {  m_secureState = value;}
     void   set_date_debut(const QDateTime &value)              {  m_date_debut  = value;}
     void   set_date_fin(  const QDateTime &value)              {  m_date_fin    = value;}
     void   set_pk_patient(const QString &value)                {  m_pk_patient  = value;}
     void   set_guid_patient(const QString &value)              {  m_guid_patient  = value;}
     void   set_code_indication(const QString &value)           {  m_code_indication  = value;}
     void   set_type_code_indication(const QString &value)      {  m_type_code_indication  = value;}
     void   set_smr(const QString &value)                       {  m_smr  = value;}
     void   set_smr_indication(const QString &value)            {  m_smr_indication  = value;}
     void   set_voie_admin(const QString &value)                {  m_voie_admin  = value;}
     void   set_ald(const QString &value)                       {  m_ald  = value;}
     void   set_substituable(const QString &value)              {  m_substituable  = value;}
     void   set_renouvelable(const QString &value)              {  m_renouvelable  = value;}
     void   set_quantite_totale(const QString &value)           {  m_quantite_totale  = value;}
     void   set_forme_galenique(const QString &value)           {  m_forme_galenique  = value;}
     void   set_unite_de_prise(const QString &value)            {  m_unite_de_prise  = value;}
     void   set_quantite_par_up(const QString &value)           {  m_quantite_par_up  = value;}
     void   set_unite_quantite(const QString &value)            {  m_unite_quantite  = value;}
     void   set_note_textuelle_libre(const QString &value)      {  m_note_textuelle_libre  = value;}
     void   set_schema_posologique(const QString &value)        {  m_schema_posologique  = value;}
     //.......... methodes acces ..............
     QString   ordo_key()            const    { return m_ordo_key;}
     QString   numOrdre()            const    { return m_numOrdre;}
     QString   secureState()         const    { return m_secureState;}
     QDateTime date_debut()          const    { return m_date_debut;}
     QDateTime date_fin()            const    { return m_date_fin;}
     QString pk_patient()            const    { return m_pk_patient;}
     QString guid_patient()          const    { return m_guid_patient;}
     QString code_indication()       const    { return m_code_indication;}
     QString type_code_indication()  const    { return m_type_code_indication;}
     QString smr()                   const    { return m_smr;}
     QString smr_indication()        const    { return m_smr_indication;}
     QString voie_admin()            const    { return m_voie_admin;}
     QString ald()                   const    { return m_ald;}
     QString substituable()          const    { return m_substituable;}
     QString renouvelable()          const    { return m_renouvelable;}
     QString quantite_totale()       const    { return m_quantite_totale;}
     QString forme_galenique()       const    { return m_forme_galenique;}
     QString unite_de_prise()        const    { return m_unite_de_prise;}
     QString quantite_par_up()       const    { return m_quantite_par_up;}
     QString unite_quantite()        const    { return m_unite_quantite;}
     QString note_textuelle_libre()  const    { return m_note_textuelle_libre;}
     QString schema_posologique()    const    { return m_schema_posologique;}

     QString                  serialize() const;
     static QString           serialize(const C_OrdoLineRecord *pC_OrdoLineRecord);
     static C_OrdoLineRecord* unSerialize(const QString & data, C_OrdoLineRecord *pC_OrdoLineRecord);
     static C_OrdoLineRecord  unSerialize(const QString & data);

 private:
     QString   m_ordo_key;        // cette valeur est la clef (exemple: QDateTime de redaction) d'appartenance à une ordonnance composée de plusieurs lignes de C_OrdoLineRecord
     QString   m_numOrdre;        // eventuel numero d'ordre du produit dans l'ordonnance à laquelle il appartient
     QString   m_secureState;     // etat des alertes signalees lors de l'enregistrement (permet de retrouver rappidement les prescriptions potentiellement a problemes)
     QDateTime m_date_debut;
     QDateTime m_date_fin;
     QString   m_pk_patient;
     QString   m_guid_patient;
     QString   m_code_indication;          // code : cim10,Cisp, separes par des epsace si plusieurs codes) etc...
     QString   m_type_code_indication;     // origine du code
     QString   m_smr;                      // SMR lié à cette prescription
     QString   m_smr_indication;           // si selon indication (alors
     QString   m_voie_admin;
     QString   m_ald;
     QString   m_substituable;
     QString   m_renouvelable;
     QString   m_quantite_totale;
     QString   m_forme_galenique;
     QString   m_unite_de_prise;
     QString   m_quantite_par_up;
     QString   m_unite_quantite;
     QString   m_note_textuelle_libre;
     QString   m_schema_posologique;

};


//======================================================= C_BDM_PluginI ===================================
/*! \class C_BDM_PluginI
 *  \brief pure virtual Interface Class to provide data to C_BDM_Api database, each data commercial sources must provide
 * a plugin derived from this modele.
 */

class C_BDM_PluginI : C_BDM_ApiVar
{

public:
    enum flags  {no_filter   = 0,
                 atc_filter  = 1,
                 nom_filter  = 2,
                 dci_filter  = 4,
                 ucd_filter  = 8,
                 dc3_filter  = 16,
                 cip_filter  = 32,
                 gen_filter  = 64,
                 vil_filter  = 128,
                 hop_filter  = 256,
                 all_filter  = 511
                };
    enum hit_flag  {ONLY_IF_NOT_EXISTS   = 0,
                    EVEN_IF_EXISTS       = 1,
                    INCREASE_HIT         = 2,
                    FIX_HIT              = 3
                   };

    explicit C_BDM_PluginI();
    ~C_BDM_PluginI();
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //------------------ INTERFACE VIRTUELLE ------------------------------------------------------------------------
    //                   chaque implementation commerciale devra implementer les methodes virtuelles pures de cette partie
    virtual int                   init(const QString &confDatas)=0;
    virtual void                  setLogWidget      ( QTextEdit    *logWidget)=0;
    virtual void                  setProgressWidget ( QProgressBar *pQProgressBar)=0;  //progressWidget
    virtual QProgressBar *        progressWidget()=0;                                  //progressWidget
    virtual QString               dataSourceVersion()=0;
    virtual QString               lang()=0;
    virtual QString               owner()=0;
    virtual QString               getLastError()=0;

    //--------------------------- get_CIS_RCP_From_CIP -----------------------------------------------------------
    /*! \brief return ANSM (ex afssaps) CIS ans RCP code from CIP code, to use in html request with ANSM (ex afssaps) web site.
     *  \param const QString cip is drug cip code.
     *  \param QString *rcp is pointer on QString to return RCP result if not zero .
     *  \return CIS code string
    */
    virtual  QString              get_CIS_and_RCP_From_CIP(const QString &cip, QString *rcp =0 )=0;
    //.................. classification ATC ....................
    virtual int                   nextATC_Code(QString &codeAtc, QString &libelle)=0;

    //.................. liste des medicaments ................
    virtual long                  drugsList_Count()=0;
    virtual int                   getDrugList_Start()=0;
    virtual int                   getDrugList_NextRecord(C_BDM_DrugListRecord &rC_BDM_DrugListRecord)=0;
    //.................. liste des Smr ........................
    //-------------------------------- getNextSmrInfoForCIP ------------------------------------------------------
    /*! \brief select SMR and ASM informations for a drug. You must call this methode While returns true.
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \param QString &date           it will contains date        of SMR ASM.
     *  \param QString &level          it will contains level       of SMR ASM..
     *  \param QString &indication     it will contains indication  of SMR ASM..
     *  \param QString &descriptif     it will contains description of SMR ASM..
     *  \param QString &codeCimx       it will contains code CIM10  of SMR ASM..
     *  \return true while datas are presents.. You must loop while returns true.
     */
    virtual bool                  getNextSmrInfoForCIP(      const QString &cip,
                                                             QString &date,
                                                             QString &level,
                                                             QString &levelLibelle,
                                                             QString &indication,
                                                             QString &descriptif,
                                                             QString &codeCimx
                                                      )=0;
    //-------------------------------- getDefinedDailyDoseFromCIP ------------------------------------------------------
    /*! \brief return the defined daily dose from cip.
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return QString defined daily dose
     */
    virtual QString   getDefinedDailyDoseFromCIP ( const QString &cip)=0;
    //-------------------------------- getMonographieFromCIP ------------------------------------------------------
    /*! \brief select monographie for a drug.
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return QString contains monographie
     */
     virtual QString  getMonographieFromCIP ( const QString &cip ,   bool dataMustBeReadInCache  = TRUE )=0;
     //-------------------------------- getPriseUnitFormFromCIP ------------------------------------------------------
     /*! \brief return the prise unit form from cip. (comprimés, suppositoires sachets,ampoules,doses kg, cuillères à café etc...)
      *  \param const QString &cip      code CIP of the drug from wich wee want datas.
      *  \return QString with unit form
      */
     virtual QString             getPriseUnitFormFromCIP ( const QString &cip , const QString &commercialName = 0 )=0;
     //-------------------------------- isStupefiant ------------------------------------------------------
     /*! \brief return if the product identified par Id is a stupefiant
      *  \param const QString &cip      code CIP of the drug from wich wee want datas.
      *  \return 1 is stupefiant
      */
     virtual int             isStupefiant ( const QString &cip )=0;
     //-------------------------------- code_ATC_To_Name ------------------------------------------------------
     /*! \brief return if ATC libelle from code ATC
      *  \param const QString &code      code ATC .
      *  \return QString return libelle
      */
     virtual QString code_ATC_To_Name(const QString &code)=0;
     //-------------------------------- getDrugRouteFromCIP ------------------------------------------------------
     /*! \brief return the drug route from cip.
      *  \param const QString &cip      code CIP of the drug from wich wee want datas.
      *  \return QString with the drug route
      */
     virtual QString   getDrugRouteFromCIP ( const QString &cip)=0;
     //-------------------------------- getPosologiesFromCIP ------------------------------------------------------
     /*! \brief return posologies list as posologie grammar QString
      *  \param const QString &cip      code CIP of the drug from wich wee want datas.
      *  \return QStringList with grammar QString list
      */
     virtual QStringList   getPosologiesFromCIP ( const QString &cip ) = 0;

     //-------------------------------- getInteractionCim10 ------------------------------------------------------
     /*! \brief return physiopath interactions from patient and drug.
      *  \param const QString& cip drug cip identification .
      *  \param const QStringList &cim10List cim10 pathologies list .
      *  \param QString drugName (default empty) the drug name.
      *  \return QList<C_InterResultPair> result interaction pair list
      */
     virtual QList<C_InterResultPair> getInteractionCim10(const QString &cip, const QStringList &cim10List , QString drugName  = ""  )=0;
     //-------------------------------- getInteractionAgeSexePoidsSportVigil ------------------------------------------------------
     /*! \brief return physiopath interactions from patient and drug.
      *  \param const QString& cip drug cip identification .
      *  \param const QString &age patient age .
      *  \param const QString &sexe patient sexe F-M-I.
      *  \param const QString &poids patient poids .
      *  \param const QString &taille patient size .
      *  \param bool sport if true particular attention for doping drugs is required  .
      *  \param bool vigil if true particular attention for drugs which vigilance  alteration is required  .
      *  \param QString drugName (default empty) the drug name.
      *  \return QList<C_InterResultPair> result interaction pair list
      */
      virtual QList<C_InterResultPair>        getInteractionAgeSexePoidsSportVigil( const QString &cip,
                                                                                    const QString &age ,
                                                                                    const QString &sexe,
                                                                                    const QString &poids,
                                                                                    const QString &taille,
                                                                                    bool  sport       = true,
                                                                                    bool  vigil       = true,
                                                                                    QString drugName  = ""  )=0;
     //-------------------------------- getInteractionPairFromCipList ------------------------------------------------------
     /*! \brief return interactions xml results from a cip list.
      *  \param const QStringList &cipList      drugs CIP codes list to test.
      *  \return QList<C_InterResultPair> result interaction pair list
      */
     virtual QList<C_InterResultPair> getInteractionPairFromCipList ( const QStringList &cipList)=0;
     //-------------------------------- getInteractionFromCipList ------------------------------------------------------
     /*! \brief return interactions xml results from a cip list.
      *  \param const QStringList &cipList      drugs CIP codes list to test.
      *  \return QStringList where each line is a xml result interaction
      *   each interaction line is a xml structure where :
      *   <itli>           </itli> delimits each interaction line structured as follows.
      *   <itli_code1>     </itli_code1>       delimits first  term code (if exists)
      *   <itli_typcode1>  </itli_typcode1>    delimits first  term codetyp examples "CIP ATC CIM10 CISP NONE AL PO"
      *   <itli_terme1>    </itli_terme1>      delimits first  term libelle text
      *   <itli_code2>     </itli_code2>       delimits second term code (if exists)
      *   <itli_typcode2>  </itli_typcode2>    delimits second term codetyp examples "CIP ATC CIM10 CISP NONE"
      *   <itli_terme2>    </itli_terme2>      delimits second term libelle text
      *   <itli_terme2>    </itli_terme2>      delimits second term libelle text
      *   <itli_texte>     </itli_texte>       delimits text interaction information
      *   <itli_ityp>      </itli_ityp>        delimits interaction type (RESERVED)
      *   <itli_level>     </itli_level>       interraction level
      */
     // virtual QStringList   getInteractionFromCipList ( const QStringList &cipList)=0;

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //------------------ INTERFACE IMPLEMENTEE -----------------------------------------------------------------------
    //-------------------------------- isInitialised ------------------------------------------------------
    /*! \brief return initialised statut .
    */
    int           isInitialised();
    //-------------------------------- patientContexte ------------------------------------------------------
    /*! \brief return a poointer on C_PatientCtx (patient contexte) .
    */
//$   C_PatientCtx *patientContexte();

    //-------------------------------- setPatientContexte ------------------------------------------------------
    /*! \brief set patient contexte.
    */
//$    void setPatientContexte(C_PatientCtx* patientCtx);
    //-------------------------------- getInteractionAllergies ------------------------------------------------------
    /*! \brief return allergicals interactions from patient and drug.
     *  \param const QString& cip drug cip identification .
     *  \param QString drugName (default empty) the drug name.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
    // ASPIRINE|DCI|ASPIRINE|ALD|Allergie(Allergie)|plutôt intolérance|06-06-1956|
    // 3515495|CIP|LAMALINE|Sport|Allergie(Allergie)|urticaire généralisé |06-06-1956|
    // 3007528|CIP|ASPIRINE|ALD|Allergie(Allergie)|plutôt intolérance|06-06-1956|
    // J01CR02|ATC|AMOXICILINE ET INHIBITEUR D'ENZYME|ALD|Allergie(Allergie)|pas de commentaire|06-06-1956|

    QList<C_InterResultPair> getInteractionAllergies(const QString &cip, QList<C_LifeEvent> lifeEventList, QString drugName  = ""  );
    //-------------------------------- dbi_cip_atcName ------------------------------------------------------
    /*! \brief return ATC code from CIP code.
     *  \param const QString& cip drug cip identification .
     *  \return QString ATC code from this drug
     */
    QString                              dbi_cip_atcName(const QString& cip);
    //-------------------------------- dbi_cip_drugName ------------------------------------------------------
    /*! \brief return drug name code from CIP code.
     *  \param const QString& cip drug cip identification .
     *  \return QString drug name
     */
    QString                              dbi_cip_drugName(const QString& cip);
    //-------------------------------- dbi_atc_to_cip_map ------------------------------------------------------
    /*! \brief return QMap <dci_name, cip>  from CIP code.
     *  \param atc     atc code from which we want DCI list.
     *  \return QMap <dci_name, cip>
     */
    QMap<QString, QString>               dbi_atc_to_cip_map(const QString &atc);
    const QList < C_BDM_DrugListRecord > dbi_selectProductsList         (const QString &text, C_BDM_PluginI::flags filterFlag   = C_BDM_PluginI::all_filter  );
    QString                              dbi_makeSelectProductsListQuery(const QString &text, C_BDM_PluginI::flags filterFlag);
protected:
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //------------------ PROTECTED ZONE -----------------------------------------------------------------------

    //--------------------------- dbi_database -----------------------------------------------------------
    /*! \brief return intermediate QSqlDatabase (prefixed with dbi_  ) which contains additionals services tables as :
     *    'bdm_druglist' 'my_cache_monographie' .
    */
    C_BaseCommon         *dbi_database() {return m_pDbi_Database;}

    //-------------------------------- dbi_init_database ------------------------------------------------------
    /*! \brief connect and init the additionnal database.
    *  this function needs an ANOTHER VALID and connected DATABASE to acced SQL functions,
    *  to eventualy create additionnal database, if not already created.
    *  So for this, it is necessary that the DERIVED class has already initialised his proper database,
    *  and it is responsable to call this method with his proper database in databaseAlreadyInitialised
    *  argument.
    *  \param const QSqlDatabase &databaseAlreadyInitialised  SQL database already initialised
    *  \return true if all is OK false otherwise.
    */
    bool    dbi_init_database(const QString &baseName, C_BaseCommon *databaseAlreadyInitialised);

    //-------------------------------- setInitialisedSate ------------------------------------------------------
    /*! \brief set Initialised Sate
    */
    void setInitialisedSate(int state);

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //------------------ PRIVATE ZONE -------------------------------------------------------------------------------
private:
    //-------------------------------- verifyDataSourceVersion ------------------------------------------------------
    /*! \brief connect API to source datas via C_BDM_InitPluginI interface which provides data to  C_BDM_Api
     *  \param C_BDM_InitPluginI *pC_BDM_InitPluginI: data interface which provides data to  C_BDM_Api.
     *  \return true in all is ok otherwise false (0)
     */
    int verifyDataSourceVersion();
    //-------------------------------- lastDataSourceVersion ------------------------------------------------------
    /*! \brief return last DataSourceVersion
    */
    QString lastDataSourceVersion();

    //------------------------ updateDrugLists -----------------------------------------
    /*! \brief for a good performance response a rapid special drugs list is implemented
     *  this list is to update each news datas base source versions datas. We proceed update if
     * m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
     *  \param C_BDM_InitPluginI *pC_BDM_InitPluginI: data interface which provides data to  C_BDM_Api.
     *  \return true in all is ok otherwise false
     */
    bool updateDrugLists();
    //-------------------------------- makeSelectProductsListQuery --------------------------------------------
    /*! \brief make select query to select drugs list from user input, for a good performance
     *  response a rapid special drugs list is implemented
     *  this list is to update each news datas base source versions datas. We proceed update if
     *  m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
     *  \param const QString textSelect user text fr select drugs.
     *  \param C_BDM_Api::flags filterFlag selection filter.
     *  \return query result string
     */
    QString  makeSelectProductsListQuery(const    QString &text, C_BDM_PluginI::flags filterFlag);


private:
    int                 m_isInitialised;
//$    C_PatientCtx       *m_pC_PatientCtx;
    C_BaseCommon       *m_pDbi_Database;

};

//=========================================================== C_BDM_Api ===================================
/*! \class C_BDM_Api
 *  \brief Class Api to use for LAP GUI for a good performance response a rapid special drugs list is implemented
 *  this list is to update each news datas base source versions datas. We proceed update if
 *  m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
 *  so wee needs SQL functions to manage this druglist.
 */

class C_BDM_Api : public C_BaseCommon,            // le gestionnaire generique de bases de donnee
                         C_BDM_ApiVar             // le nom des champs de la base de donnees
{
    Q_OBJECT
public:
    enum flags  {no_filter   = 0,
                 atc_filter  = 1,
                 nom_filter  = 2,
                 dci_filter  = 4,
                 ucd_filter  = 8,
                 dc3_filter  = 16,
                 cip_filter  = 32,
                 gen_filter  = 64,
                 vil_filter  = 128,
                 hop_filter  = 256,
                 all_filter  = 511
                };
    enum hit_flag  {ONLY_IF_NOT_EXISTS   = 0,
                    EVEN_IF_EXISTS       = 1,
                    INCREASE_HIT         = 2,
                    FIX_HIT              = 3
                   };

    //------------------------ C_BDM_Api -----------------------------------------
    /*! \brief constructor  C_BDM_Api
     *  \param const QString   &confData: fields definitions.
     *  \param const QString   &params    connexions parameters.
     *  \param C_BDM_PluginI   *pC_BDM_PluginI pointer on drugs datas serveur.
     *  \param QObject         *parent         pointer QObject parent.
    */
    explicit C_BDM_Api(const QString   &confData,                        // definition des champs de la base de donnée (ceux de la liste des drogues)
                       const QString   &params ,                         // parametres de connexion a la bese de données
                       C_BDM_PluginI   *pC_BDM_PluginI,                  // pointeur sur le pC_BDM_PluginI serveur de donnees
                       QObject         *parent             = 0           // objet parent
                      );

    //------------------------ ~C_BDM_Api -----------------------------------------
    /*! \brief destructor  C_BDM_Api
    */
    ~C_BDM_Api();

    //........................ INTERFACE D'INITIALISATION ...................................
    //------------------------ connectToDataSource -----------------------------------------
    /*! \brief connect API to source datas via C_BDM_InitPluginI interface which provides data to  C_BDM_Api
     *  \param C_BDM_InitPluginI *pC_BDM_InitPluginI: data interface which provides data to  C_BDM_Api.
     *  \return true in all is ok otherwise false
     */
    int connectToDataSource(C_BDM_PluginI *pC_BDM_PluginI);

    //-------------------------------- createPosologieHit ------------------------------------------------------
    /*! \brief this table records a posologie drug hit parade adjusted in real time of use.
     *  \param int mode  default = ONLY_IF_NOT_EXISTS/create table only if not exists, otherwise create table even if exists.
     *  \return true in all is ok otherwise false
     */
    int createPosologieHit(int mode = C_BDM_Api::ONLY_IF_NOT_EXISTS );

    //------------------------ isValid -----------------------------------------
    /*! \brief return validation state of this class. if no valid the class can't works
     */
    int      isValid();

    //........................ INTERFACE D'UTILISATION ...................................
    //------------------------ selectProductsList -----------------------------------------
    /*! \brief select drugs list from user input, for a good performance response a rapid special drugs list is implemented
     *  this list is to update each news datas base source versions datas. We proceed update if
     * m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
     *  \param QTreeWidget *pQtreeWidget: QTreeWidget to fill with datas.
     *  \param const QString textSelect user text fr select drugs.
     *  \param C_BDM_Api::flags filterFlag selection filter.
     *  \return number products
     */
    int selectProductsList (  QTreeWidget *pQTreeWidget,                              // QTreeWidget graphique à renseigner avec les données
                              const QString textSelect    = "",                       // saisie partielle d'un texte pour recherche
                              C_BDM_Api::flags filterFlag = C_BDM_Api::all_filter     // filtre de saisie
                            );
    //------------------------ selectProductsList -----------------------------------------
    /*! \brief select drugs list from user input, for a good performance response a rapid special drugs list is implemented
     *  this list is to update each news datas base source versions datas. We proceed update if
     *  m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
     *  \param const QString textSelect user text fr select drugs.
     *  \param C_BDM_Api::flags filterFlag selection filter.
     *  \return QList < C_BDM_DrugListRecord >  list of C_BDM_DrugListRecord  results
     */
    const QList < C_BDM_DrugListRecord > selectProductsList (const QString &texte, C_BDM_PluginI::flags = C_BDM_PluginI::all_filter);
    //------------------------ getListIndications -----------------------------------------
    /*! \brief select indications list from product identified by const QString &id, const QString &id_type
     *  filtred by desired smr
     * m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
     *  \param QString &id code of the drug from wich wee want indications exemple cip code of the drug.
     *  \param QString &id_type type of id code for exemple "CIP" for cip code, "THE" for theriaque code
     *  \param QString &smrLevel list of the smr desired smr levels filter as this
     *  \return QList < C_BDM_DrugListRecord >  list of C_BDM_DrugListRecord  results
     */
    QStringList getListIndications (const QString &id, const QString &id_type, const QString &smrLevel);

    //-------------------------------- fill_ATC_treeWidget ------------------------------------------------------
    /*! \brief fill pQTreeWidget with ATC classification
     *  \param pQTreeWidget QTreeWidget to fill with datas     .
     */
    void fill_ATC_treeWidget(QTreeWidget *pQTreeWidget);

    //-------------------------------- ATC_from_CIP ------------------------------------------------------
    /*! \brief return ATC code from CIP code.
     *  \param const QString& cip drug cip identification .
     *  \return QString ATC code from this drug
     */
    QString ATC_from_CIP(const QString& cip);
    //-------------------------------- code_ATC_To_Name ------------------------------------------------------
    /*! \brief return if ATC libelle from code ATC
     *  \param const QString &code      code ATC .
     *  \return QString return libelle
     */
    QString code_ATC_To_Name(const QString &code);
    //-------------------------------- CIP_to_DrugName ------------------------------------------------------
    /*! \brief return drug name code from CIP code.
     *  \param const QString& cip drug cip identification .
     *  \return QString drug name
     */
    QString CIP_to_DrugName(const QString& cip);

    //-------------------------------- getNextSmrInfoForCIP ------------------------------------------------------
    /*! \brief select SMR and ASM informations for a drug. You must call this methode While returns true.
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \param QString &date           it will contains date        of SMR ASM.
     *  \param QString &level          it will contains level       of SMR ASM..
     *  \param QString &indication     it will contains indication  of SMR ASM..
     *  \param QString &descriptif     it will contains description of SMR ASM..
     *  \param QString &codeCimx       it will contains code CIM10  of SMR ASM..
     *  \return true while datas are presents.. You must loop while returns true.
     */
    bool             getNextSmrInfoForCIP (    const QString &cip,
                                               QString &date,
                                               QString &level,
                                               QString &levelLibelle,
                                               QString &indication,
                                               QString &descriptif,
                                               QString &codeCimx
                                          );
    //-------------------------------- getMonographieFromCIP ------------------------------------------------------
    /*! \brief select monographie for a drug.
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return QString contains monographie
     */
    QString             getMonographieFromCIP (  const QString &cip,   bool dataMustBeReadInCache  = TRUE );
    //-------------------------------- getPriseUnitFormFromCIP ------------------------------------------------------
    /*! \brief return the prise unit form from cip. (comprimés, suppositoires sachets,ampoules,doses kg, cuillères à café etc...)
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return QString with unit form
     */
    QString             getPriseUnitFormFromCIP ( const QString &cip, const QString &commercialName = 0);
    //-------------------------------- drugsList_Size ------------------------------------------------------
    /*! \brief return size of drugs list. This return only cache value and proceed to no SQL opération
     */
    int                 drugsList_Size();
    //-------------------------------- dataSourceVersion ------------------------------------------------------
    /*! \brief return datasource version
     */
    QString dataSourceVersion();
    //--------------------------- get_CIS_RCP_From_CIP -----------------------------------------------------------
    /*! \brief return ANSM (ext afssaps) CIS ans RCP code from CIP code, to use in html request with ANSM (ext afssaps) web site.
     *  \param const QString cip is drug cip code.
     *  \param QString *rcp is pointer on QString to return RCP result if not zero .
     *  \return CIS code string
    */
    QString get_CIS_and_RCP_From_CIP(const QString &cip, QString *rcp =0 );
    //-------------------------------- isStupefiant ------------------------------------------------------
    /*! \brief return if the product identified par Id is a stupefiant
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return 1 is stupefiant
     */
    int             isStupefiant ( const QString &cip );
    //-------------------------------- getDefinedDailyDoseFromCIP ------------------------------------------------------
    /*! \brief return the defined daily dose from cip.
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return QString defined daily dose
     */
    QString   getDefinedDailyDoseFromCIP ( const QString &cip);
    //-------------------------------- getDrugRouteFromCIP ------------------------------------------------------
    /*! \brief return the drug route from cip.
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return QString with the drug route
     */
    QString   getDrugRouteFromCIP ( const QString &cip);
    //-------------------------------- getPosologiesFromCIP ------------------------------------------------------
    /*! \brief return posologies list as posologie grammar QString
     *  \param const QString &cip      code CIP of the drug from wich wee want datas.
     *  \return QStringList with grammar QString list
     */
    QStringList   getPosologiesFromCIP ( const QString &cip );

    //-------------------------------- getInteractionAllergies ------------------------------------------------------
    /*! \brief return allergicals interactions from patient and drug.
     *  \param const QString& cip drug cip identification .
     *  \param QString drugName (default empty) the drug name.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
    QList<C_InterResultPair> getInteractionAllergies(const QString &cip , QString drugName  = "" );
    //-------------------------------- getInteractionCim10 ------------------------------------------------------
    /*! \brief return physiopath interactions from patient and drug.
     *  \param const QString& cip drug cip identification .
     *  \param QString drugName (default empty) the drug name.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
    QList<C_InterResultPair> getInteractionCim10(const QString &cip, QString drugName  = ""  );
    //-------------------------------- getInteractionCim10FromCipList ------------------------------------------------------
    /*! \brief return physiopath interactions from patient and drug.
     *  \param const QStringList &cipList drugs cip list .
     *  \return QList<C_InterResultPair> result interaction pair list
     */
    QList<C_InterResultPair> getInteractionCim10FromCipList( const QStringList &cipList);

    //-------------------------------- getInteractionCim10 ------------------------------------------------------
    /*! \brief return physiopath interactions from patient and drug.
     *  \param const QString& cip drug cip identification .
     *  \param const QStringList &cim10List cim10 pathologies list .
     *  \param QString drugName (default empty) the drug name.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
    QList<C_InterResultPair> getInteractionCim10(const QString &cip, const QStringList &cim10List , QString drugName  = ""  );
    //-------------------------------- getInteractionAgeSexePoidsSportVigil ------------------------------------------------------
    /*! \brief return physiopath interactions from patient and drug.
     *  \param const QStringList &cipList drugs cip list .
     *  \param QString drugName (default empty) the drug name.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
    QList<C_InterResultPair>         getInteractionAgeSexePoidsSportVigil( const QStringList &cipList);

    //-------------------------------- getInteractionAgeSexePoidsSportVigil ------------------------------------------------------
    /*! \brief return physiopath interactions from patient and drug.
     *  \param const QString& cip drug cip identification .
     *  \param QString drugName (default empty) the drug name.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
     QList<C_InterResultPair>        getInteractionAgeSexePoidsSportVigil(const QString &cip, QString drugName ="" );
    //-------------------------------- getInteractionAgeSexePoidsSportVigil ------------------------------------------------------
    /*! \brief return physiopath interactions from patient and drug.
     *  \param const QString& cip drug cip identification .
     *  \param const QString &age patient age .
     *  \param const QString &sexe patient sexe F-M-I.
     *  \param const QString &poids patient poids .
     *  \param const QString &taille patient size .
     *  \param bool sport if true particular attention for doping drugs is required  .
     *  \param bool vigil if true particular attention for drugs which vigilance  alteration is required  .
     *  \param QString drugName (default empty) the drug name.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
     QList<C_InterResultPair>        getInteractionAgeSexePoidsSportVigil(const QString &cip,
                                                                          const QString &age ,
                                                                          const QString &sexe,
                                                                          const QString &poids,
                                                                          const QString &taille,
                                                                          bool  sport       = true,
                                                                          bool  vigil       = true,
                                                                          QString drugName  = ""  );
    //-------------------------------- getInteractionPairFromCipList ------------------------------------------------------
    /*! \brief return interactions xml results from a cip list.
     *  \param const QStringList &cipList      drugs CIP codes list to test.
     *  \return QList<C_InterResultPair> result interaction pair list
     */
    QList<C_InterResultPair> getInteractionPairFromCipList ( const QStringList &cipList);
    //-------------------------------- getInteractionFromCipList ------------------------------------------------------
    /*! \brief return interactions xml results from a cip list.
     *  \param const QStringList &cipList      drugs CIP codes list to test.
     *  \return QStringList where each line is a xml result interaction
     *   each interaction line is a xml structure where :
     *   <itli>           </itli> delimits each interaction line structured as follows.
     *   <itli_code1>     </itli_code1>       delimits first  term code (if exists)
     *   <itli_typcode1>  </itli_typcode1>    delimits first  term codetyp examples "CIP ATC CIM10 CISP NONE AL PO"
     *   <itli_terme1>    </itli_terme1>      delimits first  term libelle text
     *   <itli_code2>     </itli_code2>       delimits second term code (if exists)
     *   <itli_typcode2>  </itli_typcode2>    delimits second term codetyp examples "CIP ATC CIM10 CISP NONE"
     *   <itli_terme2>    </itli_terme2>      delimits second term libelle text
     *   <itli_terme2>    </itli_terme2>      delimits second term libelle text
     *   <itli_texte>     </itli_texte>       delimits text interaction information
     *   <itli_ityp>      </itli_ityp>        delimits interaction type (RESERVED)
     *   <itli_level>     </itli_level>       interraction level
     */
    // QStringList   getInteractionFromCipList ( const QStringList &cipList);
    //-------------------------------- selectPosologieHitList ------------------------------------------------------
    /*! \brief select drugs posologies hits list from drug code
     *  \param const QString &drug_id : as variable name shows, it's drug identification key.
     *  \param const QString &drug_id_type : as variable name shows, it's drug identification key type.
     *  \param int limit : limit number of returns.
     *  \return QMap <int, QString> where int is order number and QString is grammar string started by 'cip/pk!' mention
     */
    QStringList  selectPosologieHitList(const QString &drug_id, const QString &drug_id_type = "CIP", int limit  = 15  );

    //-------------------------------- increasePosologieHit ------------------------------------------------------
    /*! \brief increase a posologie drug hit parade adjusted in real time of use. Create record only if not exists.
     *  \param const QString &grammar :     grammar input string as
     *  "345687/123!ALL_LITERAL=comprimé[1;m|2;M|4;s]/8\n[0.5;m|1;M15r|2;sr30|3;h10-13]/4\n[0.5;m|1;s]/3".
     *  where cip code is 345687 and if present facultative pk code 123 after '/' symbol.
     *  \param const QString &drug_id : as variable name shows, it's drug identification key.
     *  \param const QString &drug_id_type : as variable name shows, it's drug identification key type.
     *  \param int mode  default = INCREASE_HIT/increase hit  else FIX_HIT add the posologie whith fix hit.
     *  \return true in all is ok otherwise false
     */
    int increasePosologieHit(const QString &grammar, const QString &id, const QString &drug_id_type  = "CIP" ,  int mode   = INCREASE_HIT );

    //------------------------ updateDrugLists -----------------------------------------
    /*! \brief for a good performance response a rapid special drugs list is implemented
     *  this list is to update each news datas base source versions datas. We proceed update if
     * m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
     *  \param C_BDM_InitPluginI *pC_BDM_InitPluginI: data interface which provides data to  C_BDM_Api.
     *  \return true in all is ok otherwise false
     */
    bool updateDrugLists(C_BDM_PluginI *pC_BDM_PluginI);

    //-------------------------------- patientContexte ------------------------------------------------------
    /*! \brief return a poointer on C_PatientCtx (patient contexte) .
    */
    C_PatientCtx *patientContexte();
    //-------------------------------- setPatientContexte ------------------------------------------------------
    /*! \brief set patient contexte.
    */
    void setPatientContexte(C_PatientCtx* patientCtx);

//................................ PRIVATE ....................................................................
private :

    //................. initialisations ............................
    int      connectBase(const QString &params);
//-------------------------------- ATC_to_CIP_Map ------------------------------------------------------
    QMap<QString, QString> ATC_to_CIP_Map(const QString &atc);
    //-------------------------------- drugsList_Count ------------------------------------------------------
    /*! \brief return size of drugs list. proceed to SQL opération and set cache list number.
    */
    int      drugsList_Count();
    //-------------------------------- makeSelectProductsListQuery --------------------------------------------
    /*! \brief make select query to select drugs list from user input, for a good performance
     *  response a rapid special drugs list is implemented
     *  this list is to update each news datas base source versions datas. We proceed update if
     *  m_DatasSourceVersion differs from pC_BDM_PluginI->dataSourceVersion();
     *  \param const QString textSelect user text fr select drugs.
     *  \param C_BDM_Api::flags filterFlag selection filter.
     *  \return query result string
     */
    QString  makeSelectProductsListQuery(const    QString &text, C_BDM_Api::flags filterFlag);
    //int      initializeData(C_BDM_PluginI *pC_BDM_PluginI);
    //int      initializeASMR(C_BDM_PluginI *pC_BDM_PluginI);
    //int      initializeSMR (C_BDM_PluginI *pC_BDM_PluginI);
    //void     onSmrAvancement(const QString &label);;

    //................. liste des medicaments ......................

    //................. interrogation dans le systeme d'interraction ...............
    QString          it_getInteractionForTwoComposants(QTreeWidget *pQTreeWidget,
                                                       const QString &class_it,
                                                       const QString &produit_1,
                                                       const QString &produit_2);

    //................. creation des enregistrements dans le systeme d'interraction ...............
    QString          it_createRecord(const QString   &regle, const QString   &mecanisme, const QString   &cat,          const QString &datetime, const QString &owner);
    QString          it_createLink(const QString &pk1, const QString &pk2, const QString &pki, const QString &class_it, const QString &datetime, const QString &owner);
    QString          it_createComposant( const QString &libelle,
                                         const QString &descr,
                                         const QString &id_ctx_type,
                                         const QString &id_ctx ,
                                         const QString &id_class,
                                         const QString &datetime,
                                         const QString &owner);
    int              it_createTables();
signals:

public slots:
private slots:

private:
    int                 it_execQueryGetInteraction(QSqlQuery &query, const QString &requete, QTreeWidget *pQTreeWidget);
    QTreeWidgetItem*    it_getInteractionFromPk(const QString &pk, QTreeWidget *pQTreeWidget);
    QString             it_getComposantNameFromPk(const QString &pk);
private:
    C_PatientCtx       *m_pC_PatientCtx;
    int                 m_isValid;
    long                m_nbToParse;
    int                 m_DrugListNb;
    QSqlQuery          *m_pQSqlQuery;
    bool                m_firstTimeGetNextSmrInfoForCIP;
    QString             m_DatasSourceVersion;
    C_BDM_PluginI      *m_pC_BDM_PluginI;
};

#endif // C_BDM_API_H

