-
Notifications
You must be signed in to change notification settings - Fork 0
/
adherence_migration.sql
715 lines (668 loc) · 37.4 KB
/
adherence_migration.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
DELIMITER $$
DROP PROCEDURE IF EXISTS adherenceMigration$$
CREATE PROCEDURE adherenceMigration()
BEGIN
/*Delete all inserted discontinuations data if the script fail*/
SET SQL_SAFE_UPDATES = 0;
SET FOREIGN_KEY_CHECKS=0;
DELETE FROM obs WHERE encounter_id IN
(
SELECT en.encounter_id FROM encounter en, encounter_type ent
WHERE en.encounter_type=ent.encounter_type_id
AND ent.uuid='c45d7299-ad08-4cb5-8e5d-e0ce40532939'
);
SET SQL_SAFE_UPDATES = 1;
SET FOREIGN_KEY_CHECKS=1;
/*Start migration for Évaluation faite par: */
/*Start migration for Médecin */
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163556,c.encounter_id,c.encounter_datetime,c.location_id,162591,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd)=concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.evaluationDoctor=1;
select 1 as adherence;
/*Pharmacien/Dispensateur*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163556,c.encounter_id,c.encounter_datetime,c.location_id,163557,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) =concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.evaluationPharmacien=1;
select 2 as adherence;
/*Infirmière */
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163556,c.encounter_id,c.encounter_datetime,c.location_id,1577,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) =concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.evaluationNurse=1;
select 3 as adherence;
/*Travailleur social/Psychologue */
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163556,c.encounter_id,c.encounter_datetime,c.location_id,163558,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) =concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.evaluationSocialWorker=1;
select 4 as adherence;
/* Agent de santé communautaire/accompagnateur*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163556,c.encounter_id,c.encounter_datetime,c.location_id,1555,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) =concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.evaluationAgent=1;
select 5 as adherence;
/*Autre, préciser:*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,comments,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163556,c.encounter_id,c.encounter_datetime,c.location_id,5622,ac.evaluationOtherText,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) =concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.evaluationOther=1;
select 6 as adherence;
/*End migration for Évaluation faite par: */
/*Start migration for Adhérence:
Durant les 4 derniers jours, combien de doses du médicament le patient a-t-il-manqué?*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_numeric,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163709,c.encounter_id,c.encounter_datetime,c.location_id,
CASE WHEN ac.missedDoses=1 THEN 0
WHEN ac.missedDoses=2 THEN 1
WHEN ac.missedDoses=4 THEN 2
WHEN ac.missedDoses=8 THEN 3
WHEN ac.missedDoses=16 THEN 4
END,1,e.createDate, UUID()
from encounter c, itech.encounter e,itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.missedDoses IN(1,2,4,8,16) ;
select 7 as adherence;
/*End migration for Adhérence:
Durant les 4 derniers jours, combien de doses du médicament le patient a-t-il-manqué?*/
/*Start migration for Quel pourcentage de doses le patient a-t-il pris le mois dernier ? */
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_numeric,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,163710,c.encounter_id,c.encounter_datetime,c.location_id,
CASE WHEN ac.doseProp=1 THEN 0
WHEN ac.doseProp=2 THEN 10
WHEN ac.doseProp=4 THEN 20
WHEN ac.doseProp=8 THEN 30
WHEN ac.doseProp=16 THEN 40
WHEN ac.doseProp=32 THEN 50
WHEN ac.doseProp=64 THEN 60
WHEN ac.doseProp=128 THEN 70
WHEN ac.doseProp=256 THEN 80
WHEN ac.doseProp=512 THEN 90
WHEN ac.doseProp=1024 THEN 100
END,1,e.createDate, UUID()
from encounter c, itech.encounter e,itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.doseProp IN(1,2,4,8,16,32,64,128,256,512,1024) ;
select 8 as adherence;
/*End migration for Quel pourcentage de doses le patient a-t-il pris le mois dernier ?*/
/*Start migration for Raison donnée pour avoir manqué une dose, cocher le ou les cas ci-dessous*/
/*Médicament non-disponible à la clinique*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,1754,1,e.createDate, UUID()
from encounter c, itech.encounter e,itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonNotAvail=1;
select 9 as adherence;
/*A oublié*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,160587,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonForgot=1;
select 10 as adherence;
/*Effets secondaires, préciser ci-dessous*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,1778,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonSideEff=1;
select 11 as adherence;
/*Emprisonné*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,156761,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonPrison=1;
select 12 as adherence;
/*S'est senti trop malade*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,160585,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonTooSick=1;
select 13 as adherence;
/*A terminé tous les médicaments*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,1775,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonFinished=1;
select 14 as adherence;
/*S'est senti bien*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,160586,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonFeelWell=1;
select 15 as adherence;
/*A perdu les pilules*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,160584,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonLost=1;
select 16 as adherence;
/*N'a pas voulu*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,127750,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonDidNotWant=1;
select 18 as adherence;
/*Gêné de prendre des médicaments en présence d'autres personnes*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,160589,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonNotComf=1;
select 19 as adherence;
/*Difficultés à avaler*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,5954,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonNoSwallow=1;
select 20 as adherence;
/*En voyage*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,124153,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonTravel=1;
select 21 as adherence;
/*Manque de nourriture*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,119533,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonNoFood=1;
select 23 as adherence;
/*Autres, préciser :*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_coded,
comments,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,160582,c.encounter_id,c.encounter_datetime,c.location_id,5622,ac.reasonOtherText,1,e.createDate, UUID()
from encounter c, itech.encounter e,itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND ac.reasonOther=1;
select 24 as adherence;
/*Start migration for EFFETS SECONDAIRES*/
/*Create table obs_concept_group for the obs_group_id*/
create table if not exists itech.obs_concept_group (obs_id int,person_id int,concept_id int,encounter_id int);
/*Migration for the concept question of Nausée ou vomissement*/
/*Migration for obsgroup of Nausée ou vomissement*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='72074743-ae89-425e-ba48-718b02585b91'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideNausea=1 OR ac.sideNausea=2 OR ac.sideNausea=4);
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs,openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='72074743-ae89-425e-ba48-718b02585b91'
GROUP BY openmrs.obs.person_id,encounter_id;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,133473,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideNausea=1 OR ac.sideNausea=2 OR ac.sideNausea=4);
select 5 as adherence;
/*=====================================================================*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,162760,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,
CASE WHEN ac.sideNausea=1 THEN 1498
WHEN ac.sideNausea=2 THEN 1499
WHEN ac.sideNausea=4 THEN 1500
END,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideNausea=1 OR ac.sideNausea=2 OR ac.sideNausea=4);
select 26 as adherence;
/*End migration for Nausée ou vomissement*/
/*Start migration for Diarrhée*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='bc514162-eae6-4126-95b4-c3695a410e2d'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideDiarrhea=1 OR ac.sideDiarrhea=2 OR ac.sideDiarrhea=4);
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs,openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='bc514162-eae6-4126-95b4-c3695a410e2d'
GROUP BY openmrs.obs.person_id,encounter_id;
select 27 as adherence;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,142412,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideDiarrhea=1 OR ac.sideDiarrhea=2 OR ac.sideDiarrhea=4);
select 28 as adherence;
/*=====================================================================*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,162760,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,
CASE WHEN ac.sideDiarrhea=1 THEN 1498
WHEN ac.sideDiarrhea=2 THEN 1499
WHEN ac.sideDiarrhea=4 THEN 1500
END,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideDiarrhea=1 OR ac.sideDiarrhea=2 OR ac.sideDiarrhea=4);
select 29 as adherence;
/*End migration for Diarrhée*/
/*Start migration for Eruption cutanée*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='40a0c708-a7bb-40ee-941b-c7bdefbb73bd'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideRash=1 OR ac.sideRash=2 OR ac.sideRash=4);
select 30 as adherence;
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs,openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='40a0c708-a7bb-40ee-941b-c7bdefbb73bd'
GROUP BY openmrs.obs.person_id,encounter_id;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,512,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideRash=1 OR ac.sideRash=2 OR ac.sideRash=4);
select 31 as adherence;
/*=====================================================================*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,162760,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,
CASE WHEN ac.sideRash=1 THEN 1498
WHEN ac.sideRash=2 THEN 1499
WHEN ac.sideRash=4 THEN 1500
END,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideRash=1 OR ac.sideRash=2 OR ac.sideRash=4);
select 32 as adherence;
/*End migration for Eruption cutanée*/
/*Start migration for Maux de tête*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='369d0166-14dd-4f43-baa4-10ce377c5afb'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideHeadache=1 OR ac.sideHeadache=2 OR ac.sideHeadache=4);
select 33 as adherence;
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs,openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='369d0166-14dd-4f43-baa4-10ce377c5afb'
GROUP BY openmrs.obs.person_id,encounter_id;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,139084,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideHeadache=1 OR ac.sideHeadache=2 OR ac.sideHeadache=4);
select 34 as adherence;
/*=====================================================================*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,162760,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,
CASE WHEN ac.sideHeadache=1 THEN 1498
WHEN ac.sideHeadache=2 THEN 1499
WHEN ac.sideHeadache=4 THEN 1500
END,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideHeadache=1 OR ac.sideHeadache=2 OR ac.sideHeadache=4);
select 35 as adherence;
/*End migration for Maux de tête*/
/*Start migration for Douleur abdominale*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='cec53311-713b-4d80-8387-639be8d90f16'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideAbPain=1 OR ac.sideAbPain=2 OR ac.sideAbPain=4);
select 36 as adherence;
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs,openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='cec53311-713b-4d80-8387-639be8d90f16'
GROUP BY openmrs.obs.person_id,encounter_id;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,151,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideAbPain=1 OR ac.sideAbPain=2 OR ac.sideAbPain=4);
select 37 as adherence;
/*=====================================================================*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,162760,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,
CASE WHEN ac.sideAbPain=1 THEN 1498
WHEN ac.sideAbPain=2 THEN 1499
WHEN ac.sideAbPain=4 THEN 1500
END,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideAbPain=1 OR ac.sideAbPain=2 OR ac.sideAbPain=4);
select 38 as adherence;
/*End migration for Douleur abdominale*/
/*Start migration for Faiblesse*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='654d4c9e-f171-485c-9aee-5c906406342c'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideWeak=1 OR ac.sideWeak=2 OR ac.sideWeak=4);
select 39 as adherence;
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs,openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='654d4c9e-f171-485c-9aee-5c906406342c'
GROUP BY openmrs.obs.person_id,encounter_id;
select 40 as adherence;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,5226,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideWeak=1 OR ac.sideWeak=2 OR ac.sideWeak=4);
select 41 as adherence;
/*=====================================================================*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,162760,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,
CASE WHEN ac.sideWeak=1 THEN 1498
WHEN ac.sideWeak=2 THEN 1499
WHEN ac.sideWeak=4 THEN 1500
END,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideWeak=1 OR ac.sideWeak=2 OR ac.sideWeak=4);
select 42 as adherence;
/*End migration for Faiblesse*/
/*Start migration for Paresthésie/fourmillement*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='654d4c9e-f171-485c-9aee-5c906406342c'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideNumb=1 OR ac.sideNumb=2 OR ac.sideNumb=4);
select 43 as adherence;
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs,openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='654d4c9e-f171-485c-9aee-5c906406342c'
GROUP BY openmrs.obs.person_id,encounter_id;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,6004,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideNumb=1 OR ac.sideNumb=2 OR ac.sideNumb=4);
select 44 as adherence;
/*=====================================================================*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,162760,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,
CASE WHEN ac.sideNumb=1 THEN 1498
WHEN ac.sideNumb=2 THEN 1499
WHEN ac.sideNumb=4 THEN 1500
END,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideNumb=1 OR ac.sideNumb=2 OR ac.sideNumb=4);
select 45 as adherence;
/*End migration for Paresthésie/fourmillement*/
/*Start migration for Autres, préciser :*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,(select concept_id from concept where uuid='0c362159-faae-4212-8866-5c59afc0c99b'),c.encounter_id,c.encounter_datetime,c.location_id,1,c.date_created,UUID()
FROM encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.patientID = ac.patientID
AND e.siteCode = ac.siteCode
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideOtherText<>"" AND ac.sideOtherText is not null);
/*Finding the last obs_group_id inserted */
TRUNCATE TABLE itech.obs_concept_group;
INSERT INTO itech.obs_concept_group (obs_id,person_id,concept_id,encounter_id)
SELECT MAX(openmrs.obs.obs_id) as obs_id,openmrs.obs.person_id,openmrs.obs.concept_id,openmrs.obs.encounter_id
FROM openmrs.obs, openmrs.concept c
WHERE openmrs.obs.concept_id=c.concept_id and c.uuid='0c362159-faae-4212-8866-5c59afc0c99b'
GROUP BY openmrs.obs.person_id,encounter_id;
/*Answer*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,obs_group_id,value_coded,
comments,creator,date_created,uuid)
SELECT DISTINCT c.patient_id,159935,c.encounter_id,c.encounter_datetime,c.location_id,cg.obs_id,5622,ac.sideOtherText,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac, itech.obs_concept_group cg
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND c.encounter_id=cg.encounter_id
AND c.patient_id=cg.person_id
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND(ac.sideOtherText<>"" AND ac.sideOtherText is not null);
/*End migration for Autres, préciser :*/
select 46 as adherence;
/*Stop migration for EFFETS SECONDAIRES*/
/*Start migration for REMARQUES/PLAN D'ACTION*/
INSERT INTO obs(person_id,concept_id,encounter_id,obs_datetime,location_id,value_text,
creator,date_created,uuid)
SELECT DISTINCT c.patient_id,161011,c.encounter_id,c.encounter_datetime,c.location_id,ac.adherenceRemark,1,e.createDate, UUID()
from encounter c, itech.encounter e, itech.adherenceCounseling ac
WHERE c.uuid = e.encGuid
AND e.siteCode = ac.siteCode
AND e.patientID = ac.patientID
AND concat(e.visitDateYy,"-",e.visitDateMm,"-",e.visitDateDd) = concat(ac.visitDateYy,"-",ac.visitDateMm,"-",ac.visitDateDd)
AND (ac.adherenceRemark<>"" AND ac.adherenceRemark is not null);
select 47 as adherence;
/*End migration for REMARQUES/PLAN D'ACTION*/
/*End migration for Raison donnée pour avoir manqué une dose, cocher le ou les cas ci-dessous*/
END$$
DELIMITER ;