Browse Source

Déplacement des fonctions et macros utilitaires dans __misc__

Création d'une class recherche
Création de la requete pubmed
master
Maxime Wack 11 years ago
parent
commit
6d7ad2f1db
15 changed files with 316 additions and 150 deletions
  1. +2
    -0
      CosMoS/CosMoS.project
  2. +1
    -0
      CosMoS/bdd.cpp
  3. +1
    -31
      CosMoS/bdd.h
  4. +1
    -55
      CosMoS/config.cpp
  5. +1
    -29
      CosMoS/config.h
  6. +3
    -2
      CosMoS/cosmos.cpp
  7. +2
    -0
      CosMoS/cosmos.h
  8. +67
    -0
      CosMoS/misc.cpp
  9. +60
    -0
      CosMoS/misc.h
  10. +0
    -12
      CosMoS/optionsRche.cpp
  11. +0
    -2
      CosMoS/optionsRche.h
  12. +114
    -2
      CosMoS/recherche.cpp
  13. +16
    -3
      CosMoS/recherche.h
  14. +48
    -12
      Sante_Pub.workspace.session
  15. +0
    -2
      testcurl/testcurl.cpp

+ 2
- 0
CosMoS/CosMoS.project View File

@@ -22,6 +22,7 @@
<File Name="correc.cpp"/>
<File Name="optionsRche.cpp"/>
<File Name="recherche.cpp"/>
<File Name="misc.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="include">
<File Name="bdd.h"/>
@@ -37,6 +38,7 @@
<File Name="correc.h"/>
<File Name="optionsRche.h"/>
<File Name="recherche.h"/>
<File Name="misc.h"/>
</VirtualDirectory>
<VirtualDirectory Name="resources">
<File Name="cosmos.fbp"/>


+ 1
- 0
CosMoS/bdd.cpp View File

@@ -2,6 +2,7 @@

class_bdd::class_bdd(const wxString& path_in, wxGrid* grid)
{
//TODO: lock sur la bdd
this->grid = grid;
wxString path = path_in + slash + "cosmos.db";
if (!wxFileExists(path))


+ 1
- 31
CosMoS/bdd.h View File

@@ -8,17 +8,7 @@
#include <wx/grid.h>
#include <wx/utils.h>
#include <sqlite3.h>

#ifdef __WXGTK__
#define slash "/"
#define _C(string) string.fn_str() // wxString -> char*
#define _W(string) string // char* -> wxString
#elif defined( __WXMSW__ )
#define slash "\\"
#define _C(string) (const char*) string.c_str() // wxString -> char*
#define _W(string) wxString::FromAscii(string) // char* -> wxString
#endif
#define _itoW(integer) wxString::Format("%i",integer) // int -> wxString
#include "misc.h"

class class_bdd
{
@@ -46,24 +36,4 @@ class class_bdd
void delcorrection(const wxString& orig);
};

/* CSV BDD GRID
id 0 0 13
n_dossier 1 1 4
nom 3 2 5
prenom 4 3 6
service 6 11 /
etablissement 7 7 10
travail 12 8 11
thème 13 6 9
publi prévue 18 10 /
responsable 19 4 7
consultant 20 5 8
date 21 9 12
==========================================
resultats 4 0
publi 1 1
publi_CHU 2 2
cs_associe 3 3
*/

#endif //__bdd__

+ 1
- 55
CosMoS/config.cpp View File

@@ -178,58 +178,4 @@ void config::downrule(int index)
ruleset[index+1] = ruleset[index];
ruleset[index] = temp;
}
}

wxString config::bool2W(bool in)
{
if (in)
return wxString("true");
else
return wxString("false");
}

bool config::W2bool(wxString in)
{
if (in == "true")
return true;
else
return false;
}

wxString config::op2W(int in)
{
switch (in)
{
case AND: return "AND"; break;
case OR: return "OR"; break;
default: return "AND";break;
};
}
int config::W2op(wxString in)
{
if (in == "AND")
return AND;
else if (in == "OR")
return OR;
return AND;
}

wxString config::type2W(int in)
{
switch (in)
{
case delai: return "delai"; break;
case dates: return "dates"; break;
default: return "delai"; break;
};
}

int config::W2type(wxString in)
{
if (in == "delai")
return delai;
else if (in == "dates")
return dates;
return delai;
}
}

+ 1
- 29
CosMoS/config.h View File

@@ -5,20 +5,10 @@
#include <wx/window.h>
#include <wx/filefn.h>
#include <vector>
#include "misc.h"

using namespace std;

#ifdef __WXGTK__
#define slash "/"
#define _C(string) string.fn_str() // wxString -> char*
#define _W(string) string // char* -> wxString
#elif defined( __WXMSW__ )
#define slash "\\"
#define _C(string) (const char*) string.c_str() // wxString -> char*
#define _W(string) wxString::FromAscii(string) // char* -> wxString
#endif
#define _itoW(integer) wxString::Format("%i",integer) // int -> wxString

typedef struct trule
{
wxString name;
@@ -35,18 +25,6 @@ typedef struct trule
int retmax;
}rule;

enum
{
AND=0,
OR=1,
};

enum
{
delai = 0,
dates = 1
};

class config
{
protected:
@@ -74,12 +52,6 @@ public:
void modrule(int index, rule temp);
void uprule(int index);
void downrule(int index);
wxString bool2W(bool in);
bool W2bool(wxString in);
wxString op2W(int in);
int W2op(wxString in);
wxString type2W(int in);
int W2type(wxString in);
// GETters et SETters
void SetDbpath(const wxString& dbpath) {this->dbpath = dbpath;}


+ 3
- 2
CosMoS/cosmos.cpp View File

@@ -19,7 +19,7 @@ cosmosGUI( parent )
bdd = new class_bdd(configuration->GetDbpath(), grid_Consults);
bdd->updategrid();
fenetre_corrections = new correc(this, bdd);
recherche = new class_recherche(configuration, bdd, grid_Consults);
}

void cosmos::OnImport( wxCommandEvent& event )
@@ -41,6 +41,7 @@ void cosmos::OnExport( wxCommandEvent& event )

void cosmos::OnQuit( wxCommandEvent& event )
{
delete recherche;
delete fenetre_corrections;
delete bdd;
delete fenetre_options;
@@ -50,7 +51,7 @@ void cosmos::OnQuit( wxCommandEvent& event )

void cosmos::OnStart( wxCommandEvent& event )
{
// TODO: Implement OnStart
recherche->start();
}

void cosmos::OnOptionsRche( wxCommandEvent& event )


+ 2
- 0
CosMoS/cosmos.h View File

@@ -12,6 +12,7 @@ Subclass of cosmosGUI, which is generated by wxFormBuilder.
#include "config.h"
#include "correc.h"
#include "optionsRche.h"
#include "recherche.h"

/** Implementing cosmosGUI */
class cosmos : public cosmosGUI
@@ -22,6 +23,7 @@ protected:
class_bdd* bdd;
correc* fenetre_corrections;
optionsRche* fenetre_optionsRche;
class_recherche* recherche;
// Handlers for cosmosGUI events.
void OnImport( wxCommandEvent& event );
void OnExport( wxCommandEvent& event );


+ 67
- 0
CosMoS/misc.cpp View File

@@ -0,0 +1,67 @@
#include "misc.h"

wxString bool2W(bool in)
{
if (in)
return wxString("true");
else
return wxString("false");
}

bool W2bool(wxString in)
{
if (in == "true")
return true;
else
return false;
}

wxString op2W(int in)
{
switch (in)
{
case AND: return "AND"; break;
case OR: return "OR"; break;
default: return "AND";break;
};
}
int W2op(wxString in)
{
if (in == "AND")
return AND;
else if (in == "OR")
return OR;
return AND;
}

wxString type2W(int in)
{
switch (in)
{
case delai: return "delai"; break;
case dates: return "dates"; break;
default: return "delai"; break;
};
}

int W2type(wxString in)
{
if (in == "delai")
return delai;
else if (in == "dates")
return dates;
return delai;
}

wxDateTime int2date(int in)
{
wxDateTime out;
out.ParseFormat(_itoW(in), "%Y%m%d");
return out;
}

int date2int(wxDateTime in)
{
return wxAtoi(in.Format("%Y%m%d"));
}

+ 60
- 0
CosMoS/misc.h View File

@@ -0,0 +1,60 @@
#ifndef __misc__
#define __misc__

#include <wx/string.h>
#include <wx/datetime.h>

#ifdef __WXGTK__
#define slash "/"
#define _C(string) string.fn_str() // wxString -> char*
#define _W(string) string // char* -> wxString
#elif defined( __WXMSW__ )
#define slash "\\"
#define _C(string) (const char*) string.c_str() // wxString -> char*
#define _W(string) wxString::FromAscii(string) // char* -> wxString
#endif
#define _itoW(integer) wxString::Format("%i",integer) // int -> wxString

enum
{
AND=0,
OR=1,
};

enum
{
delai = 0,
dates = 1
};

wxString bool2W(bool in);
bool W2bool(wxString in);
wxString op2W(int in);
int W2op(wxString in);
wxString type2W(int in);
int W2type(wxString in);
wxDateTime int2date(int in);
int date2int(wxDateTime in);

/* CSV BDD GRID
id 0 0 13
n_dossier 1 1 4
nom 3 2 5
prenom 4 3 6
service 6 11 /
etablissement 7 7 10
travail 12 8 11
thème 13 6 9
publi prévue 18 10 /
responsable 19 4 7
consultant 20 5 8
date 21 9 12
==========================================
resultats 4 0
publi 1 1
publi_CHU 2 2
cs_associe 3 3
*/


#endif //__misc__

+ 0
- 12
CosMoS/optionsRche.cpp View File

@@ -224,16 +224,4 @@ void optionsRche::updateGUI( wxCommandEvent& event )
textctrl_ville->Enable();
else
textctrl_ville->Disable();
}

wxDateTime optionsRche::int2date(int in)
{
wxDateTime out;
out.ParseFormat(_itoW(in), "%Y%m%d");
return out;
}

int optionsRche::date2int(wxDateTime in)
{
return wxAtoi(in.Format("%Y%m%d"));
}

+ 0
- 2
CosMoS/optionsRche.h View File

@@ -26,8 +26,6 @@ protected:
void OnUpdate( wxCommandEvent& event );
void OnOk( wxCommandEvent& event );
wxDateTime int2date(int in);
int date2int(wxDateTime in);
public:
/** Constructor */
optionsRche( wxWindow* parent, config* configuration );


+ 114
- 2
CosMoS/recherche.cpp View File

@@ -5,16 +5,86 @@ class_recherche::class_recherche(config* configuration, class_bdd* bdd, wxGrid*
this->configuration = configuration;
this->bdd = bdd;
this->grid = grid;
curlhandle = curl_easy_init ();
curl_easy_setopt (curlhandle, CURLOPT_WRITEFUNCTION, WriteDataCallback);
curl_easy_setopt (curlhandle, CURLOPT_WRITEDATA, (void*)&curldata);
}

class_recherche::~class_recherche()
{
curl_easy_cleanup (curlhandle);
curl_global_cleanup ();
}

void class_recherche::recherche(int row, rule regle)
void class_recherche::start()()
{
//wxArrayInt selection = grid_Consults->GetSelectedRows();
//for (int i=0; i < (int)selection.GetCount(); i++)
}

wxString class_recherche::build(int row, rule regle)
{
wxString requete="?db=pubmed&term=";
bool both = false;
if (grid->GetCellValue(row, 5) == "")
regle.usedemandeur = false;
if (grid->GetCellValue(row, 7) == "")
regle.useresponsable = false;
if (grid->GetCellValue(row, 8) == "")
regle.useconsultant = false;
if (regle.usedemandeur && regle.useresponsable)
{
both = true;
requete << "(";
}
if (regle.usedemandeur)
requete << parsedemandeur(grid->GetCellValue(row, 5), grid->GetCellValue(row, 6), regle.opdemandeur);
if (both)
requete << " " << op2W(regle.opboth) << " ";
if (regle.useresponsable)
requete << parseresponsable(grid->GetCellValue(row,7), regle.opresponsable);
if (both)
requete << ")";
if (regle.useconsultant)
requete << " AND " << parseconsultant(grid->GetCellValue(row,8));
if (regle.useville)
requete << " AND " << regle.ville << "[Affiliation]";
if (regle.usesuppl)
requete << " AND " << regle.suppl;
requete << "&retmax=" << _itoW(regle.retmax);
if (regle.usefin)
{
requete << "&datetype=pdat&mindate=";
wxDateTime temp;
if (regle.type_date == dates)
temp = int2date(regle.fin);
if (regle.type_date == delai)
{
temp.ParseFormat(grid->GetCellValue(row, 12), "%d/%m/%Y");
temp += wxDateSpan(regle.fin);
}
requete << temp.Format("%Y/%m/%d");
temp.SetToCurrent();
requete << "&maxdate=" << temp.Format("%Y/%m/%d");
}
requete.Replace(" ", "+");
return requete;
}

wxString class_recherche::parsedemandeur(wxString nom, wxString prenom, int op)
{
wxString out, nom1, nom2, prenom1, prenom2;
@@ -36,14 +106,18 @@ wxString class_recherche::parsedemandeur(wxString nom, wxString prenom, int op)
if (prenom1.Find('-') != wxNOT_FOUND)
prenom1 = prenom1.BeforeFirst('-').Left(1) + prenom1.AfterFirst('-').Left(1);
else
prenom1 = prenom1.Left(1);
if (prenom2.Find('-') != wxNOT_FOUND)
prenom2 = prenom2.BeforeFirst('-').Left(1) + prenom2.AfterFirst('-').Left(1);
else
prenom2 = prenom2.Left(1);
if (mult)
{
out << "(" << nom1 << " " << prenom1 << "[Author]";
//out << " " << op2W(op) << " ";
out << " " << op2W(op) << " ";
out << nom2 << " " << prenom2 << "[Author])";
}
else
@@ -54,11 +128,49 @@ wxString class_recherche::parsedemandeur(wxString nom, wxString prenom, int op)

wxString class_recherche::parseresponsable(wxString responsable, int op)
{
wxString out;
if (responsable.Find('/') == wxNOT_FOUND)
out = responsable;
else
{
out = "(" + responsable.BeforeFirst('/') + "[Author]";
out << " " << op2W(op) << " ";
out << responsable.AfterFirst('/') << "[Author])";
}
return out;
}

wxString class_recherche::parseconsultant(wxString consultant)
{
wxString out, nom, prenom;
prenom = consultant.BeforeFirst(' ');
nom = consultant.AfterFirst(' ');
if (prenom.Find('-') != wxNOT_FOUND)
prenom = prenom.BeforeFirst('-').Left(1) + prenom.AfterFirst('-').Left(1);
else
prenom = prenom.Left(1);
out = nom + " " + prenom + "[Author]";
return out;
}

static size_t WriteDataCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
CurlData *mem = (CurlData *)userp;
mem->content = (char*) realloc(mem->content, mem->size + realsize + 1);
if (mem->content == NULL) {
printf("Echec de realloc (I'd like to see that happen !!!!!)");
exit(EXIT_FAILURE);
}
memcpy(&(mem->content[mem->size]), contents, realsize);
mem->size += realsize;
mem->content[mem->size] = 0;
return realsize;
}

+ 16
- 3
CosMoS/recherche.h View File

@@ -1,11 +1,17 @@
#ifndef __recherche__
#define __recherche__

#include <wx/msgdlg.h>
#include <wx/grid.h>
#include <curl/curl.h>
#include "config.h"
#include "bdd.h"
//#include "tinyxml2.h"
#include "config.h"
#include "tinyxml2.h"

typedef struct _CurlData {
char *content;
size_t size;
} CurlData;

class class_recherche
{
@@ -14,7 +20,10 @@ private:
class_bdd* bdd;
wxGrid* grid;
void recherche(int row, rule regle);
CURL* curlhandle;
CurlData curldata;
wxString build(int row, rule regle);
wxString parsedemandeur(wxString nom, wxString prenom, int op);
wxString parseresponsable(wxString responsable, int op);
wxString parseconsultant(wxString consultant);
@@ -23,6 +32,10 @@ public:
class_recherche(config* configuration, class_bdd* bdd, wxGrid* grid);
~class_recherche();
void start();
};

static size_t WriteDataCallback(void *contents, size_t size, size_t nmemb, void *userp);

#endif //__recherche__

+ 48
- 12
Sante_Pub.workspace.session View File

@@ -1,36 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<Session Name="G:\Commun\Etudiants\Maxime W\Projets\Sante_Pub.workspace">
<int Value="4" Name="m_selectedTab"/>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\Sante_Pub.workspace" Name="m_workspaceName"/>
<Session Name="C:\Projets\Sante_Pub.workspace">
<int Value="3" Name="m_selectedTab"/>
<wxString Value="C:\Projets\Sante_Pub.workspace" Name="m_workspaceName"/>
<TabInfoArray Name="TabInfoArray">
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmos.h" Name="FileName"/>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\misc.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="0" Name="CurrentLine"/>
<int Value="4" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\misc.cpp" Name="FileName"/>
<int Value="42" Name="FirstVisibleLine"/>
<int Value="65" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmos.h" Name="FileName"/>
<int Value="2" Name="FirstVisibleLine"/>
<int Value="25" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmos.cpp" Name="FileName"/>
<int Value="30" Name="FirstVisibleLine"/>
<int Value="53" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\config.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="0" Name="CurrentLine"/>
<int Value="19" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\config.cpp" Name="FileName"/>
<int Value="157" Name="FirstVisibleLine"/>
<int Value="180" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\bdd.h" Name="FileName"/>
<int Value="13" Name="FirstVisibleLine"/>
<int Value="36" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\bdd.cpp" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="14" Name="CurrentLine"/>
<int Value="4" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\config.h" Name="FileName"/>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\recherche.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="16" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\recherche.cpp" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="0" Name="CurrentLine"/>
<int Value="21" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmosGUI.cpp" Name="FileName"/>
<int Value="150" Name="FirstVisibleLine"/>
<int Value="7" Name="CurrentLine"/>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\testcurl\testcurl.cpp" Name="FileName"/>
<int Value="15" Name="FirstVisibleLine"/>
<int Value="38" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
</TabInfoArray>


+ 0
- 2
testcurl/testcurl.cpp View File

@@ -56,8 +56,6 @@ void testcurl::OnGo( wxCommandEvent& event )
}


static size_t WriteDataCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;


Loading…
Cancel
Save