Medial Code Documentation
Loading...
Searching...
No Matches
InfraMed.h
1//
2// InfraMed.h - classes to use data repositories and their indexes
3//
4
5#ifndef __INFRAMED__H__
6#define __INFRAMED__H__
7//#define _USE_AS_DLL
8#ifdef _USE_AS_DLL
9#ifdef __INFRAMED_DLL
10#define DLLEXTERN __declspec(dllexport)
11#else
12#define DLLEXTERN __declspec(dllimport)
13#endif
14#else
15#define DLLEXTERN
16#endif
17
19#include "MedSparseVec.h"
21#include <map>
22#include <vector>
23#include <string>
24#include "MedDictionary.h"
25#include "MedSignals.h"
26#include <fstream>
27#include <thread>
28#include <mutex>
29
30using namespace std;
31
32#define MED_MAGIC_NUM 0x0123456789abcdef
33#define REPOSITORY_FULL_FORMAT 0x0
34#define REPOSITORY_STRIPPED_FORMAT 0x1
35
36#define MAX_PID_NUMBER 20000000
37
38#define MAX_SID_NUMBER 100000
39#define MAX_SIGNALS 1000
40
41// next is needed in some places, leaving last 16 places for marking some needed states
42#define MAX_ID_NUM ((unsigned int)0xfffffff0)
43
44// general agreed upon usefull defines
45#define GENDER_BOTH 0
46#define GENDER_MALE 1
47#define GENDER_FEMALE 2
48#define MIN_DATE 19000101
49#define MAX_DATE 21000101
50#define INFRAMED_MIN_AGE 0
51#define INFRAMED_MAX_AGE 150
52
53class MedRepository;
54class PidRec;
55class InMemRepData;
56
58public:
59 string name = "";
60 int buf_size = 0;
61 int buf_len = 0;
62 unsigned char *buf = NULL;
63 unsigned long long buf_start_in_file = 0;
64
65 static const int default_buf_size = 128 * 1024;
66
67 int open(const string &fname);
68 int open(const string &fname, const int bsize);
69 void close();
70 unsigned long long read(unsigned char *outb, unsigned long long pos, unsigned long long len);
71
72 ifstream *inf = NULL;
73
74
75};
76
77class IndexElem {
78public:
79 short file_num;
80 unsigned long long pos_in_file;
81 void *data;
82 int len; // len is always in bytes (to allow for size/alloc calculations)
83
84 IndexElem() { file_num = -1; pos_in_file = 0; data = NULL; len = 0; }
85};
86
88public: // 12 bytes per entry instead of 22
89 unsigned int pos_add;
90 unsigned int data_ptr_add;
91 unsigned int len; // could be short however class is always being padded to 4x so using a full int
92
93 CompactIndexElem() { pos_add = 0; data_ptr_add = 0; len = 0; }
94};
95
96//extern mutex *index_table_locks; //[MAX_SID_NUMBER];
97
98// next is a fairly memory/speed efficient index to hold positions of a continous signal in a file/memory.
100public:
101 // thread safing
102 //mutex m_lock;
103
104
105 // using MedSparseVec - but also saving mem by getting len with the diff to the next entry
107 int last_len; // length of last element inserted to sv
108 int sid; // sid for this table
109
110 unsigned long long base; // base position in a file or in memory
111 unsigned int factor; // size of a single record for the sid
112
113
114 unsigned char *work_area; // ptr to data in memory (NULL if there's no data loaded)
115 int work_area_allocated; // signing if we allocated the work_area for data (and need to delete[] it) or not.
116 unsigned long long w_size;
117 int is_loaded;
118 int full_load; // signing wheather we loaded a full signal or a partial one
119 unsigned long long tot_size;
120 double tot_size_gb;
121 int is_locked; // will not be freed if locked !!!
122
123 unsigned int acc; // accumulator for easier insertions
124
125 void init() {
126 sid = 0; sv.set_def(0); acc = 0; w_size = 0; tot_size = 0; tot_size_gb = 0; is_loaded = 0; full_load = 0;
127 is_locked = 0; work_area_allocated = 0; work_area = NULL;
128 }
129 IndexTable() { init(); }
130
131 int insert(unsigned int pid, int len) { int rc = insert(pid, acc, len); if (rc >= 0) acc += (unsigned int)len; return rc; }
132 int insert(unsigned int pid, unsigned int delta, int len); // { last_len = len; return sv.insert(pid, delta); }
133 int get(const unsigned int pid, unsigned long long &pos, int &len);
134 int get_len(const unsigned int pid);
135 unsigned long long get_data_size(); // returns the size in bytes required for the actual data accompanying this index table
136
137 void clear(); // also deallocated data if needed
138
139 // locking prevents clearing or reading if already loaded
140 void lock(); //{ /*lock_guard<mutex> guard(m_lock);*/ is_locked = 1; }
141 void unlock(); // { /*lock_guard<mutex> guard(m_lock);*/ is_locked = 0; }
142
143 // serializations
144 size_t get_size();
145 size_t serialize(unsigned char *blob);
146 size_t deserialize(unsigned char *blob);
147
148 // i/o to/from bin file
149 int write_to_file(string &fname);
150 int read_from_file(string &fname);
151
152 // i/o to read index and data as well
153 int read_index_and_data(string &idx_fname, string &data_fname);
154 int read_index_and_data(string &idx_fname, string &data_fname, const vector<int> &pids_to_include);
155
156};
157
158class MedIndex {
159public:
160 int rep_mode;
161
162 vector<string> ifnames;
163
164 void clear() { ifnames.clear(); sid2idx.clear(); pid2idx.clear(); idx_i.clear(); idx.clear(); pids.clear(); signals.clear(); n_pids = 0; n_signals = 0; sid_in.clear(); }
165
166 int read_index(vector<string> &fnames);
167 int read_sub_index(vector<string> &fnames, const vector<int> &pids_to_include, const vector<int> &signals_to_include); // empty vector - means all are chosen
168
169 inline void *get_ind_elem(int pid, int sid, unsigned int &len);
170 inline IndexElem *get_ind_elem2(int pid, int sid);
171
172 //int write_index(string &fname);
173
174 unsigned long long get_index_max_data_size();
175 void set_mem_ptrs_off();
176
177 // next reads all the data parts that match the index in memory
178 int read_all_data(unsigned char *&work_area, unsigned long long &wlen, vector<string> &data_fnames);
179 //int MedIndex::read_all_data(unsigned char *&work_area, unsigned long long &wlen, vector<string> &data_fnames, vector<int> pids_to_take, vector<int> sids_to_take);
180 int read_full_data(unsigned char *&work_area, unsigned long long &wlen, vector<string> &data_fnames);
181
182 // next reads index and data for a single signal using an IndexTable index (mode 3 and up).
183 int read_index_table_and_data(int sid, string &idx_fname, string &data_fname, const vector<int> &pids_to_include,
184 unsigned char *w_area, unsigned long long &data_size);
185 int read_index_table_and_data(int sid, string &idx_fname, string &data_fname, const vector<int> &pids_to_include);
186 int update_pids();
187
188 // new modes (2 and up) related
189 //int get_idx_file_mode(const string &fname);
190
191
192 // lists of all pids and signals in the index
193 vector<int> pids;
194 vector<int> signals;
195 map<int, int> sid_in;
196
197 // mode 3 index - (much less variables !!)
198 vector<IndexTable> index_table;
199
200
201 int contains_pid(int pid) { return (pid_idx[pid] >= 0); }
202
203 MedRepository *my_rep;
204 int min_pid_num;
205 int max_pid_num;
206
207 MedIndex() { min_pid_num = -1; max_pid_num = -1; rep_mode = 0; }
208
209private:
210 int mode;
211
212 int get_mode(const string &fname);
213 int read_index_mode0(const string &fname, const vector<int> &pids_to_include, const vector<int> &signals_to_include);
214 int read_index_mode0_direct(const string &fname, const vector<int> &pids_to_include, const vector<int> &signals_to_include);
215 int read_index_mode0_new_direct(const string &fname, int f_factor, const vector<int> &pids_to_include, const vector<int> &signals_to_include);
216 int prep_idx_i();
217 int prep_idx_i_direct();
218
219 // mode 0 data elements
220 int n_pids;
221 int n_signals;
222 map<int, int> sid2idx;
223 map<int, int> pid2idx;
224 vector<vector<unsigned int>> idx_i; // first dimension: signals, second: pids
225 vector<IndexElem> idx;
226
227 vector<vector<unsigned int>> idx_i_base;
228 vector<vector<unsigned char>> idx_i_add;
229
230 vector<vector<CompactIndexElem>> idx_recs;
231 vector<IndexElem> idx_recs_base;
232 vector<int> i_sid_type_byte_len;
233 vector<int> i_sid_factor;
234
235 vector<vector<unsigned int>> last_pid;
236 //vector<int> idx_factor;
237 //vector<int> idx_fno;
238
239
240 // direct mapping
241 vector<unsigned int> sid_idx;
242 vector<unsigned int> pid_idx;
243 int min_pid, max_pid;
244 unsigned int n_pids_in_index;
245 unsigned int n_signals_in_index;
246 vector<int> pid_seen;
247
248 vector<unsigned int> idx_pid;
249 vector<unsigned int> idx_sid;
250
251
252
253};
254
255// InMemRepData is a class holding RAW data to be loaded into a repository
256// it works under the assumption of a small number of pids (1-1000 more or less).
257// Large datasets would better be from an already made repository
258// The advantages are that no loading from a file is needed and that there are API's to
259// load data in and to connect this to a repository.
260// API's are more c-style to enable easier work with C# API's
262public:
263 MedRepository * my_rep;
264 map<pair<int, int>, pair<int, vector<char>>> data; // map from a pair of pid,sid to a pair of nvals, data vector
265
266 // init_rep must be called first , as we must know the sigs names/types/etc...
267 void init_rep(MedRepository &rep) { my_rep = &rep; }
268 //int init_sigs(string &sigs_fname) { return my_rep->sigs.read({ sigs_fname }); }
269
270 // insert data basic API's . These are for a single pid/sid but a vector of elements can be loaded
271 // data can be insertred in any order and several times per pid/sid , different pids are supported too.
272 int insertData(int pid, int sid, int *time_data, float *val_data, int n_time, int n_val);
273 int insertData(int pid, const char *sig, int *time_data, float *val_data, int n_time, int n_val);
274 static int insertData_to_buffer(int pid, int sid, int *time_data, float *val_data, int n_time, int n_val,
275 const MedSignals &sigs, map<pair<int, int>, pair<int, vector<char>>> &data);
276
278 void erase_pid_data(int pid);
279
280
281 // This sort action MUST be called after inserting all data, otherwise the order of the elements in each pid-sid vector will be the inserting order
282 int sortData();
283 int sort_pid_sid(int pid, int sid); // helper func - sort single vector
284
285 // clearing
286 void clear() { data.clear(); }
287
288 // a repository get function to use with this type of data
289 static void *get_from_buffer(int pid, int sid, int &len,const map<pair<int, int>, pair<int, vector<char>>> &data);
290 void *get(int pid, int sid, int &len);
291
292 // debug and prints
293 int print_all();
294 int print(int pid);
295 int print(int pid, int sid);
296
297 // serializer for data
299
300};
301
302
303class DLLEXTERN MedRepository {
304public:
305 int rep_mode;
306 string rep_files_prefix;
307
308 string desc;
309 string config_fname;
310 string path;
311 string metadata_path;
312 vector<string> dictionary_fnames;
313 vector<string> signal_fnames;
314 vector<string> data_fnames;
315 vector<string> index_fnames;
316 string fsignals_to_files;
317 int min_pid_num;
318 int max_pid_num;
319 int time_unit;
320 int format;
321
322 MedIndex index;
324 MedSignals sigs;
325 vector<int> pids;
326 vector<int> all_pids_list;
327
328 InMemRepData in_mem_rep; // for mode of running in in_mem
329
330 //-------------------------------------------------------------------
331 // most useful APIs - more overloads below
332 //-------------------------------------------------------------------
333
334 // reading a repository for a group of pids and signals. Empty group means all of it.
335 int read_all(const string &conf_fname);
336 int read_all(const string &conf_fname, const vector<int> &pids_to_take, const vector<string> &signals_to_take);
337 int read_all(const string &conf_fname, const vector<int> &pids_to_take, const vector<int> &signals_to_take);
338
339 // reading without any signal (will later be loaded with load()
340 int init(const string &conf_fname);
341
342 // getting the data for a pid,signal . Pointer to start returned, len elements inside. If not found NULL and 0 returned.
343 inline void *get(int pid, const string &sig_name, int &len);
344 inline void *uget(int pid, const string &sig_name, UniversalSigVec &usv);
345 // inline void *get(int pid, int sid, int &len); // use this variant inside big loops to avoid map from string to int. // default variant
346 inline void *get_all_modes(int pid, int sid, int &len);
347 inline void *uget(int pid, int sid, UniversalSigVec_legacy &usv); // Universal vec API, use this inside loops to avoid string map
348 inline void *uget(int pid, int sid, GenericSigVec &gsv);
349 void * (MedRepository::*get_ptr)(int, int, int&) = &MedRepository::get3;
350 inline void *get(int pid, int sid, int &len) { return (this->*get_ptr)(pid, sid, len); }
351
352 //-------------------------------------------------------------------
353
354 inline void *get_in_mem(int pid, int sid, int &len) { return in_mem_rep.get(pid, sid, len); }
355 void switch_to_in_mem_mode() { in_mem_rep.clear(); in_mem_rep.my_rep = (MedRepository *)this; get_ptr = &MedRepository::get_in_mem; }
356 bool in_mem_mode_active() { return (get_ptr == &MedRepository::get_in_mem); }
357
358 //-------------------------------------------------------------------
359 int read_config(const string &fname);
360
361 int read_dictionary();
362 int read_dictionary(const string &dname);
363
364 int read_signals();
365 int read_signals(const string &fname);
366
367 int read_index();
368 int read_index(const vector<int> &pids_to_take, const vector<int> &signals_to_take);
369 int read_index(vector<string> &fnames);
370 int read_index(vector<string> &fnames, const vector<int> &pids_to_take, const vector<int> &signals_to_take);
371 int read_index_tables(const vector<int> &pids_to_take, const vector<int> &signals_to_take);
372
373 // reading the data matching the current index (always read an index BEFORE reading data)
374 int read_data();
375 int read_data(const string &fname);
376 int read_data(vector<string> &fnames);
377 //int read_data(string &fname, vector<int> &pids_to_take, vector<int> &signals_to_take);
378 void free_data();
379
380 // main initializing routines of repository from disk
381 int read_all(const string &conf_fname, const vector<int> &pids_to_take, const vector<int> &signals_to_take, int read_data_flag);
382
383 int read_all(const string &conf_fname, const vector<int> &pids_to_take, const vector<string> &signals_to_take, int read_data_flag);
384
385 // mode 3 and up allows load and free of signals - overloads below
386 int load(const vector<int> &sids, vector<int> &pids_to_take);
387
388 // locking a sig in memory: will not be freed with free() functions - overloads below
389 int lock_all_sigs();
390 int lock(const vector<int> &sids);
391
392 int unlock_all_sigs();
393 int unlock(const vector<int> &sids);
394
395 // when freeing: locked signals will NOT be freed, in order to free all unlock all first - overloads below
396 int free_all_sigs();
397 int free(const vector<int> &sids);
398
399 double bound_gb;
400 int free_to_bound() { return free_to_bound(bound_gb); } // calls free_to_bound with default set memory bound
401 int free_to_bound(double _bound_gb); // frees unlocked signals until getting below the bound
402
403 // default is inifinity (1000gb), however - if set, the repository will try to free signals in order to get below this bound
404 // it can not free locked in signals, so in some cases the overall memory usage could be higher
405 int set_max_mem(double gb_mem) { bound_gb = gb_mem; return 0; }
406
407 MedRepository() { path = ""; metadata_path = ""; work_area = NULL; work_size = 0; fsignals_to_files = ""; index.my_rep = this; min_pid_num = -1; max_pid_num = -1; rep_mode = 0; rep_files_prefix = "rep"; bound_gb = 100.0; sigs.my_repo = this; }
409 //fprintf(stderr, "rep free\n"); fflush(stderr);
410 if (work_area) {
411 //fprintf(stderr, "~MedRepository before delete[] work_area %d", work_area);
412 delete[] work_area;
413 //fprintf(stderr, "~MedRepository after delete[] work_area %d", work_area);
414 work_area = NULL;
415 }
416 free_all_sigs();
417 //fprintf(stderr, "rep free ended\n"); fflush(stderr);
418 };
419 //int build_full_format_index();
420
421 void clear();
422
423 // main access routine: gets a pointer to data given pid and sid and its len (in vaiable type units).
424 // When there's no data returns NULL and len==0
425 inline void *get3(int pid, int sid, int &len);
426
427 // common request: get a list of all values BEFORE (<) a given date
428 SDateVal *get_before_date(int pid, int sid, int date, int &len);
429 SDateVal *get_before_date(int pid, const string &sig_name, int date, int &len);
430
431 // api for SDateVal (most common), to get ptr to a valur relative to a specific date
432 // mode options are "==" "<=" ">=" "<" ">"
433 // these return the first one exactly at the same date, or the first one just before (<= or <) etc.
434 SDateVal *get_date(int pid, int sid, int date, const string &mode);
435 SDateVal *get_date(int pid, const string &sig_name, int date, const string &mode);
436
437
438 // test if repository has a specific pid or a specific signal
439 int contains_pid(int pid) { return index.contains_pid(pid); }
440 int contains_sid(int sid);
441
442 // printing routines (mainly for debugging)
443 void print_vec_dict(void *data, int len, int pid, int sid);
444 void long_print_vec_dict(void *data, int len, int pid, int sid);
445 void long_print_vec_dict(void *data, int len, int pid, int sid, int from, int to);
446 void long_print_vec_dict(void *data, int len, int pid, int sid, int index);
447 void print_channel_helper(int sid, int channel, float val);
448 string get_channel_info(int sid, int channel, float val);
449 string convert_date(int d, int sid);
450 void print_data_vec_dict(int pid, int sid);
451 void long_print_data_vec_dict(int pid, int sid);
452 void long_print_data_vec_dict(int pid, int sid, int from, int to);
453 void print_csv_vec(void * data, int len, int pid, int sid, bool dict_val);
454 void convert_pid_sigs(const UniversalSigVec &usv, vector<pair<vector<string>, vector<string>>> &pid_result, const string &sig_name, int sig_id, int limit_count);
455 void print_pid_sig(int pid, const string &sig_name, const vector<pair<vector<string>, vector<string>>> &usv);
456
457 // getting all the dates for a pid in which there was at least one of the given signals
458 int get_dates_with_signal(int pid, vector<string> &sig_names, vector<int> &dates);
459
460 int get_pids_with_sig(const string &sig_name, vector<int> &in_pids); // getting all pids in rep that have at least once the signal.
461
462 //-----------------------------------------------------------
463 // useful overloads
464 //-----------------------------------------------------------
465 int load(const string &sig_name);
466 int load(const int sid);
467 int load(const vector<string> &sig_names);
468 int load(const vector<int> &sids);
469 int load(const string &sig_name, vector<int> &pids_to_take);
470 int load(const int sid, vector<int> &pids_to_take);
471 int load_pids_sorted(const int sid, vector<int> &pids_to_take);
472 int load(const vector<string> &sig_names, vector<int> &pids_to_take);
473
474 int lock(const string &sig_name);
475 int lock(const int sid);
476 int lock(const vector<string> &sig_names);
477
478 int unlock(const string &sig_name);
479 int unlock(const int sid);
480 int unlock(const vector<string> &sig_names);
481
482 int free(const string &sig_name);
483 int free(const int sid);
484 int free(const vector<string> &sig_names);
485
486 int read_pid_list();
487
488 int generate_fnames_for_prefix();
489
493 void load_additional_dict(const string &dict_path);
497 void clear_additional_dict();
498private:
499 int get_data_mode(const string &fname);
500 unsigned char *work_area;
501 unsigned long long work_size;
502
503 vector<string> _addtional_dict_path;
504};
505
506
507//===============================================================
508// simplifying iterations over several signals
510public:
511 MedRepository * rep;
512 vector<string> sig_names;
513 vector<UniversalSigVec *> usvs;
514
515 int init(MedRepository *_rep, const vector<string> &_sig_names, const vector<UniversalSigVec *> &_usvs);
516 int read_pid(int pid);
517 int read_pid(int pid, const vector<UniversalSigVec *> &_usvs);
518
519private:
520 vector<int> sids;
521};
522
523//=============================================================================================
524// Inline functions
525//=============================================================================================
526//------------------------------------------------------------
527//inline IndexElem *MedIndex::get_ind_elem(int pid, int sid)
528//{
529// if (pid2idx.find(pid) == pid2idx.end() || sid2idx.find(sid) == sid2idx.end())
530// return NULL;
531// int i_pid = pid2idx[pid];
532// int i_sid = sid2idx[sid];
533// int ie_i = idx_i[i_pid*n_signals + i_sid];
534//
535// if (ie_i < 0)
536// return NULL;
537//
538// return &idx[ie_i];
539//}
540inline IndexElem *MedIndex::get_ind_elem2(int pid, int sid)
541{
542 unsigned int i_pid = pid_idx[pid];
543 unsigned int i_sid = sid_idx[sid];
544
545 //if (i_pid<0 || i_sid<0)
546 if (i_sid >= MAX_ID_NUM || i_pid >= MAX_ID_NUM)
547 return NULL;
548
549 // int ie_i = idx_i[i_pid*n_signals + i_sid];
550 int ie_i = idx_i[i_sid][i_pid];
551
552 if (ie_i < 0)
553 return NULL;
554
555 return &idx[ie_i];
556}
557
558
559inline void *MedIndex::get_ind_elem(int pid, int sid, unsigned int &len)
560{
561 unsigned int i_pid = pid_idx[pid];
562 unsigned int i_sid = sid_idx[sid];
563
564 if (i_sid >= MAX_ID_NUM || i_pid >= MAX_ID_NUM)
565 return NULL;
566
567 unsigned char ie_i_add = idx_i_add[i_sid][i_pid];
568
569 if (ie_i_add == 0) {
570 //fprintf(stderr, "pid %d sid %d i_pid %d i_sid %d ie_i_add is 0 !!!!\n", pid, sid, i_pid, i_sid);
571 return NULL;
572 }
573 //fprintf(stderr, "pid %d sid %d i_pid %d i_sid %d ie_i_add is not 0 !!!!\n", pid, sid, i_pid, i_sid);
574 int i_base = i_pid >> 7;
575
576 int ie_i = idx_i_base[i_sid][i_base] + ie_i_add - 1;
577
578 len = idx_recs[i_sid][ie_i].len;
579
580 unsigned long long d_add = (unsigned long long)idx_recs[i_sid][ie_i].data_ptr_add*(unsigned long long)i_sid_factor[i_sid];
581
582 return (void *)((unsigned long long)idx_recs_base[i_sid].data + d_add);
583}
584
585//-----------------------------------------------------------
586// returns also len - in units of the relevant sid type (!)
587inline void *MedRepository::get(int pid, const string &sig_name, int &len)
588{
589 len = 0;
590 int sid = sigs.sid(sig_name);
591 if (sid < 0)
592 return NULL;
593 return(get(pid, sid, len));
594}
595
596
597//-----------------------------------------------------------
598// returns also len - in units of the relevant sid type (!)
599inline void *MedRepository::get_all_modes(int pid, int sid, int &len)
600{
601 //return ((get_ptr)(pid, sid, len));
602
603 if (rep_mode >= 3)
604 return get3(pid, sid, len);
605
606 void *ie;
607
608 unsigned int blen;
609
610 len = 0;
611 ie = index.get_ind_elem(pid, sid, blen);
612 if (ie == NULL)
613 return NULL;
614
615 len = blen;
616 return (ie);
617}
618
619//-----------------------------------------------------------
620// get for mode 3 using index table
621inline void *MedRepository::get3(int pid, int sid, int &len)
622{
623 unsigned long long pos;
624 index.index_table[sid].get(pid, pos, len);
625
626 if (len == 0)
627 return NULL;
628
629 return ((void *)&index.index_table[sid].work_area[pos]);
630}
631
632
633//======================================================================
634// Universal APIs
635//======================================================================
636inline void *MedRepository::uget(int pid, const string &sig_name, UniversalSigVec &usv)
637{
638 usv.len = 0;
639 int sid = sigs.sid(sig_name);
640 if (sid < 0)
641 return NULL;
642 return(uget(pid, sid, usv));
643}
644
645inline void *MedRepository::uget(int pid, int sid, UniversalSigVec_legacy &usv)
646{
647 usv.init(sigs.Sid2Info[sid]);
648
649 usv.data = get(pid, sid, usv.len);
650 return usv.data;
651
652}
653
654inline void *MedRepository::uget(int pid, int sid, GenericSigVec &gsv)
655{
656 gsv.init(sigs.Sid2Info[sid]);
657
658 gsv.data = (char*)get(pid, sid, gsv.len);
659 return gsv.data;
660}
661
662
663
667namespace medial {
671 namespace signal_hierarchy {
673 string filter_code_hierarchy(const vector<string> &vec, const string &signalHirerchyType);
675 vector<int> parents_code_hierarchy(MedDictionarySections &dict, const string &group,
676 const string &signalHirerchyType, int depth = 1, int max_nodes = 10);
678 vector<int> sons_code_hierarchy(MedDictionarySections &dict, const string &group, const string &signalHirerchyType);
680 void sons_code_hierarchy_recursive(MedDictionarySections &dict,
681 const string &signalName, const string &code, vector<int> &flat_all_sons, int max_depth = 0);
683 string get_readcode_code(MedDictionarySections &dict, int id, const string &signalHirerchyType);
684 }
688 namespace repository {
690 float DateDiff(int refDate, int dateSample);
692 int DateAdd(int refDate, int daysAdd);
694 int get_value(MedRepository &rep, int pid, int sigCode);
696 int get_value(PidRec &rep, int sigCode);
697
698 enum fix_method {
699 none = 0,
700 drop = 1,
701 take_first = 2,
702 take_last = 3,
703 take_mean = 4,
704 take_max = 5,
705 take_min = 6
706 };
708 bool fix_contradictions(UniversalSigVec &s, fix_method method, UniversalSigVec_mem &edited);
709
713 template<class T> int fetch_next_date(vector<T> &patientFile, vector<int> &signalPointers);
716 void set_global_time_unit(const string &repository_path);
717 }
718}
719
720#endif
Logger.h - allowing logs with more control.
An Abstract class that can be serialized and written/read from file.
#define ADD_SERIALIZATION_FUNCS(...)
Definition SerializableObject.h:122
Definition InfraMed.h:87
Definition MedSignals.h:915
Definition InfraMed.h:261
void erase_pid_data(int pid)
Erase pid data.
Definition InMemData.cpp:172
Definition InfraMed.h:77
Definition InfraMed.h:99
Definition InfraMed.h:57
Definition MedDictionary.h:87
Definition InfraMed.h:158
Definition InfraMed.h:303
Definition MedSignals.h:719
Definition MedSparseVec.h:69
Definition MedPidRepository.h:43
Definition MedSignals.h:144
Definition SerializableObject.h:32
Definition MedSignals.h:760
Definition InfraMed.h:509
medial namespace for function
Definition InfraMed.h:667
Definition StdDeque.h:58