zKnit()
# medhx_20090405 (this one has results for the 3 listed participants below, just under different histIds).
# medhx20100113 (this one does not have results for the participants listed below).

chkFor = c(8113068701,8151924202,8155040901,8161465702,8161742501,8163597901,8171299501,8172084901,8172271601,8172431601,8173159101,8173159102,8173360601)

getMain = function(db.tbl) {

    main = HNDdbGet(db.tbl)

    main$HNDid = HNDconcatID(zVsel(main, handlsIdPrefix:handlsIdSuffix))

    main
    }


hx15.main = getMain('medhx.hist_main')                  # current wave 1 medhx database
hx10.main = getMain('medhx20100113.hist_main')              # restored mechx from 2010-01-13
hx09.main = getMain('medhx_20090405.hist_main')             # restored medhx from 2009-04-05

#
# ***Find histIDs for HNDids in hist_main...
#

(h15ID = hx15.main[hx15.main$HNDid %in% chkFor,zQ(histId,HNDid)])
     histId      HNDid
2219 100815 8161465702
2221 100817 8173159101
2225 100821 8173159102
2304 100900 8161742501
2310 100906 8173360601
2318 100914 8163597901
2435 101031 8172084901
2498 101094 8171299501
2593 101189 8151924202
2622 101218 8172431601
2624 101220 8172271601
2691 101287 8113068701
2692 101288 8155040901
(h10ID = hx10.main[hx10.main$HNDid %in% chkFor,zQ(histId,HNDid)])
     histId      HNDid
2219 100815 8161465702
2221 100817 8173159101
2225 100821 8173159102
2304 100900 8161742501
2310 100906 8173360601
2318 100914 8163597901
2435 101031 8172084901
2498 101094 8171299501
2593 101189 8151924202
2622 101218 8172431601
2624 101220 8172271601
2691 101287 8113068701
2692 101288 8155040901
(h09ID = hx09.main[hx09.main$HNDid %in% chkFor,zQ(histId,HNDid)])
     histId      HNDid
2235   2397 8172084901
2265   2427 8161465702
2269   2431 8173159102
2270   2432 8173159101
2350   2512 8161742501
2357   2519 8173360601
2362   2524 8163597901
2535   2697 8171299501
2639   2801 8151924202
2666   2828 8172431601
2672   2834 8172271601
2736   2898 8155040901
2737   2899 8113068701
#
# ***Are histIDs in hist_surg???
#

hist15_surg = HNDdbGet('medhx.hist_surg')
hist10_surg = HNDdbGet('medhx20100113.hist_surg')
hist09_surg = HNDdbGet('medhx_20090405.hist_surg')

(h15surg = hist15_surg[hist15_surg$histId %in% h15ID$histID,])
[1] id          histId      surgeryId   isSurgery   surgeryType WhnStamp    WhnXfer     server     
<0 rows> (or 0-length row.names)
(h10surg = hist15_surg[hist10_surg$histId %in% h10ID$histID,])
[1] id          histId      surgeryId   isSurgery   surgeryType WhnStamp    WhnXfer     server     
<0 rows> (or 0-length row.names)
(h09surg = hist15_surg[hist09_surg$histId %in% h09ID$histID,])
[1] id          histId      surgeryId   isSurgery   surgeryType WhnStamp    WhnXfer     server     
<0 rows> (or 0-length row.names)
#
# ***Check for changes in histID-HNDid matches...
#

hist.10.15 = merge(h10ID, h15ID, 'histId', all=T)
hist.09.15 = merge(h09ID, h15ID, 'histId', all=T)
hndI.09.15 = merge(h09ID, h15ID, 'HNDid',  all=T)

(hist.10.15$diffHNDid = with(hist.10.15, HNDid.x-HNDid.y))      # No changes between 2010 & 2015
 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0
(hist.09.15$diffHNDid = with(hist.09.15, HNDid.x-HNDid.y))      # No correspondence between 2009 & 2015
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
zQuick(hist.10.15)
[1] 13  4
     histId            HNDid.x              HNDid.y             diffHNDid
 Min.   :100815.0   Min.   :8113068701   Min.   :8113068701   Min.   :0  
 1st Qu.:100900.0   1st Qu.:8161465702   1st Qu.:8161465702   1st Qu.:0  
 Median :101031.0   Median :8171299501   Median :8171299501   Median :0  
 Mean   :101038.5   Mean   :8162662024   Mean   :8162662024   Mean   :0  
 3rd Qu.:101218.0   3rd Qu.:8172431601   3rd Qu.:8172431601   3rd Qu.:0  
 Max.   :101288.0   Max.   :8173360601   Max.   :8173360601   Max.   :0  
zQuick(hist.09.15)
[1] 26  4
     histId             HNDid.x              HNDid.y             diffHNDid  
 Min.   :  2397.00   Min.   :8113068701   Min.   :8113068701   Min.   : NA  
 1st Qu.:  2567.25   1st Qu.:8161465702   1st Qu.:8161465702   1st Qu.: NA  
 Median : 51857.00   Median :8171299501   Median :8171299501   Median : NA  
 Mean   : 51834.58   Mean   :8162662024   Mean   :8162662024   Mean   :NaN  
 3rd Qu.:101001.75   3rd Qu.:8172431601   3rd Qu.:8172431601   3rd Qu.: NA  
 Max.   :101288.00   Max.   :8173360601   Max.   :8173360601   Max.   : NA  
                     NA's   :13           NA's   :13           NA's   :26   
(hndI.09.15$diffHisID = with(hndI.09.15, histId.x-histId.y))
 [1] -98388 -98388 -98390 -98388 -98388 -98390 -98397 -98634 -98386 -98390 -98385 -98390 -98387
zQuick(hndI.09.15)
[1] 13  4
     HNDid               histId.x           histId.y          diffHisID        
 Min.   :8113068701   Min.   :2397.000   Min.   :100815.0   Min.   :-98634.00  
 1st Qu.:8161465702   1st Qu.:2432.000   1st Qu.:100900.0   1st Qu.:-98390.00  
 Median :8171299501   Median :2524.000   Median :101031.0   Median :-98388.00  
 Mean   :8162662024   Mean   :2630.692   Mean   :101038.5   Mean   :-98407.77  
 3rd Qu.:8172431601   3rd Qu.:2828.000   3rd Qu.:101218.0   3rd Qu.:-98388.00  
 Max.   :8173360601   Max.   :2899.000   Max.   :101288.0   Max.   :-98385.00  
hndI.09.15
        HNDid histId.x histId.y diffHisID
1  8113068701     2899   101287    -98388
2  8151924202     2801   101189    -98388
3  8155040901     2898   101288    -98390
4  8161465702     2427   100815    -98388
5  8161742501     2512   100900    -98388
6  8163597901     2524   100914    -98390
7  8171299501     2697   101094    -98397
8  8172084901     2397   101031    -98634
9  8172271601     2834   101220    -98386
10 8172431601     2828   101218    -98390
11 8173159101     2432   100817    -98385
12 8173159102     2431   100821    -98390
13 8173360601     2519   100906    -98387

It looks like something happened in between 2009 & 2010. It doesn't help us find the IDs we're looking for, but this suggests that something wonky may have happening syncing the database between home base and the MRVs.

What's odd is that the HNDids aren't in 2010 but they were in 2009. I suspect that the surgery table in 2009 didn't sync to home base between 2009 & 2010.