예제 #1
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        self.clinicalItemCategoryIdStrList = list()
        headers = ["clinical_item_category_id", "source_table"]
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
                RowItemModel( [-7, "Admit Dx"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = [
            "clinical_item_id", "clinical_item_category_id", "analysis_status",
            "name"
        ]
        dataModels = \
            [
                RowItemModel( [-1, -1, 1, "CBC"], headers ),
                RowItemModel( [-2, -1, 1, "BMP"], headers ),
                RowItemModel( [-3, -1, 1, "Hepatic Panel"], headers ),
                RowItemModel( [-4, -1, 1, "Cardiac Enzymes"], headers ),
                RowItemModel( [-5, -2, 1, "CXR"], headers ),
                RowItemModel( [-6, -2, 1, "RUQ Ultrasound"], headers ),
                RowItemModel( [-7, -2, 1, "CT Abdomen/Pelvis"], headers ),
                RowItemModel( [-8, -2, 1, "CT PE Thorax"], headers ),
                RowItemModel( [-9, -3, 1, "Acetaminophen"], headers ),
                RowItemModel( [-10, -3, 1, "Carvedilol"], headers ),
                RowItemModel( [-11, -3, 1, "Enoxaparin"], headers ),
                RowItemModel( [-12, -3, 1, "Warfarin"], headers ),
                RowItemModel( [-13, -3, 1, "Ceftriaxone"], headers ),
                RowItemModel( [-14, -4, 1, "Admit"], headers ),
                RowItemModel( [-15, -4, 1, "Discharge"], headers ),
                RowItemModel( [-16, -4, 1, "Readmit"], headers ),

                RowItemModel( [-22, -5, 1, "Diagnosis 2"], headers ),
                RowItemModel( [-23, -5, 1, "Diagnosis 3"], headers ),
                RowItemModel( [-24, -5, 1, "Diagnosis 4"], headers ),

                RowItemModel( [-30, -6, 1, "Troponin (High)"], headers ),
                RowItemModel( [-31, -6, 1, "BNP (High)"], headers ),
                RowItemModel( [-32, -6, 1, "Creatinine (High)"], headers ),
                RowItemModel( [-33, -6, 1, "ESR (High)"], headers ),

                RowItemModel( [-21, -7, 0, "Diagnosis 1"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)

        headers = [
            "patient_item_id", "patient_id", "clinical_item_id", "item_date",
            "analyze_date"
        ]
        dataModels = \
            [
                RowItemModel( [-52, -11111, -23, datetime(1999, 9, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-51, -11111, -21, datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-1,  -11111, -4,  datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-2,  -11111, -10, datetime(2000, 1, 1, 1), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -11111, -8,  datetime(2000, 1, 1, 2), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-5,  -11111, -12, datetime(2000, 2, 1, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-60, -11111, -32, datetime(2000, 1, 1, 4), datetime(2010, 1, 1, 0)], headers ),  # Within query time
                RowItemModel( [-61, -11111, -30, datetime(2000, 1, 4, 0), datetime(2010, 1, 1, 0)], headers ),  # Within 1 week
                RowItemModel( [-62, -11111, -31, datetime(2000, 1,10, 0), datetime(2010, 1, 1, 0)], headers ),  # Past 1 week

                RowItemModel( [-55, -22222, -21, datetime(2000, 1, 8, 0), datetime(2010, 1, 1, 0)], headers ),  # Admit Dx
                RowItemModel( [-12, -22222, -6,  datetime(2000, 1, 8, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-13, -22222, -14, datetime(2000, 1, 8, 1), datetime(2010, 1, 1, 0)], headers ),  # Admit
                RowItemModel( [-14, -22222, -7,  datetime(2000, 1, 8, 2), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-15, -22222, -8,  datetime(2000, 1, 8, 3), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-16, -22222, -15, datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),   # Discharge
                RowItemModel( [-56, -22222, -21, datetime(2000, 1,13, 0), datetime(2010, 1, 1, 0)], headers ),  # Admit Dx
                RowItemModel( [-17, -22222, -9,  datetime(2000, 1,13, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-19, -22222, -14, datetime(2000, 1,13, 1), datetime(2010, 1, 1, 0)], headers ),   # Admit (Readmit)
                RowItemModel( [-20, -22222, -10, datetime(2000, 1,13, 2), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-21, -22222, -11, datetime(2000, 1,13, 3), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-22, -22222, -15, datetime(2000, 1,18, 0), datetime(2010, 1, 1, 0)], headers ),   # Discharge
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("patient_item", dataModel)

        headers = \
            [   "clinical_item_id","subsequent_item_id",
                "count_0","count_3600","count_86400","count_604800","count_any",
                "time_diff_sum", "time_diff_sum_squares",
            ]
        dataModels = \
            [
                RowItemModel( [ -1, -1,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -2, -2,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -3, -3,   95, 95, 97, 97, 97,  0.0, 0.0], headers ),
                RowItemModel( [ -4, -4,   40, 40, 40, 40, 40,  0.0, 0.0], headers ),
                RowItemModel( [ -5, -5,   40, 40, 50, 50, 50,  0.0, 0.0], headers ),
                RowItemModel( [ -6, -6,   70, 70, 70, 70, 70,  0.0, 0.0], headers ),
                RowItemModel( [ -7, -7,   70, 70, 70, 70, 70,  0.0, 0.0], headers ),
                RowItemModel( [ -8, -8,   35, 35, 35, 50, 80,  0.0, 0.0], headers ),
                RowItemModel( [-10,-10,   45, 45, 55, 60, 90,  0.0, 0.0], headers ),
                RowItemModel( [-12,-12,   75, 75, 75, 80, 90,  0.0, 0.0], headers ),

                RowItemModel( [-14,-14,    100,  100,  100,  100,  100,  0.0, 0.0], headers ),
                RowItemModel( [-15,-15,    100,  100,  100,  100,  100,  0.0, 0.0], headers ),
                RowItemModel( [-16,-16,    30,  30,  30,  30,  30,  0.0, 0.0], headers ),

                RowItemModel( [-30,-30,    3,  3,  3,  3,  3,  0.0, 0.0], headers ),
                RowItemModel( [-31,-31,    4,  4,  4,  4,  4,  0.0, 0.0], headers ),
                RowItemModel( [-32,-32,    4,  4,  4,  4,  4,  0.0, 0.0], headers ),
                RowItemModel( [-33,-33,    5,  5,  5,  5,  5,  0.0, 0.0], headers ),


                RowItemModel( [ -2, -4,    0,  2,  3,  3,  3,  200.0, 50000.0], headers ),
                RowItemModel( [ -2, -6,    2,  2,  5,  5,  5,  300.0, 11990.0], headers ),
                RowItemModel( [ -3, -1,   20, 23, 23, 23, 23,  400.0, 344990.0], headers ),
                RowItemModel( [ -4, -5,    3,  3, 13, 43, 43,  340.0, 343110.0], headers ),
                RowItemModel( [ -4, -6,   23, 33, 33, 33, 63,  420.0, 245220.0], headers ),
                RowItemModel( [ -4, -7,   27, 33, 33, 33, 63,   40.0, 5420.0], headers ),
                RowItemModel( [ -4,-10,   25, 35, 40, 45, 63,   47.0, 5420.0], headers ),
                RowItemModel( [ -5, -4,    0,  0, 20, 20, 20,  540.0, 54250.0], headers ),

                RowItemModel( [ -6,-16,   10, 10, 10, 10, 10,  0.0, 0.0], headers ),
                RowItemModel( [ -8,-16,   5, 5, 5, 5, 5,  0.0, 0.0], headers ),
                RowItemModel( [-10,-16,   8, 8, 8, 8, 8,  0.0, 0.0], headers ),

                RowItemModel( [-10,-30,   10, 10, 10, 10, 10,  0.0, 0.0], headers ),
                RowItemModel( [-10,-31,   10, 10, 10, 10, 10,  0.0, 0.0], headers ),
                RowItemModel( [-12,-30,   20, 20, 20, 20, 20,  0.0, 0.0], headers ),
                RowItemModel( [-12,-31,   20, 20, 20, 20, 20,  0.0, 0.0], headers ),
                RowItemModel( [-10,-32,   10, 10, 10, 10, 10,  0.0, 0.0], headers ),
                RowItemModel( [-10,-33,   10, 10, 10, 10, 10,  0.0, 0.0], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_association",
                                              dataModel)

        # Indicate that cache data needs to be updated
        self.dataManager = DataManager()
        self.dataManager.clearCacheData("analyzedPatientCount")
        self.dataManager.clearCacheData("clinicalItemCountsUpdated")

        # Instance to test on
        self.analyzer = OutcomePredictionAnalysis()
        self.preparer = PreparePatientItems()
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self);
        
        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader; 
        ClinicalItemDataLoader.build_clinical_item_psql_schemata();
        
        self.clinicalItemCategoryIdStrList = list();
        headers = ["clinical_item_category_id","default_recommend","source_table"];
        dataModels = \
            [   
                RowItemModel( [-1, 1, "Labs"], headers ),
                RowItemModel( [-2, 1, "Imaging"], headers ),
                RowItemModel( [-3, 1, "Meds"], headers ),
                RowItemModel( [-4, 0, "Nursing"], headers ),    # Disable default recommend to allow for checks
                RowItemModel( [-5, 0, "Problems"], headers ),
                RowItemModel( [-6, 1, "Lab Results"], headers ),
                RowItemModel( [-7, 1, "Admit Dx"], headers ),
                RowItemModel( [-8, 0, "Demographics"], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("clinical_item_category", dataModel );
            self.clinicalItemCategoryIdStrList.append( str(dataItemId) );

        headers = ["clinical_item_id","clinical_item_category_id","default_recommend","item_count","name"];
        dataModels = \
            [   
                RowItemModel( [-1, -1, 1, 30, "CBC"], headers ),
                RowItemModel( [-2, -1, 1, 30, "BMP"], headers ),
                RowItemModel( [-3, -1, 1, 95, "Hepatic Panel"], headers ),
                RowItemModel( [-4, -1, 1, 40, "Cardiac Enzymes"], headers ),
                RowItemModel( [-5, -2, 1, 40, "CXR"], headers ),
                RowItemModel( [-6, -2, 1, 70, "RUQ Ultrasound"], headers ),
                RowItemModel( [-7, -2, 1, 70, "CT Abdomen/Pelvis"], headers ),
                RowItemModel( [-8, -2, 1, 35, "CT PE Thorax"], headers ),   
                RowItemModel( [-9, -3,  1, 0, "Acetaminophen"], headers ),
                RowItemModel( [-10, -3, 1, 45, "Carvedilol"], headers ),
                RowItemModel( [-11, -3, 1, 50, "Enoxaparin"], headers ),
                RowItemModel( [-12, -3, 1, 75, "Warfarin"], headers ),
                RowItemModel( [-13, -3, 0,  0, "Ceftriaxone"], headers ),   # Disable default recommend to allow for checks
                RowItemModel( [-14, -4, 1,  0, "Foley Catheter"], headers ),
                RowItemModel( [-15, -4, 1,  0, "Strict I&O"], headers ),
                RowItemModel( [-16, -4, 1,  0, "Fall Precautions"], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel );

        headers = ["patient_item_id","patient_id","clinical_item_id","item_date","analyze_date"];
        dataModels = \
            [   
                RowItemModel( [-1,  -11111, -4,  datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-2,  -11111, -10, datetime(2000, 1, 1, 1), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -11111, -8,  datetime(2000, 1, 1, 2), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-5,  -11111, -12, datetime(2000, 2, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-6,  -11111, -6,  datetime(2000, 2, 1, 1), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-10, -22222, -7,  datetime(2000, 1, 5, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-12, -22222, -6,  datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-13, -22222, -11, datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-14, -33333, -6,  datetime(2000, 2, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-15, -33333, -2,  datetime(2000, 2,11, 0), datetime(2010, 1, 1, 0)], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("patient_item", dataModel );

        headers = \
            [   "clinical_item_id","subsequent_item_id", 
                "count_0","count_3600","count_86400","count_604800","count_any",
                "time_diff_sum", "time_diff_sum_squares",
            ];
        dataModels = \
            [   
                RowItemModel( [ -1, -1,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -2, -2,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -3, -3,   95, 95, 97, 97, 97,  0.0, 0.0], headers ),
                RowItemModel( [ -4, -4,   40, 40, 40, 40, 40,  0.0, 0.0], headers ),
                RowItemModel( [ -5, -5,   40, 40, 50, 50, 50,  0.0, 0.0], headers ),
                RowItemModel( [ -6, -6,   70, 70, 70, 70, 70,  0.0, 0.0], headers ),
                RowItemModel( [ -7, -7,   70, 70, 70, 70, 70,  0.0, 0.0], headers ),
                RowItemModel( [ -8, -8,   35, 35, 35, 50, 80,  0.0, 0.0], headers ),
                RowItemModel( [-10,-10,   45, 45, 55, 60, 90,  0.0, 0.0], headers ),
                RowItemModel( [-11,-11,   50, 50, 50, 80, 90,  0.0, 0.0], headers ),
                RowItemModel( [-12,-12,   75, 75, 75, 80, 90,  0.0, 0.0], headers ),

                RowItemModel( [ -2, -4,    0,  2,  3,  3,  3,  200.0, 50000.0], headers ),
                RowItemModel( [ -2, -6,    2,  2,  5,  5,  5,  300.0, 11990.0], headers ),
                RowItemModel( [ -3, -1,   20, 23, 23, 23, 23,  400.0, 344990.0], headers ),
                RowItemModel( [ -4, -5,    3,  3, 13, 43, 43,  340.0, 343110.0], headers ),
                RowItemModel( [ -4, -6,   23, 33, 33, 33, 63,  420.0, 245220.0], headers ),
                RowItemModel( [ -4, -7,   27, 33, 33, 33, 63,   40.0, 5420.0], headers ),
                RowItemModel( [ -4,-10,   25, 35, 40, 45, 63,   47.0, 5420.0], headers ),
                RowItemModel( [ -5, -4,    0,  0, 20, 20, 20,  540.0, 54250.0], headers ),
                RowItemModel( [ -8,-12,    15,15, 15, 15, 15,   25.0,  520.0], headers ),
                RowItemModel( [ -10,-11,   12,12, 16, 16, 20,   20.0,  220.0], headers ),
                RowItemModel( [ -10,-12,   10,10, 10, 10, 10,   20.0,  120.0], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("clinical_item_association", dataModel );

        dataTextStr = \
"""item_collection_id;external_id;name;section;subgroup
-1;-1;Test Order Set - 1;Meds;TreatmentMeds
-2;-1;Test Order Set - 1;Meds;SymptomsMeds
-3;-1;Test Order Set - 1;Labs;GeneralLabs
-4;-2;Test Order Set - 2;Labs;GeneralLabs
-5;-2;Test Order Set - 2;Imaging;Xrays
-6;-2;Test Order Set - 2;Imaging;AdvancedImaging
-7;-3;Test Order Set - 3;Imaging;GeneralImaging
-8;-3;Test Order Set - 3;Nursing;GeneralNursing
-9;-3;Test Order Set - 3;Meds;RandomMeds
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "item_collection", delim=";");

        dataTextStr = \
"""item_collection_item_id;item_collection_id;clinical_item_id;collection_type_id
-1;-1;-11;4
-2;-1;-12;4
-3;-1;-13;4
-4;-2;-9;4
-5;-2;-10;4
-6;-3;-1;4
-7;-3;-2;4
-8;-3;-3;4
-100;-3;-4;4
-9;-4;-1;4
-10;-4;-2;4
-11;-4;-3;4
-101;-4;-11;4
-12;-5;-5;4
-74;-6;-6;4
-77;-6;-7;4
-13;-6;-8;4
-14;-7;-5;4
-15;-7;-6;4
-16;-7;-7;4
-17;-7;-8;4
-18;-8;-14;4
-19;-8;-15;4
-20;-9;-11;4
-21;-9;-12;4
-22;-9;-13;4
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "item_collection_item", delim=";");

        # Instance to test on
        self.analyzer = RecommendationClassificationAnalysis();
        self.preparer = PreparePatientItems();
예제 #3
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        self.clinicalItemCategoryIdStrList = list()
        headers = ["clinical_item_category_id", "source_table"]
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = [
            "clinical_item_id", "clinical_item_category_id", "name",
            "analysis_status"
        ]
        dataModels = \
            [
                RowItemModel( [1, -1, "CBC",1], headers ),
                RowItemModel( [2, -1, "BMP",0], headers ), # Clear analysis status, so this will be ignored unless changed
                RowItemModel( [3, -1, "Hepatic Panel",1], headers ),
                RowItemModel( [4, -1, "Cardiac Enzymes",1], headers ),
                RowItemModel( [5, -2, "CXR",1], headers ),
                RowItemModel( [6, -2, "RUQ Ultrasound",1], headers ),
                RowItemModel( [7, -2, "CT Abdomen/Pelvis",1], headers ),
                RowItemModel( [8, -2, "CT PE Thorax",1], headers ),
                RowItemModel( [9, -3, "Acetaminophen",1], headers ),
                RowItemModel( [10, -3, "Carvedilol",1], headers ),
                RowItemModel( [11, -3, "Enoxaparin",1], headers ),
                RowItemModel( [12, -3, "Warfarin",1], headers ),
                RowItemModel( [13, -3, "Ceftriaxone",1], headers ),
                RowItemModel( [14, -4, "Foley Catheter",1], headers ),
                RowItemModel( [15, -4, "Strict I&O",1], headers ),
                RowItemModel( [16, -4, "Fall Precautions",1], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)

        # Input file contents in Bag-of-Words formats
        # Specifically avoid the use of items 6 or 7 in the training data
        self.inputBOWFileStr = \
"""[[1,1],[2,2],[3,1],[4,4],[5,10],[8,5]]
[[3,4],[4,4],[9,3],[10,2],[12,6],[13,3],[15,5],[16,8]]
[[1,1],[2,2],[3,1],[4,4],[5,10],[8,5],[9,1],[10,2],[11,1],[12,4],[13,10],[14,1],[15,3],[16,5]]
[[1,4],[2,9],[9,1],[10,2],[11,7],[12,4],[13,2],[16,6]]
[[4,3],[5,31],[8,5],[12,6],[13,8],[16,5]]
"""
        self.instance = TopicModel()
예제 #4
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        log.info("Populate the database with test data")

        self.clinicalItemCategoryIdStrList = list()
        headers = ["clinical_item_category_id", "source_table"]
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = [
            "clinical_item_id", "clinical_item_category_id", "name",
            "analysis_status"
        ]
        dataModels = \
            [
                RowItemModel( [-1, -1, "CBC",1], headers ),
                RowItemModel( [-2, -1, "BMP",0], headers ), # Clear analysis status, so this will be ignored unless changed
                RowItemModel( [-3, -1, "Hepatic Panel",1], headers ),
                RowItemModel( [-4, -1, "Cardiac Enzymes",1], headers ),
                RowItemModel( [-5, -2, "CXR",1], headers ),
                RowItemModel( [-6, -2, "RUQ Ultrasound",1], headers ),
                RowItemModel( [-7, -2, "CT Abdomen/Pelvis",1], headers ),
                RowItemModel( [-8, -2, "CT PE Thorax",1], headers ),
                RowItemModel( [-9, -3, "Acetaminophen",1], headers ),
                RowItemModel( [-10, -3, "Carvedilol",1], headers ),
                RowItemModel( [-11, -3, "Enoxaparin",1], headers ),
                RowItemModel( [-12, -3, "Warfarin",1], headers ),
                RowItemModel( [-13, -3, "Ceftriaxone",1], headers ),
                RowItemModel( [-14, -4, "Foley Catheter",1], headers ),
                RowItemModel( [-15, -4, "Strict I&O",1], headers ),
                RowItemModel( [-16, -4, "Fall Precautions",1], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)
        self.clinicalItemQuery = \
            """
            select
                clinical_item_id, name, analysis_status, default_recommend
            from
                clinical_item
            where
                clinical_item_id < 0
            order by
                clinical_item_id  desc
            """

        headers = [
            "patient_item_id", "patient_id", "clinical_item_id", "item_date",
            "analyze_date"
        ]
        dataModels = \
            [
                RowItemModel( [-1,  -11111, -4,  datetime(2000, 1, 1, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-2,  -11111, -10, datetime(2000, 1, 1, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -11111, -8,  datetime(2000, 1, 1, 2), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-4,  -11111, -10, datetime(2000, 1, 2, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-5,  -11111, -12, datetime(2000, 2, 1, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-10, -22222, -7,  datetime(2000, 1, 5, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-12, -22222, -6,  datetime(2000, 1, 9, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-13, -22222, -11, datetime(2000, 1, 9, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-14, -33333, -6,  datetime(2000, 2, 9, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-15, -33333, -2,  datetime(2000, 2,11, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-16, -33333, -11,  datetime(2000, 2,11, 0), datetime(2100, 1, 1, 0)], headers ),
                RowItemModel( [-17, -33333, -11,  datetime(2001, 1, 1, 0), datetime(2100, 1, 1, 0)], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("patient_item", dataModel)
        self.patientItemQuery = \
            """
            select
                patient_item_id, patient_id, clinical_item_id, item_date, analyze_date
            from
                patient_item
            where
                clinical_item_id < 0
            order by
                patient_id desc, item_date, patient_item_id desc
            """


        headers = [ "clinical_item_id","subsequent_item_id",\
                    "count_0","count_3600","count_86400","count_604800","count_any",
                    "time_diff_sum","time_diff_sum_squares",
                    "patient_count_0","patient_count_3600","patient_count_86400","patient_count_604800","patient_count_any",
                    "patient_time_diff_sum","patient_time_diff_sum_squares",
                    "patient_count_0","encounter_count_0",
                  ]
        dataModels = \
            [
                RowItemModel( [-11,-11,   3, 3, 3, 3, 4,  999.0, 9999.0,   2, 2, 2, 2, 2,  999.0, 9999.0, 2,2], headers ),
                RowItemModel( [-11, -7,   0, 0, 0, 0, 0,  0.0, 0.0,   0, 0, 0, 0, 0,  0.0, 0.0, 0,0], headers ),
                RowItemModel( [-11, -6,   1, 1, 1, 1, 1,  0.0, 0.0,   1, 1, 1, 1, 1,  0.0, 0.0, 1,1], headers ),
                RowItemModel( [-11, -2,   1, 1, 1, 1, 1,  0.0, 0.0,   1, 1, 1, 1, 1,  0.0, 0.0, 1,1], headers ),
                RowItemModel( [ -7,-11,   0, 0, 0, 1, 1,  345600.0, 119439360000.0,   0, 0, 0, 1, 1,  345600.0, 119439360000.0, 0,0], headers ),
                RowItemModel( [ -7, -7,   1, 1, 1, 1, 1,  0.0, 0.0,   1, 1, 1, 1, 1,  0.0, 0.0, 1,1], headers ),
                RowItemModel( [ -7, -6,   0, 0, 0, 1, 1,  345600.0, 119439360000.0,   0, 0, 0, 1, 1,  345600.0, 119439360000.0, 0,0], headers ),

                RowItemModel( [ -6,-11,   1, 1, 1, 2, 2, 172800.0, 29859840000.0,   1, 1, 1, 2, 2, 172800.0, 29859840000.0, 1,1], headers ),
                RowItemModel( [ -6, -7,   0, 0, 0, 0, 0,  0.0, 0.0,   0, 0, 0, 0, 0,  0.0, 0.0, 0,0], headers ),
                RowItemModel( [ -6, -6,   2, 2, 2, 2, 2,  0.0, 0.0,   2, 2, 2, 2, 2,  0.0, 0.0, 2,2], headers ),
                RowItemModel( [ -6, -2,   0, 0, 0, 1, 1,  172800.0, 29859840000.0,   0, 0, 0, 1, 1,  172800.0, 29859840000.0, 0,0], headers ),

                RowItemModel( [ -2,-11,   1, 1, 1, 1, 1,  0.0, 0.0,   1, 1, 1, 1, 1,  0.0, 0.0, 1,1], headers ),
                RowItemModel( [ -2, -7,   1, 1, 1, 1, 1,  0.0, 0.0,   1, 1, 1, 1, 1,  0.0, 0.0, 1,1], headers ),
                RowItemModel( [ -2, -6,   0, 0, 0, 0, 0,  0.0, 0.0,   0, 0, 0, 0, 0,  0.0, 0.0, 0,0], headers ),
                RowItemModel( [ -2, -2,   1, 1, 1, 1, 1,  0.0, 0.0,   1, 1, 1, 1, 1,  0.0, 0.0, 1,1], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_association",
                                              dataModel)
        self.clinicalItemAssociationQuery = \
            """
            select
                clinical_item_id, subsequent_item_id,
                count_0,count_3600,count_86400,count_604800,count_any,
                time_diff_sum,time_diff_sum_squares,
                patient_count_0,patient_count_3600,patient_count_86400,patient_count_604800,patient_count_any,
                patient_time_diff_sum, patient_time_diff_sum_squares
            from
                clinical_item_association
            where
                clinical_item_id < 0
            order by
                clinical_item_id, subsequent_item_id
            """

        self.analyzer = DataManager()
        # Instance to test on
        self.analyzer.maxClinicalItemId = 0
예제 #5
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        log.info("Populate the database with test data")

        self.clinicalItemCategoryIdStrList = list()
        headers = ["clinical_item_category_id", "source_table"]
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = ["clinical_item_id", "clinical_item_category_id", "name"]
        dataModels = \
            [
                RowItemModel( [-1, -1, "CBC"], headers ),
                RowItemModel( [-2, -1, "BMP"], headers ),
                RowItemModel( [-3, -1, "Hepatic Panel"], headers ),
                RowItemModel( [-4, -1, "Cardiac Enzymes"], headers ),
                RowItemModel( [-5, -2, "CXR"], headers ),
                RowItemModel( [-6, -2, "RUQ Ultrasound"], headers ),
                RowItemModel( [-7, -2, "CT Abdomen/Pelvis"], headers ),
                RowItemModel( [-8, -2, "CT PE Thorax"], headers ),
                RowItemModel( [-9, -3, "Acetaminophen"], headers ),
                RowItemModel( [-10, -3, "Carvedilol"], headers ),
                RowItemModel( [-11, -3, "Enoxaparin"], headers ),
                RowItemModel( [-12, -3, "Warfarin"], headers ),
                RowItemModel( [-13, -3, "Ceftriaxone"], headers ),
                RowItemModel( [-14, -4, "Foley Catheter"], headers ),
                RowItemModel( [-15, -4, "Strict I&O"], headers ),
                RowItemModel( [-16, -4, "Fall Precautions"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)

        headers = [
            "patient_item_id", "patient_id", "clinical_item_id", "item_date",
            "analyze_date"
        ]
        dataModels = \
            [
                RowItemModel( [-1,  -11111, -4,  datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-2,  -11111, -10, datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -11111, -8,  datetime(2000, 1, 1, 2), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-4,  -11111, -10, datetime(2000, 1, 2, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-5,  -11111, -12, datetime(2000, 2, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-10, -22222, -7,  datetime(2000, 1, 5, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-12, -22222, -6,  datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-13, -22222, -11, datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-14, -33333, -6,  datetime(2000, 2, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-15, -33333, -2,  datetime(2000, 2,11, 0), datetime(2010, 1, 1, 0)], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("patient_item", dataModel)

        headers = \
            [   "clinical_item_id","subsequent_item_id",
                "patient_count_0","patient_count_3600","patient_count_86400","patient_count_604800","patient_count_any",
                "time_diff_sum", "time_diff_sum_squares",
            ]
        dataModels = \
            [
                RowItemModel( [ -1, -1,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -2, -2,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -3, -3,   95, 95, 97, 97, 97,  0.0, 0.0], headers ),
                RowItemModel( [ -4, -4,   40, 40, 40, 40, 40,  0.0, 0.0], headers ),
                RowItemModel( [ -5, -5,   40, 40, 50, 50, 50,  0.0, 0.0], headers ),
                RowItemModel( [ -6, -6,   70, 70, 70, 70, 70,  0.0, 0.0], headers ),


                RowItemModel( [ -2, -3,    0,  0,  0,  0,  0,    0.0,     0.0], headers ),  # Zero count associations, probably shouldn't even be here. If so, ignore them anyway
                RowItemModel( [ -2, -4,    0,  2,  3,  3,  3,  200.0, 50000.0], headers ),
                RowItemModel( [ -2, -6,    2,  2,  5,  5,  5,  300.0, 11990.0], headers ),
                RowItemModel( [ -3, -1,   20, 23, 23, 23, 23,  400.0, 344990.0], headers ),
                RowItemModel( [ -4, -5,    3,  3, 13, 43, 43,  340.0, 343110.0], headers ),
                RowItemModel( [ -4, -6,   23, 33, 33, 33, 63,  420.0, 245220.0], headers ),
                RowItemModel( [ -4, -7,   23, 33, 33, 33, 63,   40.0, 5420.0], headers ),
                RowItemModel( [ -5, -4,    0,  0, 20, 20, 20,  540.0, 54250.0], headers ),

                RowItemModel( [ -6, -2,    7,   7,   7,   7,   7,  1.0, 1.0], headers ),
                RowItemModel( [ -6, -4,   20,  20,  20,  20,  20,  1.0, 1.0], headers ),
            ]
        for dataModel in dataModels:
            # Add non patient_count variations (Adding 5 to values that are >5 and not for the zero time interval)
            for header in headers:
                if header.startswith("patient_count_"):
                    timeStr = header[len("patient_count_"):]
                    dataModel["count_%s" % timeStr] = dataModel[header]
                    # Copy over value

                    if timeStr != "0" and dataModel[header] > 5:
                        dataModel["count_%s" % timeStr] += 5
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_association",
                                              dataModel)

        # Indicate that cache data needs to be updated
        self.dataManager = DataManager()
        self.dataManager.clearCacheData("analyzedPatientCount")
        self.dataManager.clearCacheData("clinicalItemCountsUpdated")

        self.recommender = ItemAssociationRecommender()
예제 #6
0
파일: TestDBUtil.py 프로젝트: xxxx3/CDSS
    def test_findOrInsertItem(self):
        DBUtil.runDBScript(self.SCRIPT_FILE, False)

        searchDict = {}
        insertDict = {}

        searchDict["TestTypes_id"] = +123
        log.debug("Insert a new item using default params")
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes", searchDict)
        self.assertEqual(+123, data)
        self.assertEqual(True, isNew)

        log.debug("Find the existing item")
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes", searchDict)
        self.assertEqual(+123, data)
        self.assertEqual(False, isNew)

        insertDict["TestTypes_id"] = +456
        log.debug("Find existing item, with optional insert data")
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes", searchDict,
                                                insertDict)
        self.assertEqual(+123, data)
        self.assertEqual(False, isNew)

        searchDict["TestTypes_id"] = +789
        insertDict["TestTypes_id"] = +789
        insertDict["MyInteger"] = 123
        log.debug("Insert a new item with actual data")
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes", searchDict,
                                                insertDict)
        self.assertEqual(+789, data)
        self.assertEqual(True, isNew)

        searchDict["TestTypes_id"] = +234
        insertDict["TestTypes_id"] = +234
        log.debug("Retrieve a different column")
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes",
                                                searchDict,
                                                insertDict,
                                                retrieveCol="MyText")
        self.assertEqual(None, data)
        self.assertEqual(True, isNew)

        searchDict["TestTypes_id"] = +345
        insertDict["TestTypes_id"] = +345
        insertDict["MyText"] = "testText"
        log.debug("Insert and retrieve a different column")
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes",
                                                searchDict,
                                                insertDict,
                                                retrieveCol="MyText")
        self.assertEqual("testText", data)
        self.assertEqual(True, isNew)

        insertDict["MyText"] = "newText"
        log.debug(
            "Try inserting a different value under an existing row.  Should NOT work"
        )
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes",
                                                searchDict,
                                                insertDict,
                                                retrieveCol="MyText")
        self.assertEqual("testText", data)
        self.assertEqual(False, isNew)

        log.debug(
            "Try inserting a different value under an existing row, but force the update"
        )
        insertDict["MyText"] = "newText"
        (data, isNew) = DBUtil.findOrInsertItem("TestTypes",
                                                searchDict,
                                                insertDict,
                                                retrieveCol="MyText",
                                                forceUpdate=True)
        self.assertEqual("newText", data)
        self.assertEqual(False, isNew)
예제 #7
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self);
        
        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader; 
        ClinicalItemDataLoader.build_clinical_item_psql_schemata();
        
        self.clinicalItemCategoryIdStrList = list();
        headers = ["clinical_item_category_id","source_table"];
        dataModels = \
            [   
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("clinical_item_category", dataModel );
            self.clinicalItemCategoryIdStrList.append( str(dataItemId) );

        headers = ["clinical_item_id","clinical_item_category_id","name","analysis_status"];
        dataModels = \
            [   
                RowItemModel( [-1, -1, "CBC",1], headers ),
                RowItemModel( [-2, -1, "BMP",0], headers ), # Clear analysis status, so this will be ignored unless changed
                RowItemModel( [-3, -1, "Hepatic Panel",1], headers ),
                RowItemModel( [-4, -1, "Cardiac Enzymes",1], headers ),
                RowItemModel( [-5, -2, "CXR",1], headers ),
                RowItemModel( [-6, -2, "RUQ Ultrasound",1], headers ),
                RowItemModel( [-7, -2, "CT Abdomen/Pelvis",1], headers ),
                RowItemModel( [-8, -2, "CT PE Thorax",1], headers ),
                RowItemModel( [-9, -3, "Acetaminophen",1], headers ),
                RowItemModel( [-10, -3, "Carvedilol",1], headers ),
                RowItemModel( [-11, -3, "Enoxaparin",1], headers ),
                RowItemModel( [-12, -3, "Warfarin",1], headers ),
                RowItemModel( [-13, -3, "Ceftriaxone",1], headers ),
                RowItemModel( [-14, -4, "Admit",1], headers ),  # Look for sequences of these
                RowItemModel( [-15, -4, "Discharge",1], headers ),
                RowItemModel( [-16, -4, "Readmit",1], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel );

        headers = ["patient_item_id","encounter_id","patient_id","clinical_item_id","item_date"];
        dataModels = \
            [   
                RowItemModel( [-2,  -111,   -11111, -10, datetime(2000, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -111,   -11111, -8,  datetime(2000, 1, 1, 2)], headers ),
                RowItemModel( [-1,  -111,   -11111, -14, datetime(2000, 1, 1,10)], headers ),   # Admit
                RowItemModel( [-4,  -111,   -11111, -10, datetime(2000, 1, 2, 0)], headers ),
                RowItemModel( [-5,  -111,   -11111, -12, datetime(2000, 2, 1, 0)], headers ),
                RowItemModel( [-6,  -111,   -11111, -15, datetime(2000, 2, 2, 0)], headers ),   # Discharge
                RowItemModel( [-10, -111,   -11111, -11, datetime(2000, 2, 2, 0)], headers ),
                RowItemModel( [-13, -111,   -11111, -10, datetime(2000, 2, 2,10)], headers ),

                RowItemModel( [-7,  -112,   -11111, -9,  datetime(2000, 3, 1, 0)], headers ),
                RowItemModel( [-8,  -112,   -11111, -14, datetime(2000, 3, 1, 1)], headers ),   # Admit
                RowItemModel( [-9,  -112,   -11111, -8,  datetime(2000, 3, 1, 1)], headers ),
                RowItemModel( [-11, -112,   -11111, -15, datetime(2000, 3, 2, 0)], headers ),   # Discharge
                RowItemModel( [-12, -112,   -11111, -7,  datetime(2000, 3, 2, 0)], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("patient_item", dataModel );

        self.analyzer = TripleAssociationAnalysis();  # Instance to test on
예제 #8
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        self.clinicalItemCategoryIdStrList = list()
        headers = ["clinical_item_category_id", "source_table"]
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = [
            "clinical_item_id", "clinical_item_category_id", "name",
            "analysis_status"
        ]
        dataModels = \
            [
                RowItemModel( [-1, -1, "CBC",1], headers ),
                RowItemModel( [-2, -1, "BMP",0], headers ), # Clear analysis status, so this will be ignored unless changed
                RowItemModel( [-3, -1, "Hepatic Panel",1], headers ),
                RowItemModel( [-4, -1, "Cardiac Enzymes",1], headers ),
                RowItemModel( [-5, -2, "CXR",1], headers ),
                RowItemModel( [-6, -2, "RUQ Ultrasound",1], headers ),
                RowItemModel( [-7, -2, "CT Abdomen/Pelvis",1], headers ),
                RowItemModel( [-8, -2, "CT PE Thorax",1], headers ),
                RowItemModel( [-9, -3, "Acetaminophen",1], headers ),
                RowItemModel( [-10, -3, "Carvedilol",1], headers ),
                RowItemModel( [-11, -3, "Enoxaparin",1], headers ),
                RowItemModel( [-12, -3, "Warfarin",1], headers ),
                RowItemModel( [-13, -3, "Ceftriaxone",1], headers ),
                RowItemModel( [-14, -4, "Foley Catheter",1], headers ),
                RowItemModel( [-15, -4, "Strict I&O",1], headers ),
                RowItemModel( [-16, -4, "Fall Precautions",1], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)


        dataTextStr = \
"""item_collection_id;external_id;name;section;subgroup
-1;-1;Test Order Set - 1;Meds;TreatmentMeds
-2;-1;Test Order Set - 1;Meds;SymptomsMeds
-3;-1;Test Order Set - 1;Labs;GeneralLabs
-4;-2;Test Order Set - 2;Labs;GeneralLabs
-5;-2;Test Order Set - 2;Imaging;Xrays
-6;-2;Test Order Set - 2;Imaging;AdvancedImaging
-7;-3;Test Order Set - 3;Imaging;GeneralImaging
-8;-3;Test Order Set - 3;Nursing;GeneralNursing
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr), "item_collection", delim=";")

        dataTextStr = \
"""item_collection_item_id;item_collection_id;clinical_item_id;collection_type_id
-1;-1;-12;4
-2;-1;-13;4
-3;-2;-11;4
-4;-2;-10;4
-5;-3;-1;4
-6;-3;-2;4
-7;-4;-2;4
-8;-4;-3;4
-9;-5;-5;4
-10;-6;-6;4
-11;-6;-7;4
-12;-6;-8;4
-13;-7;-5;4
-14;-7;-6;4
-15;-8;-14;4
-16;-8;-15;4
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr),
                          "item_collection_item",
                          delim=";")

        # Sample Prepared Validation File
        self.validationFileStr = \
"""patient_id\tqueryItemCountByIdJSON\tverifyItemCountByIdJSON\tbaseItemId\tbaseItemDate\tqueryStartTime\tqueryEndTime\tverifyEndTime\toutcome.7
123\t{"-1": 1, "-2": 1, "-3": 1, "-4": 1, "-5": 1, "-8": 1, "-9": 1, "-10": 1, "-11": 1, "-12": 1, "-13": 1}\t{"-12": 1, "-14": 1, "-15": 1, "-16": 1}\t10\t2012-04-11 00:00:00\t2012-04-11 10:57:00\t2012-04-11 14:57:00\t2012-04-12 10:57:00\t0
456\t{"-2": 1, "-4": 2, "-8": 4, "-10": 1, "-12": 6}\t{"-12": 6, "-14": 7, "-16": 8}\t10\t2013-12-24 00:00:00\t2013-12-24 06:50:00\t2013-12-24 10:50:00\t2013-12-25 06:50:00\t1
789\t{"-1": 1, "-3": 3, "-5": 5, "-9": 9, "-10": 1, "-11": 11}\t{"-13": 13, "-15": 15}\t10\t2011-08-19 00:00:00\t2011-08-19 11:12:00\t2011-08-19 15:12:00\t2011-08-20 11:12:00\t0
"""

        self.analyzer = OrderSetRecommenderClassificationAnalysis()
예제 #9
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        StrideLoader.build_stride_psql_schemata()
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        headers = [
            "stride_preadmit_med_id", "pat_anon_id", "contact_date",
            "medication_id", "description", "thera_class", "pharm_class",
            "pharm_subclass"
        ]
        dataModels = \
            [   # Deliberately design dates in far future to facilitate isolated testing
                RowItemModel([-100, -1000, datetime(2113, 7, 6),  -5680, "NORVASC 5 MG PO TABS", "CARDIAC DRUGS", "CALCIUM CHANNEL BLOCKING AGENTS", "Calcium Channel Blockers - Dihydropyridines"], headers ),
                RowItemModel([-110, -2000, datetime(2110, 3, 8),  -6540, "PRILOSEC 20 MG PO CPDR", "GASTROINTESTINAL", "PROTON-PUMP INHIBITORS", "Gastric Acid Secretion Reducing Agents - Proton Pump Inhibitors (PPIs)"], headers ),
                RowItemModel([-120, -2000, datetime(2110, 3, 8),  -8113, "TRIAMCINOLONE 0.1% CREAM", "SKIN PREPS", "TOPICAL ANTI-INFLAMMATORY STEROIDAL", "Dermatological - Glucocorticoid"], headers ),
                # Multiple or no mappings
                RowItemModel([-130, -3000, datetime(2109, 9,20),-126745, "NORETHINDRN ESTRADIOL", "CONTRACEPTIVES", "CONTRACEPTIVES,ORAL", "Contraceptive Oral - Monophasic"], headers ),
                RowItemModel([-140, -4000, datetime(2110, 5, 4),  -28384, "HYDROCODONE-ACETAMINOPHEN 10-325 MG PO TABS", "ANALGESICS", "ANALGESICS, NARCOTICS", "Analgesic Narcotic Hydrocodone Combinations"], headers ),
                # Excessively complex mapping
                RowItemModel([-150, -5000, datetime(2108, 8, 6), -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", "BIOLOGICALS", "GRAM POSITIVE COCCI VACCINES", "Vaccine Bacterial - Gram Positive Cocci"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("stride_preadmit_med",
                                              dataModel,
                                              retrieveCol="pat_anon_id")

        # Mapping table to simplify dose
        headers = ["medication_id", "name", "rxcui", "active_ingredient"]
        dataModels = \
            [   # Mappings to active ingredients
                RowItemModel( [ -5680, "NORVASC 5 MG PO TABS", -17767, "Amlodipine"], headers ),
                RowItemModel( [ -6540, "PRILOSEC 20 MG PO CPDR", -7646, "Omeprazole"], headers ),
                RowItemModel( [ -8113, "TRIAMCINOLONE ACETONIDE 0.1 % TP CREA", -10759, "Triamcinolone"], headers ),
                # If multiple active ingredients in a combo, unravel to active components
                RowItemModel( [ -28384, "HYDROCODONE-ACETAMINOPHEN 10-325 MG PO TABS", -161, "Acetaminophen"], headers ),
                RowItemModel( [ -28384, "HYDROCODONE-ACETAMINOPHEN 10-325 MG PO TABS", -5489, "Hydrocodone"], headers ),
                # No mapping entries for Norethindrone+Estradiol
                # Excessive mappings for pneumovax
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854930, "pneumococcal capsular polysaccharide type 1 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854932, "pneumococcal capsular polysaccharide type 10A vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854934, "pneumococcal capsular polysaccharide type 11A vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854936, "pneumococcal capsular polysaccharide type 12F vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854938, "pneumococcal capsular polysaccharide type 14 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854940, "pneumococcal capsular polysaccharide type 15B vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854942, "pneumococcal capsular polysaccharide type 17F vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854944, "pneumococcal capsular polysaccharide type 18C vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854946, "pneumococcal capsular polysaccharide type 19A vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854948, "pneumococcal capsular polysaccharide type 19F vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854950, "pneumococcal capsular polysaccharide type 2 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854952, "pneumococcal capsular polysaccharide type 20 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854954, "pneumococcal capsular polysaccharide type 22F vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854956, "pneumococcal capsular polysaccharide type 23F vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854958, "pneumococcal capsular polysaccharide type 3 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854960, "pneumococcal capsular polysaccharide type 33F vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854962, "pneumococcal capsular polysaccharide type 4 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854964, "pneumococcal capsular polysaccharide type 5 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854966, "pneumococcal capsular polysaccharide type 6B vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854968, "pneumococcal capsular polysaccharide type 7F vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854970, "pneumococcal capsular polysaccharide type 8 vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854972, "pneumococcal capsular polysaccharide type 9N vaccine"], headers ),
                RowItemModel( [ -95140, "PNEUMOCOCCAL 23-VALPS VACCINE 25 MCG/0.5 ML INJ INJ", -854974, "pneumococcal capsular polysaccharide type 9V vaccine"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("stride_mapped_meds",
                                                          dataModel,
                                                          retrieveCol="rxcui")

        self.converter = STRIDEPreAdmitMedConversion()
예제 #10
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()
        #self.purgeTestRecords();

        headers = [
            "clinical_item_category_id", "default_recommend", "source_table"
        ]
        dataModels = \
            [
                RowItemModel( [-1, 1, "Labs"], headers ),
                RowItemModel( [-2, 1, "Imaging"], headers ),
                RowItemModel( [-3, 1, "Meds"], headers ),
                RowItemModel( [-4, 1, "Nursing"], headers ),
                RowItemModel( [-5, 1, "Problems"], headers ),
                RowItemModel( [-6, 1, "Lab Results"], headers ),
                RowItemModel( [-7, 0, "No Rec Category"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)

        headers = [
            "clinical_item_id", "clinical_item_category_id", "patient_count",
            "name", "analysis_status"
        ]
        dataModels = \
            [
                RowItemModel( [-1, -1, 100, "CBC",1], headers ),
                RowItemModel( [-2, -1, 200, "BMP",0], headers ), # Clear analysis status, so this will be ignored unless changed
                RowItemModel( [-3, -1, 300, "Hepatic Panel",1], headers ),
                RowItemModel( [-4, -1, 400, "Cardiac Enzymes",1], headers ),
                RowItemModel( [-5, -2, 500, "CXR",1], headers ),
                RowItemModel( [-6, -2, 600, "RUQ Ultrasound",1], headers ),
                RowItemModel( [-7, -2, 700, "CT Abdomen/Pelvis",1], headers ),
                RowItemModel( [-8, -2, 800, "CT PE Thorax",1], headers ),
                RowItemModel( [-9, -3, 900, "Acetaminophen",1], headers ),
                RowItemModel( [-10, -3, 1000, "Carvedilol",1], headers ),
                RowItemModel( [-11, -3, 100, "Enoxaparin",1], headers ),
                RowItemModel( [-12, -3, 200, "Warfarin",1], headers ),
                RowItemModel( [-13, -3, 300, "Ceftriaxone",1], headers ),
                RowItemModel( [-14, -4, 400, "Foley Catheter",1], headers ),
                RowItemModel( [-15, -4, 500, "Strict I&O",1], headers ),
                RowItemModel( [-16, -4, 600, "Fall Precautions",1], headers ),
                RowItemModel( [-77, -7, 700, "No Rec Item",1], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)

        dataTextStr = \
"""patient_item_id;patient_id;clinical_item_id;item_date
-1;-123;-6;3/11/2012 10:57
-2;-123;-7;3/11/2012 10:57
-3;-123;-1;4/11/2012 10:57
-4;-123;-2;4/11/2012 10:57
-5;-123;-3;4/11/2012 10:57
-6;-123;-4;4/11/2012 10:57
-8;-123;-8;4/11/2012 10:57
-9;-123;-9;4/11/2012 10:57
-10;-123;-10;4/11/2012 0:00
-11;-123;-11;4/11/2012 10:57
-12;-123;-12;4/11/2012 10:57
-13;-123;-13;4/11/2012 10:57
-14;-123;-12;4/12/2012 3:57
-15;-123;-14;4/12/2012 3:57
-16;-123;-15;4/12/2012 3:57
-17;-123;-16;4/12/2012 3:57
-18;-123;-13;5/12/2012 8:57
-19;-123;-5;5/12/2012 8:57
-21;-456;-4;12/24/2013 6:50
-22;-456;-4;12/24/2013 7:50
-24;-456;-77;12/24/2013 8:50
-25;-456;-10;12/24/2013 0:00
-26;-456;-12;12/24/2013 6:50
-27;-456;-12;12/24/2013 6:55
-28;-456;-12;12/24/2013 6:59
-29;-456;-12;12/24/2013 18:50
-30;-456;-12;12/24/2013 19:50
-31;-456;-14;12/24/2013 18:50
-32;-456;-8;12/24/2013 18:50
-33;-456;-8;12/24/2013 20:50
-34;-456;-8;12/24/2013 18:30
-35;-789;-1;8/19/2011 11:12
-36;-789;-3;8/19/2011 11:12
-37;-789;-3;8/19/2011 0:12
-38;-789;-3;8/19/2011 0:52
-39;-789;-5;8/19/2011 11:12
-40;-789;-9;8/19/2011 11:12
-41;-789;-9;8/19/2011 0:12
-42;-789;-9;8/19/2011 13:12
-43;-789;-10;8/19/2011 0:00
-44;-789;-11;8/19/2011 11:12
-45;-789;-13;8/19/2011 19:12
-46;-789;-15;8/19/2011 19:12
-47;-789;-15;8/19/2011 19:14
-48;-789;-15;8/19/2011 19:22
-49;-789;-15;8/19/2011 19:32
-50;-789;-15;8/19/2011 19:42
-1001;-321;-6;3/11/2012 10:57
-1002;-321;-7;3/11/2012 10:57
-1010;-321;-10;4/11/2012 0:00
-1003;-321;-1;4/11/2012 10:57
-1004;-321;-2;4/11/2012 10:57
-1005;-321;-3;4/11/2012 10:57
-1006;-321;-4;4/11/2012 10:57
-1008;-321;-8;4/11/2012 10:57
-1009;-321;-9;4/11/2012 10:57
-1011;-321;-11;4/11/2012 10:57
-1012;-321;-12;4/11/2012 10:57
-1013;-321;-13;4/11/2012 10:57
-1014;-321;-12;4/12/2012 3:57
-1015;-321;-14;4/12/2012 3:57
-1016;-321;-15;4/12/2012 3:57
-1017;-321;-16;4/12/2012 3:57
-1018;-321;-13;4/12/2012 8:57
-1019;-321;-5;4/12/2012 8:57
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr), "patient_item", delim=";")


        dataTextStr = \
"""item_collection_id;external_id;name;section;subgroup
-1;-1;Test Order Set - 1;Meds;TreatmentMeds
-2;-1;Test Order Set - 1;Meds;SymptomsMeds
-3;-1;Test Order Set - 1;Labs;GeneralLabs
-4;-2;Test Order Set - 2;Labs;GeneralLabs
-5;-2;Test Order Set - 2;Imaging;Xrays
-6;-2;Test Order Set - 2;Imaging;AdvancedImaging
-7;-3;Test Order Set - 3;Imaging;GeneralImaging
-8;-3;Test Order Set - 3;Nursing;GeneralNursing
-9;-4;Test Order Set - 4;Ad-hoc Orders;Ad-hoc Orders
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr), "item_collection", delim=";")

        dataTextStr = \
"""item_collection_item_id;item_collection_id;clinical_item_id;collection_type_id
-1;-1;-12;4
-2;-1;-13;4
-3;-2;-11;4
-4;-2;-10;4
-5;-3;-1;4
-6;-3;-2;4
-7;-4;-2;4
-8;-4;-3;4
-9;-5;-5;4
-10;-6;-6;4
-11;-6;-7;4
-12;-6;-8;4
-74;-6;-4;4
-77;-6;-77;4
-13;-7;-5;4
-14;-7;-6;4
-15;-8;-14;4
-16;-8;-15;4
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr),
                          "item_collection_item",
                          delim=";")

        dataTextStr = \
"""patient_item_collection_link_id;patient_item_id;item_collection_item_id
-1;-3;-5
-2;-4;-6
-3;-15;-15
-4;-32;-12
-1001;-1003;-5
-1002;-1004;-6
-1003;-1015;-15
-1004;-1019;-9
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr),
                          "patient_item_collection_link",
                          delim=";")

        # Sample Prepared Validation File
        self.validationFileStr = \
"""patient_id\tqueryItemCountByIdJSON\tverifyItemCountByIdJSON\tbaseItemId\tbaseItemDate\tqueryStartTime\tqueryEndTime\tverifyEndTime\toutcome.7
-123\t{"-1": 1, "-2": 1, "-3": 1, "-4": 1, "-8": 1, "-9": 1, "-10": 1, "-11": 1, "-12": 1, "-13": 1}\t{"-12": 1, "-14": 1, "-15": 1, "-16": 1}\t10\t2012-04-11 00:00:00\t2012-04-11 10:57:00\t2012-04-11 14:57:00\t2012-04-12 10:57:00\t0
-456\t{"-4": 2, "-77": 1, "-10": 1, "-12": 3}\t{"-12": 2, "-14": 1, "-8": 3}\t10\t2013-12-24 00:00:00\t2013-12-24 06:50:00\t2013-12-24 10:50:00\t2013-12-25 06:50:00\t1
-789\t{"-1": 1, "-3": 3, "-5": 1, "-9": 3, "-10": 1, "-11": 1}\t{"-13": 1, "-15": 5}\t10\t2011-08-19 00:00:00\t2011-08-19 11:12:00\t2011-08-19 15:12:00\t2011-08-20 11:12:00\t0
-321\t{"-1": 1, "-2": 1, "-3": 1, "-4": 1, "-8": 1, "-9": 1, "-10": 1, "-11": 1, "-12": 1, "-13": 1}\t{"-12": 1, "-14": 1, "-15": 1, "-16": 1}\t10\t2012-04-11 00:00:00\t2012-04-11 10:57:00\t2012-04-11 14:57:00\t2012-04-12 10:57:00\t0
"""

        # Another Sample Prepared Validation File, with key Order Set triggers
        self.orderSetValidationFileStr = \
"""patient_id\tqueryItemCountByIdJSON\tverifyItemCountByIdJSON\tbaseItemId\tbaseItemDate\tqueryStartTime\tqueryEndTime\tverifyEndTime\toutcome.7\torder_set_id
-123\t{"-10": 1}\t{"-1": 1, "-2": 1, "-3": 1, "-4": 1, "-8": 1, "-9": 1, "-11": 1, "-12": 1, "-13": 1}\t10\t2012-04-11 00:00:00\t2012-04-11 10:57:00\t2012-04-11 10:57:00\t2012-04-11 11:57:00\t0\t-1
-456\t{"-10": 1, "-4": 2, "-77": 1, "-12": 4, "-14": 1, "-8": 1}\t{"-12": 1, "-8": 2}\t10\t2013-12-24 00:00:00\t2013-12-24 06:50:00\t2013-12-24 18:50:00\t2013-12-24 19:50:00\t1\t-2
-789\t{"-1": 1, "-3": 3, "-5": 1, "-9": 3, "-10": 1, "-11": 1}\t{"-13": 1, "-15": 5}\t10\t2011-08-19 00:00:00\t2011-08-19 11:12:00\t2011-08-19 15:12:00\t2011-08-20 11:12:00\t0\t-4
-321\t{"-10": 1}\t{"-1": 1, "-2": 1, "-3": 1, "-4": 1, "-8": 1, "-9": 1, "-11": 1, "-12": 1, "-13": 1}\t10\t2012-04-11 00:00:00\t2012-04-11 10:57:00\t2012-04-11 10:57:00\t2012-04-11 11:57:00\t0\t-1
-321\t{"-10": 1, "-1": 1, "-2": 1, "-3": 1, "-4": 1, "-8": 1, "-9": 1, "-11": 1, "-12": 1, "-13": 1}\t{"-12": 1,"-14": 1, "-15": 1, "-16": 1}\t10\t2012-04-11 00:00:00\t2012-04-11 10:57:00\t2012-04-12 3:57:00\t2012-04-12 4:57:00\t0\t-3
"""

        self.analyzer = OrderSetUsageAnalysis()
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        self.clinicalItemCategoryIdStrList = list()
        headers = ["clinical_item_category_id", "source_table"]
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = ["clinical_item_id", "clinical_item_category_id", "name"]
        dataModels = \
            [
                RowItemModel( [-1, -1, "CBC"], headers ),
                RowItemModel( [-2, -1, "BMP"], headers ),
                RowItemModel( [-3, -1, "Hepatic Panel"], headers ),
                RowItemModel( [-4, -1, "Cardiac Enzymes"], headers ),
                RowItemModel( [-5, -2, "CXR"], headers ),
                RowItemModel( [-6, -2, "RUQ Ultrasound"], headers ),
                RowItemModel( [-7, -2, "CT Abdomen/Pelvis"], headers ),
                RowItemModel( [-8, -2, "CT PE Thorax"], headers ),
                RowItemModel( [-9, -3, "Acetaminophen"], headers ),
                RowItemModel( [-10, -3, "Carvedilol"], headers ),
                RowItemModel( [-11, -3, "Enoxaparin"], headers ),
                RowItemModel( [-12, -3, "Warfarin"], headers ),
                RowItemModel( [-13, -3, "Ceftriaxone"], headers ),
                RowItemModel( [-14, -4, "Foley Catheter"], headers ),
                RowItemModel( [-15, -4, "Strict I&O"], headers ),
                RowItemModel( [-16, -4, "Fall Precautions"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)

        headers = [
            "patient_item_id", "patient_id", "clinical_item_id", "item_date",
            "analyze_date"
        ]
        dataModels = \
            [
                RowItemModel( [-1,  -11111, -4,  datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-2,  -11111, -10, datetime(2000, 1, 1, 1), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -11111, -8,  datetime(2000, 1, 1, 2), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-4,  -11111, -10, datetime(2000, 1, 2, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-5,  -11111, -12, datetime(2000, 2, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-10, -22222, -7,  datetime(2000, 1, 5, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-12, -22222, -6,  datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-13, -22222, -11, datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-14, -33333, -6,  datetime(2000, 2, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-15, -33333, -2,  datetime(2000, 2,11, 0), datetime(2010, 1, 1, 0)], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("patient_item", dataModel)

        headers = \
            [   "clinical_item_id","subsequent_item_id",
                "count_0","count_3600","count_86400","count_604800","count_any",
                "time_diff_sum", "time_diff_sum_squares",
            ]
        dataModels = \
            [
                RowItemModel( [ -1, -1,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -2, -2,   30, 30, 30, 30, 30,  0.0, 0.0], headers ),
                RowItemModel( [ -3, -3,   95, 95, 97, 97, 97,  0.0, 0.0], headers ),
                RowItemModel( [ -4, -4,  240,240,240,240,240,  0.0, 0.0], headers ),
                RowItemModel( [ -5, -5,   40, 40, 50, 50, 50,  0.0, 0.0], headers ),
                RowItemModel( [ -6, -6,   70, 70, 70, 70, 70,  0.0, 0.0], headers ),
                RowItemModel( [ -7, -7,   35, 35, 35, 50, 80,  0.0, 0.0], headers ),
                RowItemModel( [ -8, -8,   35, 35, 35, 50, 80,  0.0, 0.0], headers ),
                RowItemModel( [-10,-10,   45, 45, 55, 60, 90,  0.0, 0.0], headers ),
                RowItemModel( [-12,-12,   75, 75, 75, 80, 90,  0.0, 0.0], headers ),



                RowItemModel( [ -2, -4,    0,  2,  3,  3,  3,  200.0, 50000.0], headers ),
                RowItemModel( [ -2, -6,    2,  2,  5,  5,  5,  300.0, 11990.0], headers ),
                RowItemModel( [ -3, -1,   20, 23, 23, 23, 23,  400.0, 344990.0], headers ),
                RowItemModel( [ -4, -5,    3,  3, 13, 43, 43,  340.0, 343110.0], headers ),
                RowItemModel( [ -4, -6,   23, 33, 33, 33, 63,  420.0, 245220.0], headers ),
                RowItemModel( [ -4, -7,   27, 33, 33, 33, 83,   40.0, 5420.0], headers ),
                RowItemModel( [ -4, -8,    1,  2,  3,  4,  5,   40.0, 5420.0], headers ),
                RowItemModel( [ -4,-10,   25, 35, 40, 45, 73,   47.0, 5420.0], headers ),
                RowItemModel( [ -5, -4,    0,  0, 20, 20, 20,  540.0, 54250.0], headers ),
                RowItemModel( [-10, -8,    2,  4,  6,  8, 10,   47.0, 5420.0], headers ),
                RowItemModel( [-10, -12,  12, 14, 16, 18, 20,   47.0, 5420.0], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_association",
                                              dataModel)

        # Indicate that cache data needs tobe updated
        self.dataManager = DataManager()
        self.dataManager.clearCacheData("analyzedPatientCount")
        self.dataManager.clearCacheData("clinicalItemCountsUpdated")

        # Instance to test on
        self.analyzer = RecommendationRankingTrendAnalysis()
예제 #12
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        self.clinicalItemCategoryIdStrList = list()
        headers = ["clinical_item_category_id", "source_table"]
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = [
            "clinical_item_id", "clinical_item_category_id", "name",
            "analysis_status"
        ]
        dataModels = \
            [
                RowItemModel( [-1, -1, "CBC",1], headers ),
                RowItemModel( [-2, -1, "BMP",0], headers ), # Clear analysis status, so this will be ignored unless changed
                RowItemModel( [-3, -1, "Hepatic Panel",1], headers ),
                RowItemModel( [-4, -1, "Cardiac Enzymes",1], headers ),
                RowItemModel( [-5, -2, "CXR",1], headers ),
                RowItemModel( [-6, -2, "RUQ Ultrasound",1], headers ),
                RowItemModel( [-7, -2, "CT Abdomen/Pelvis",1], headers ),
                RowItemModel( [-8, -2, "CT PE Thorax",1], headers ),
                RowItemModel( [-9, -3, "Acetaminophen",1], headers ),
                RowItemModel( [-10, -3, "Carvedilol",1], headers ),
                RowItemModel( [-11, -3, "Enoxaparin",1], headers ),
                RowItemModel( [-12, -3, "Warfarin",1], headers ),
                RowItemModel( [-13, -3, "Ceftriaxone",1], headers ),
                RowItemModel( [-14, -4, "Foley Catheter",1], headers ),
                RowItemModel( [-15, -4, "Strict I&O",1], headers ),
                RowItemModel( [-16, -4, "Fall Precautions",1], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)

        headers = [
            "patient_item_id", "encounter_id", "patient_id",
            "clinical_item_id", "item_date"
        ]
        dataModels = \
            [
                RowItemModel( [-1,  -111,   -11111, -4,  datetime(2000, 1, 1, 0)], headers ),
                RowItemModel( [-2,  -111,   -11111, -10, datetime(2000, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -111,   -11111, -8,  datetime(2000, 1, 1, 2)], headers ),
                RowItemModel( [-4,  -112,   -11111, -10, datetime(2000, 1, 2, 0)], headers ),
                RowItemModel( [-5,  -112,   -11111, -12, datetime(2000, 2, 1, 0)], headers ),
                RowItemModel( [-10, -222,   -22222, -7,  datetime(2000, 1, 5, 0)], headers ),
                RowItemModel( [-12, -222,   -22222, -6,  datetime(2000, 1, 9, 0)], headers ),
                RowItemModel( [-13, -222,   -22222, -11, datetime(2000, 1, 9, 0)], headers ),
                RowItemModel( [-95, -222,   -22222, -9,  datetime(2000, 1,10, 0)], headers ),
                RowItemModel( [-94, -333,   -33333, -8,  datetime(2000, 1,10, 0)], headers ),    # In first window delta unit only
                RowItemModel( [-14, -333,   -33333, -6,  datetime(2000, 2, 9, 0)], headers ),
                RowItemModel( [-15, -333,   -33333, -2,  datetime(2000, 2,11, 0)], headers ),  # Will set clinical_item_link inheritances to this item to only record certain associations
                RowItemModel( [-16, -333,   -33333, -11, datetime(2000, 2,11, 0)], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("patient_item", dataModel)

        headers = ["clinical_item_id", "linked_item_id"]
        dataModels = \
            [   # Don't have direct, but instead demonstrate inherited relationship from 6 to 2 will still be recognized
                RowItemModel( [-6, -4], headers ),
                RowItemModel( [-4, -2], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_link", dataModel)

        self.decayAnalyzer = DecayingWindows(
        )  # DecayingWindows instance to test on, *** remember to change database to medinfo_copy
        self.dataManager = DataManager()
예제 #13
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        StrideLoader.build_stride_psql_schemata()
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()

        self.patientIdStrList = list()
        headers = [
            "pat_id", "pat_enc_csn_id", "noted_date", "resolved_date",
            "dx_icd9_code", "dx_icd9_code_list", "dx_icd10_code_list",
            "data_source"
        ]
        dataModels = \
            [
                RowItemModel( ["-126500", -131017780655, "2111-10-14", None, "-431.00", "-431.00,-432","","PROBLEM_LIST"], headers ),
                RowItemModel( ["-126268", -131015534571, "2111-05-04", None, "-0285", "-0285,-0286","","PROBLEM_LIST"], headers ),
                RowItemModel( ["-126268", -131015534571, None, None, "-272.4", "-272.4,-273","","PROBLEM_LIST"], headers ),
                RowItemModel( ["-126268", -131015534571, None, None, "-309.9", "-309.9,-310","","ENC_Dx"], headers ),
                RowItemModel( ["-126268", -131015534571, "2111-05-18", None, "-785", "-785,-786","","ADMIT_DX"], headers ),
                RowItemModel( ["-126472", -131015404439, None, None, "-719.46", "-719.46,-720","","ENC_Dx"], headers ),

                # Repeat, but under different encounter, should be ignored, just base on noted date
                RowItemModel( ["-126500", -131000000000, "2111-10-14", None, "-431.00", "-431.00,-432","","PROBLEM_LIST"], headers ),
                RowItemModel( ["-126798", -131014753610, None, None, "-482.9", "-482.9,-483","","ENC_Dx"], headers ),
                RowItemModel( ["-126798", -131014753610, "2111-03-08", None, "-780", "-780,-781","","ADMIT_DX"], headers ),
                RowItemModel( ["-126798", -131016557370, "2111-07-26", None, "-780.97", "-780.97,-781","","ADMIT_DX"], headers ),    # No matching diagnosis code, will just make up a label then

                # Different patient, but using ICD9 list instead of ICD9 code
                # If there is no ICD9 list, and only ICD10 list, we will need
                # to add special logic and decide whether to try to
                # cross-reference with ICD9-based Dx'es
                RowItemModel( ["-2126500", -135000000000, "2111-10-14", None, "", "-431.00,-432","-10431.00,-10432","PROBLEM_LIST"], headers ),
                RowItemModel( ["-2126798", -135014753610, "2111-06-06", None, "", "-482.9,-483","-10482.9,-10483","PROBLEM_LIST"], headers ),
                RowItemModel( ["-2126798", -135014753610, "2111-03-08", None, "", "-780","-10780","ADMIT_DX"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("stride_dx_list",
                                                          dataModel,
                                                          retrieveCol="pat_id")
            self.patientIdStrList.append(str(dataItemId))

        self.icd9CUIdStrList = list()
        headers = ["cui", "ispref", "aui", "tty", "code", "str", "suppress"]
        dataModels = \
            [
                RowItemModel( ["-C1", "Y", "-A1", "PT", "-0285", "Diagnosis 1","N"], headers ),
                RowItemModel( ["-C2b","Y", "-A2b","PT", "-431.0", "Diagnosis 2b","N"], headers ),    # Parent diagnoses
                RowItemModel( ["-C2", "Y", "-A2", "PT", "-431.00", "Diagnosis 2","N"], headers ),
                RowItemModel( ["-C3", "N", "-A3", "AB", "-431.00", "Diagnosis 3","N"], headers ),    # Repeat, but not preferred
                RowItemModel( ["-C4", "N", "-A4", "HT", "-785", "Diagnosis 4","N"], headers ),
                RowItemModel( ["-C5", "Y", "-A5", "HT", "-780", "Diagnosis 5","N"], headers ),
                RowItemModel( ["-C6a","Y", "-A6a","PT", "-780.9", "Diagnosis 6a","N"], headers ),
                RowItemModel( ["-C6", "Y", "-A6", "PT", "-780.97", "Diagnosis 6","N"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("stride_icd9_cm",
                                                          dataModel,
                                                          retrieveCol="cui")
            self.icd9CUIdStrList.append(str(dataItemId))

        self.icd10_order_number_str_list = list()
        headers = [
            'order_number', 'icd10', 'hipaa_covered', 'short_description',
            'full_description', 'icd10_code'
        ]
        data_models = [
            RowItemModel([
                -1, '-1043100', 1, 'Diagnosis 2', 'Diagnosis 2 Full',
                '-10431.00'
            ], headers),
            RowItemModel([
                -2, '-104310', 0, 'Diagnosis 2b', 'Diagnosis 2b Full',
                '-10431.0'
            ], headers),
            RowItemModel(
                [-6, '-10780', 0, 'Diagnosis 5', 'Diagnosis 5 Full', '-10780'],
                headers)
        ]
        for data_model in data_models:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("stride_icd10_cm",
                                              data_model,
                                              retrieveCol='order_number')
            self.icd10_order_number_str_list.append(str(dataItemId))

        self.converter = STRIDEDxListConversion()
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self);

        log.info("Populate the database with test data")
        StrideLoader.build_stride_psql_schemata()
        ClinicalItemDataLoader.build_clinical_item_psql_schemata();

        self.orderMedIdStrList = list();
        headers = ["order_med_id", "pat_id", "pat_enc_csn_id", "ordering_date", "medication_id", "description","freq_name","med_route","number_of_doses"];
        dataModels = \
            [   # Deliberately design dates in far future to facilitate isolated testing
                RowItemModel( [ -418063010, "3032765", 111, datetime(2111,12,12, 8,56), 9000000, "ZZZ IMS TEMPLATE","DAILY","PO", None], headers ),
                RowItemModel( [ -418436155, "1607844", 222, datetime(2111,12,20, 0,40), -1080, "BISACODYL 10 MG PR SUPP","DAILY PRN","PR", None], headers ),
                RowItemModel( [ -418436145, "1607844", 222, datetime(2111,12,22, 0,40), -1080, "BISACODYL 10 MG PR SUPP","DAILY","PR", None], headers ),
                RowItemModel( [ -421032269, "2968778", 333, datetime(2112, 2, 8,11,17), -96559, "PIPERACILLIN-TAZOBACTAM-DEXTRS 3.375 GRAM/50 ML IV PGBK","EVERY 6 HOURS","IV", None], headers ),
                RowItemModel( [ -418011851, "-2429057", 444, datetime(2111,12,10,19, 9), -10011, "FAMOTIDINE 20 MG PO TABS","2 TIMES DAILY","PO", None], headers ),
                RowItemModel( [ -418013851, "-2429057", 444, datetime(2111,12,10,19,10), -10012, "FAMOTIDINE 40 MG PO TABS","2 TIMES DAILY","PO", None], headers ),
                RowItemModel( [ -418062652, "3036488", 555, datetime(2111,12,12, 8,30), -5007, "METOPROLOL TARTRATE 5 MG/5 ML IV SOLN 20 mg injection","ONCE","IV", 1], headers ),
                RowItemModel( [ -418062352, "3016488", 666, datetime(2111,12,13, 8,30), -5007, "METOPROLOL TARTRATE 5 MG/5 ML IV SOLN","ONCE","IV", 1], headers ),
                RowItemModel( [ -414321352, "3036588", 777, datetime(2111,12,14, 8,30), -5007, "ZZZ IMS TEMPLATE","ONCE","IV", 1], headers ),

                # Simple mixture in unimportant base
                RowItemModel( [ -395900000, "1234567", 888, datetime(2111, 1, 2, 3, 0), -520102, "CEFEPIME 2 GM IVPB","ONCE","IV", 1], headers ),
                RowItemModel( [ -395800000, "1234567", 888, datetime(2111, 1,10, 3, 0), -520102, "CEFEPIME 2 GM IVPB","q8h","IV", 6], headers ),  # Fixed number of doses
                RowItemModel( [ -395700000, "1234567", 888, datetime(2111, 3,10, 3, 0), -520102, "CEFEPIME 2 GM IVPB","q8h","IV", None], headers ),  # No dose limit specified

                # Complex mixtures
                RowItemModel( [ -392000000, "1234567", 888, datetime(2111, 4, 1, 3, 0), -530000, "IVF Mix","ONCE","IV", 1], headers ),
                RowItemModel( [ -391000000, "1234567", 888, datetime(2111, 4, 2, 3, 0), -540000, "Mini TPN","ONCE","IV", 1], headers ),
                RowItemModel( [ -390000000, "1234567", 888, datetime(2111, 5, 2, 3, 0), -550000, "TPN Adult","Continuous","IV", None], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("stride_order_med", dataModel, retrieveCol="order_med_id" );
            self.orderMedIdStrList.append( str(dataItemId) );

        # Child table for more detailed mixtures
        headers = ["order_med_id", "line", "medication_id", "medication_name","ingredient_type_c","ingredient_type"];
        dataModels = \
            [   # Just a dose combination
                RowItemModel( [ -418063010, 1, -6494, "PREDNISONE 10 MG PO TABS", 3, "Medications",], headers ),
                RowItemModel( [ -418063010, 2, -6498, "PREDNISONE 50 MG PO TABS", 3, "Medications",], headers ),

                # Simple mixture with a base fluid of negligible significance
                RowItemModel( [ -395900000, 1, -87114, "CEFEPIME 2 GRAM IV SOLR", 3, "Medications",], headers ),
                RowItemModel( [ -395900000, 2, -2364, "DEXTROSE 5 % IN WATER (D5W) IV SOLP", 1, "Base",], headers ),
                RowItemModel( [ -395800000, 1, -87114, "CEFEPIME 2 GRAM IV SOLR", 3, "Medications",], headers ),
                RowItemModel( [ -395800000, 2, -2364, "DEXTROSE 5 % IN WATER (D5W) IV SOLP", 1, "Base",], headers ),
                RowItemModel( [ -395700000, 1, -87114, "CEFEPIME 2 GRAM IV SOLR", 3, "Medications",], headers ),
                RowItemModel( [ -395700000, 2, -2364, "DEXTROSE 5 % IN WATER (D5W) IV SOLP", 1, "Base",], headers ),

                # IVF Mix
                RowItemModel( [ -392000000, 2, -2367, "DEXTROSE 70 % IN WATER (D70W) IV SOLP", 1, "Base",], headers ),
                RowItemModel( [ -392000000, 3, -7322, "SODIUM CHLORIDE 4 MEQ/ML IV SOLP", 2, "Additives",], headers ),
                RowItemModel( [ -392000000, 5, -116034, "POTASSIUM CHLORIDE 2 MEQ/ML IV SOLP", 2, "Additives",], headers ),

                # Mini mixture, expands
                RowItemModel( [ -391000000, 1, -203799, "PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP", 1, "Base",], headers ),
                RowItemModel( [ -391000000, 2, -2367, "DEXTROSE 70 % IN WATER (D70W) IV SOLP", 1, "Base",], headers ),
                RowItemModel( [ -391000000, 3, -7322, "SODIUM CHLORIDE 4 MEQ/ML IV SOLP", 2, "Additives",], headers ),
                RowItemModel( [ -391000000, 4, -7351, "SODIUM PHOSPHATE 3 MMOL/ML IV SOLN", 2, "Additives",], headers ),

                # Complex mixture
                RowItemModel( [ -390000000, 1, -203799, "PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP", 1, "Base",], headers ),
                RowItemModel( [ -390000000, 2, -2367, "DEXTROSE 70 % IN WATER (D70W) IV SOLP", 1, "Base",], headers ),
                RowItemModel( [ -390000000, 3, -7322, "SODIUM CHLORIDE 4 MEQ/ML IV SOLP", 2, "Additives",], headers ),
                RowItemModel( [ -390000000, 4, -7351, "SODIUM PHOSPHATE 3 MMOL/ML IV SOLN", 2, "Additives",], headers ),
                RowItemModel( [ -390000000, 5, -116034, "POTASSIUM CHLORIDE 2 MEQ/ML IV SOLP", 2, "Additives",], headers ),
                RowItemModel( [ -390000000, 6, -1312, "CALCIUM GLUCONATE 100 MG/ML (10%) IV SOLN", 2, "Additives",], headers ),
                RowItemModel( [ -390000000, 7, -4720, "MAGNESIUM SULFATE 4 MEQ/ML (50 %) INJ SOLN", 2, "Additives",], headers ),
                RowItemModel( [ -390000000, 8, -8047, "TRACE ELEM ZN-CUPRIC CL-MN-CR 0.8-0.2-0.16 MG IV SOLN", 2, "Additives",], headers ),
                RowItemModel( [ -390000000, 9, -124215, "MVI, ADULT NO.1 WITH VIT K 3,300 UNIT- 150 MCG/10 ML IV SOLN", 2, "Additives",], headers ),
                RowItemModel( [ -390000000, 10,-540571, "INSULIN REG HUMAN 100 UNITS/ML INJ", 2, "Additives",], headers ),

            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("stride_order_medmixinfo", dataModel, retrieveCol="order_med_id" );

        # Mapping table to simplify dose
        headers = ["medication_id", "name", "rxcui", "active_ingredient"];
        dataModels = \
            [   # If multiple active ingredients in a combo, unravel to active components
                RowItemModel( [ -96559, "PIPERACILLIN-TAZOBACTAM-DEXTRS 3.375 GRAM/50 ML IV PGBK", -1001, "Piperacillin"], headers ),
                RowItemModel( [ -96559, "PIPERACILLIN-TAZOBACTAM-DEXTRS 3.375 GRAM/50 ML IV PGBK", -1002, "Tazobactam"], headers ),

                # Multiple names / dosage totals for the same medication, use this mapping to narrow to a common ingredient
                RowItemModel( [ -10011, "FAMOTIDINE 20 MG PO TABS", -2001, "Famotidine"], headers ),
                RowItemModel( [ -10012, "FAMOTIDINE 40 MG PO TABS", -2001, "Famotidine"], headers ),
                RowItemModel( [ -1080, "BISACODYL 10 MG PR SUPP", -3001, "Bisacodyl"], headers ),
                RowItemModel( [ -6494, "PREDNISONE 10 MG PO TABS", -4001, "prednisone"], headers ),
                RowItemModel( [ -6498, "PREDNISONE 50 MG PO TABS", -4001, "prednisone"], headers ),

                # Simple mixture
                RowItemModel( [ -87114, "CEFEPIME 2 GRAM IV SOLR", -20481, "cefepime"], headers ),
                RowItemModel( [ -2364, "DEXTROSE 5% IN WATER (D5W) IV SOLP", -4850, "Glucose"], headers ),

                # Additional medication level mapping should probably ignored if have mixture components
                RowItemModel( [ -520102, "CEFEPIME 2 GM IVPB", -20481, "cefepime"], headers ),

                # Complex ingredients
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -10898,  'Tryptophan',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -11115,  'Valine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -4919,   'Glycine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -5340,   'Histidine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -6033,   'Isoleucine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -6308,   'Leucine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -6536,   'Lysine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -6837,   'Methionine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -8156,   'Phenylalanine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -8737,   'Proline',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -9671,   'Serine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -10524,  'Threonine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -10962,  'Tyrosine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -426,    'Alanine',], headers ),
                RowItemModel( [ -203799, 'PARENTERAL AMINO ACID 10% NO.6 10 % IV SOLP',   -1091,   'Arginine',], headers ),
                RowItemModel( [ -2367,   'DEXTROSE 70% IN WATER (D70W) IV SOLP',  -4850,   'Glucose',], headers ),
                RowItemModel( [ -7322,   'SODIUM CHLORIDE 4 MEQ/ML IV SOLP',  -9863,   'Sodium Chloride',], headers ),
                RowItemModel( [ -7351,   'SODIUM PHOSPHATE 3 MILLIMOLE/ML IV SOLN',   -235496, 'Sodium Phosphate, Monobasic',], headers ),
                RowItemModel( [ -7351,   'SODIUM PHOSPHATE 3 MILLIMOLE/ML IV SOLN',   -236719, 'Sodium Phosphate, Dibasic',], headers ),
                RowItemModel( [ -116034, 'POTASSIUM CHLORIDE 2 MEQ/ML IV SOLP',   -8591,   'Potassium Chloride',], headers ),
                RowItemModel( [ -1312,   'CALCIUM GLUCONATE 100 MG/ML (10%) IV SOLN', -1908,   'Calcium Gluconate',], headers ),
                RowItemModel( [ -4720,   'MAGNESIUM SULFATE 50 % (4 MEQ/ML) INJ SOLN',    -6585,   'Magnesium Sulfate',], headers ),
                RowItemModel( [ -8047,   'TRACE ELEM ZN-CUPRIC CL-MN-CR 0.8-0.2-0.16 MG IV SOLN', -39937,  'zinc chloride',], headers ),
                RowItemModel( [ -8047,   'TRACE ELEM ZN-CUPRIC CL-MN-CR 0.8-0.2-0.16 MG IV SOLN', -21032,  'chromous chloride',], headers ),
                RowItemModel( [ -8047,   'TRACE ELEM ZN-CUPRIC CL-MN-CR 0.8-0.2-0.16 MG IV SOLN', -21579,  'Copper Sulfate',], headers ),
                RowItemModel( [ -8047,   'TRACE ELEM ZN-CUPRIC CL-MN-CR 0.8-0.2-0.16 MG IV SOLN', -29261,  'manganese chloride',], headers ),
                RowItemModel( [ -124215, 'MVI, ADULT NO.1 WITH VIT K 1-5-10-200 MG-MCG-MG-MG IV SOLN',    -8308,   'Vitamin K 1',], headers ),
                RowItemModel( [ -124215, 'MVI, ADULT NO.1 WITH VIT K 1-5-10-200 MG-MCG-MG-MG IV SOLN',    -89905,  'Multivitamin preparation',], headers ),
                RowItemModel( [ -540571, 'INSULIN REG HUMAN 100 UNITS/ML INJ',    -253182, 'Regular Insulin, Human',], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("stride_mapped_meds", dataModel, retrieveCol="rxcui" );

        # Certain items drawn from order sets
        headers = ["order_med_id", "protocol_id","protocol_name","section_name","smart_group"];
        dataModels = \
            [
                RowItemModel( [ -418436145, -111, "General Admit", "Medications", "Stool Softeners",], headers ),
                RowItemModel( [ -421032269, -111, "General Admit", "Medications", "Antibiotics",], headers ),
                RowItemModel( [ -391000000, -222, "Nutrition", "Infusions", "TPN",], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("stride_orderset_order_med", dataModel, retrieveCol="order_med_id" );

        self.converter = STRIDEOrderMedConversion();  # Instance to test on
예제 #15
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self)

        log.info("Populate the database with test data")
        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader
        ClinicalItemDataLoader.build_clinical_item_psql_schemata()
        #self.purgeTestRecords();

        self.clinicalItemCategoryIdStrList = list()
        headers = [
            "clinical_item_category_id", "default_recommend", "source_table"
        ]
        dataModels = \
            [
                RowItemModel( [-1, 1, "Labs"], headers ),
                RowItemModel( [-2, 1, "Imaging"], headers ),
                RowItemModel( [-3, 1, "Meds"], headers ),
                RowItemModel( [-4, 1, "Nursing"], headers ),
                RowItemModel( [-5, 0, "Problems"], headers ),
                RowItemModel( [-6, 1, "Lab Results"], headers ),
                RowItemModel( [-7, 1, "Admit Dx"], headers ),
                RowItemModel( [-8, 0, "Demographics"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item_category",
                                              dataModel)
            self.clinicalItemCategoryIdStrList.append(str(dataItemId))

        headers = [
            "clinical_item_id", "clinical_item_category_id", "analysis_status",
            "default_recommend", "name"
        ]
        dataModels = \
            [
                RowItemModel( [-1, -1, 1, 1, "CBC"], headers ),
                RowItemModel( [-2, -1, 1, 1, "BMP"], headers ),
                RowItemModel( [-3, -1, 1, 1, "Hepatic Panel"], headers ),
                RowItemModel( [-4, -1, 1, 1, "Cardiac Enzymes"], headers ),
                RowItemModel( [-5, -2, 1, 1, "CXR"], headers ),
                RowItemModel( [-6, -2, 1, 1, "RUQ Ultrasound"], headers ),
                RowItemModel( [-7, -2, 1, 1, "CT Abdomen/Pelvis"], headers ),
                RowItemModel( [-8, -2, 1, 1, "CT PE Thorax"], headers ),
                RowItemModel( [-9, -3, 1, 1, "Acetaminophen"], headers ),
                RowItemModel( [-10, -3, 1, 1, "Carvedilol"], headers ),
                RowItemModel( [-11, -3, 1, 1, "Enoxaparin"], headers ),
                RowItemModel( [-12, -3, 1, 1, "Warfarin"], headers ),
                RowItemModel( [-13, -3, 1, 0, "Ceftriaxone"], headers ),
                RowItemModel( [-14, -4, 1, 1, "Foley Catheter"], headers ),
                RowItemModel( [-15, -4, 1, 1, "Strict I&O"], headers ),
                RowItemModel( [-16, -4, 1, 1, "Fall Precautions"], headers ),

                RowItemModel( [-22, -5, 1, 1, "Diagnosis 2"], headers ),
                RowItemModel( [-23, -5, 1, 1, "Diagnosis 3"], headers ),
                RowItemModel( [-24, -5, 1, 1, "Diagnosis 4"], headers ),

                RowItemModel( [-21, -7, 0, 1, "Diagnosis 1 (Admit)"], headers ),
                RowItemModel( [-25, -7, 1, 1, "Diagnosis 2 (Admit)"], headers ),

                RowItemModel( [-30, -6, 1, 1, "Troponin (High)"], headers ),
                RowItemModel( [-31, -6, 1, 1, "BNP (High)"], headers ),
                RowItemModel( [-32, -6, 1, 1, "Creatinine (High)"], headers ),
                RowItemModel( [-33, -6, 1, 1, "ESR (High)"], headers ), # Default exclude from recommendations

                RowItemModel( [-41, -8, 1, 1, "Male"], headers ),
                RowItemModel( [-42, -8, 1, 1, "Female"], headers ),
                RowItemModel( [-43, -8, 1, 1, "Birth"], headers ),
                RowItemModel( [-44, -8, 1, 1, "Birth1980s"], headers ),
                RowItemModel( [-45, -8, 1, 1, "Birth1970s"], headers ),
                RowItemModel( [-46, -8, 1, 1, "RaceWhite"], headers ),
                RowItemModel( [-47, -8, 1, 1, "RaceBlack"], headers ),
                RowItemModel( [-49, -8, 1, 1, "Death"], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel)

        headers = [
            "patient_item_id", "patient_id", "clinical_item_id", "item_date",
            "analyze_date"
        ]
        dataModels = \
            [
                RowItemModel( [-101,-11111, -43, datetime(1972, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-102,-11111, -45, datetime(1972, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-103,-11111, -41, datetime(1972, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-104,-11111, -46, datetime(1972, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-52, -11111, -23, datetime(1999, 9, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-51, -11111, -21, datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-1,  -11111, -4,  datetime(2000, 1, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-2,  -11111, -10, datetime(2000, 1, 1, 1), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-3,  -11111, -8,  datetime(2000, 1, 1, 2), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-4,  -11111, -4,  datetime(2000, 1, 1, 3), datetime(2010, 1, 1, 0)], headers ),  # Repeat item

                RowItemModel( [-60, -11111, -32, datetime(2000, 1, 1, 4), datetime(2010, 1, 1, 0)], headers ),  # Within query time
                RowItemModel( [-61, -11111, -30, datetime(2000, 1, 4, 0), datetime(2010, 1, 1, 0)], headers ),  # Within 1 week
                RowItemModel( [-63, -11111, -13, datetime(2000, 1, 4, 5), datetime(2010, 1, 1, 0)], headers ),  # Exclude item
                RowItemModel( [-64, -11111, -24, datetime(2000, 1, 4,10), datetime(2010, 1, 1, 0)], headers ),  # Exclude category
                RowItemModel( [-62, -11111, -31, datetime(2000, 1,10, 0), datetime(2010, 1, 1, 0)], headers ),  # Beyond 1 week

                RowItemModel( [-71,  -11111, -8,  datetime(2000, 1, 4, 1), datetime(2010, 1, 1, 0)], headers ), # Repeat query item within 1 week verify period, don't use as a verify item

                RowItemModel( [-201, -11111,-49,  datetime(2009, 1, 1, 1), datetime(2010, 1, 1, 0)], headers ), # Death date in far future

                RowItemModel( [-5,  -11111, -12, datetime(2000, 2, 1, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-121,-22222, -43, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-122,-22222, -44, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-123,-22222, -42, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-124,-22222, -47, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-10, -22222, -7,  datetime(2000, 1, 5, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-12, -22222, -6,  datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-13, -22222, -11, datetime(2000, 1, 9, 0), datetime(2010, 1, 1, 0)], headers ),


                RowItemModel( [-131,-33333, -43, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-132,-33333, -44, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-133,-33333, -42, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-134,-33333, -46, datetime(1983, 5, 1, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-14, -33333, -6,  datetime(2000, 2, 9, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-15, -33333, -2,  datetime(2000, 2,11, 0), datetime(2010, 1, 1, 0)], headers ),


                RowItemModel( [-141,-44444, -43, datetime(1975, 3, 3, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-142,-44444, -45, datetime(1975, 3, 3, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-143,-44444, -42, datetime(1975, 3, 3, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-144,-44444, -46, datetime(1975, 3, 3, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-20, -44444, -21, datetime(2000, 1, 5, 0), datetime(2010, 1, 1, 0)], headers ),  # Admit diagnosis
                RowItemModel( [-22, -44444, -6,  datetime(2000, 1, 5, 0), datetime(2010, 1, 1, 0)], headers ),  # Items recorded with date level precision, not time
                RowItemModel( [-23, -44444, -12, datetime(2000, 1, 5, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-24, -44444, -11, datetime(2000, 1, 6, 0), datetime(2010, 1, 1, 0)], headers ),
                RowItemModel( [-25, -44444, -8,  datetime(2000, 1, 6, 0), datetime(2010, 1, 1, 0)], headers ),

                RowItemModel( [-204,-44444,-49,  datetime(2000, 2, 1, 1), datetime(2010, 1, 1, 0)], headers ), # Death date within 1 month


                # Order Set Usage example
                RowItemModel( [-5002,-55555, -3,  datetime(2000,10, 1, 0, 0), datetime(2010, 1, 1, 0)], headers ), # Very old item, not relevant to current query
                RowItemModel( [-5040,-55555, -25, datetime(2000,10,10, 0, 0), datetime(2010, 1, 1, 0)], headers ), # Admit diagnosis (coded at date level precision before time-level order data)
                RowItemModel( [-5005,-55555, -2,  datetime(2000,10,10,10, 0), datetime(2010, 1, 1, 0)], headers ), # Non-order set item before
                RowItemModel( [-5010,-55555, -1,  datetime(2000,10,10,10, 5), datetime(2010, 1, 1, 0)], headers ), # Order Set 1
                RowItemModel( [-5020,-55555, -9,  datetime(2000,10,10,10, 5), datetime(2010, 1, 1, 0)], headers ), # Order Set 1
                RowItemModel( [-5030,-55555, -5,  datetime(2000,10,10,10,10), datetime(2010, 1, 1, 0)], headers ), # Ad-hoc within 1 hour
                RowItemModel( [-5050,-55555, -8,  datetime(2000,10,10,10,30), datetime(2010, 1, 1, 0)], headers ), # Order Set 2
                RowItemModel( [-5060,-55555, -11, datetime(2000,10,10,10,30), datetime(2010, 1, 1, 0)], headers ), # Order Set 2
                RowItemModel( [-5070,-55555, -12, datetime(2000,10,10,10,30), datetime(2010, 1, 1, 0)], headers ), # Ad-hoc Within 1 hour
                RowItemModel( [-5080,-55555, -10, datetime(2000,10,10,20, 0), datetime(2010, 1, 1, 0)], headers ), # Ad-hoc 10 hours later
                RowItemModel( [-5090,-55555, -1,  datetime(2000,10,10,20, 0), datetime(2010, 1, 1, 0)], headers ), # Order Set 1 again (ignore repeats)
                RowItemModel( [-5100,-55555, -2,  datetime(2000,10,10,20, 0), datetime(2010, 1, 1, 0)], headers ), # Order Set 1 again
                RowItemModel( [-5110,-55555, -3,  datetime(2000,10,10,20, 0), datetime(2010, 1, 1, 0)], headers ), # Ad-hoc 10 hours later
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("patient_item", dataModel)

        dataTextStr = \
"""item_collection_id;external_id;name;section;subgroup
-1;-1;Test Order Set - 1;Meds;TreatmentMeds
-2;-1;Test Order Set - 1;Meds;SymptomsMeds
-3;-1;Test Order Set - 1;Labs;GeneralLabs
-4;-2;Test Order Set - 2;Labs;GeneralLabs
-5;-2;Test Order Set - 2;Imaging;Xrays
-6;-2;Test Order Set - 2;Imaging;AdvancedImaging
-7;-3;Test Order Set - 3;Imaging;GeneralImaging
-8;-3;Test Order Set - 3;Nursing;GeneralNursing
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr), "item_collection", delim=";")

        dataTextStr = \
"""item_collection_item_id;item_collection_id;clinical_item_id;collection_type_id
-1;-1;-11;4
-2;-1;-12;4
-3;-1;-13;4
-4;-2;-9;4
-5;-2;-10;4
-6;-3;-1;4
-7;-3;-2;4
-8;-3;-3;4
-100;-3;-4;4
-9;-4;-1;4
-10;-4;-2;4
-11;-4;-3;4
-101;-4;-11;4
-12;-5;-5;4
-74;-6;-6;4
-77;-6;-7;4
-13;-6;-8;4
-14;-7;-5;4
-15;-7;-6;4
-16;-7;-7;4
-17;-7;-8;4
-18;-8;-14;4
-19;-8;-15;4
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr),
                          "item_collection_item",
                          delim=";")

        dataTextStr = \
"""patient_item_collection_link_id;patient_item_id;item_collection_item_id
-1;-5010;-6
-2;-5020;-4
-3;-5050;-13
-4;-5060;-101
-5;-5090;-6
-6;-5100;-7
"""     # Parse into DB insertion object
        DBUtil.insertFile(StringIO(dataTextStr),
                          "patient_item_collection_link",
                          delim=";")

        # Instance to test on
        self.analyzer = PreparePatientItems()
예제 #16
0
    def setUp(self):
        """Prepare state for test cases"""
        DBTestCase.setUp(self);

        self.manager = SimManager();  # Instance to test on

        from stride.clinical_item.ClinicalItemDataLoader import ClinicalItemDataLoader; 
        ClinicalItemDataLoader.build_clinical_item_psql_schemata();
        self.manager.buildCPOESimSchema();

        self.testPatientId = None;

        self.purgeTestRecords();

        log.info("Populate the database with test data")

        self.clinicalItemCategoryIdStrList = list();
        headers = ["clinical_item_category_id","source_table"];
        dataModels = \
            [
                RowItemModel( [-1, "Labs"], headers ),
                RowItemModel( [-2, "Imaging"], headers ),
                RowItemModel( [-3, "Meds"], headers ),
                RowItemModel( [-4, "Nursing"], headers ),
                RowItemModel( [-5, "Problems"], headers ),
                RowItemModel( [-6, "Lab Results"], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("clinical_item_category", dataModel );
            self.clinicalItemCategoryIdStrList.append( str(dataItemId) );

        headers = ["clinical_item_id","clinical_item_category_id","name","analysis_status"];
        dataModels = \
            [
                RowItemModel( [-1, -1, "CBC",1], headers ),
                RowItemModel( [-2, -1, "BMP",1], headers ),
                RowItemModel( [-3, -1, "Hepatic Panel",1], headers ),
                RowItemModel( [-4, -1, "Cardiac Enzymes",1], headers ),
                RowItemModel( [-5, -2, "CXR",1], headers ),
                RowItemModel( [-6, -2, "RUQ Ultrasound",1], headers ),
                RowItemModel( [-7, -2, "CT Abdomen/Pelvis",1], headers ),
                RowItemModel( [-8, -2, "CT PE Thorax",1], headers ),
                RowItemModel( [-9, -3, "Acetaminophen",1], headers ),
                RowItemModel( [-10, -3, "Carvedilol",1], headers ),
                RowItemModel( [-11, -3, "Enoxaparin",1], headers ),
                RowItemModel( [-12, -3, "Warfarin",1], headers ),
                RowItemModel( [-13, -3, "Ceftriaxone",1], headers ),
                RowItemModel( [-14, -4, "Foley Catheter",1], headers ),
                RowItemModel( [-15, -4, "Vital Signs",1], headers ),
                RowItemModel( [-16, -4, "Fall Precautions",1], headers ),
            ];
        for dataModel in dataModels:
            (dataItemId, isNew) = DBUtil.findOrInsertItem("clinical_item", dataModel );


        dataTextStr = \
"""sim_user_id;name
-1;Test User
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_user", delim=";");

        dataTextStr = \
"""sim_patient_id;age_years;gender;name
-1;60;Female;Test Female Patient
-2;55;Male;Test Male Patient
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_patient", delim=";");

        dataTextStr = \
"""sim_result_id;name;description;group_string;priority
-10;Temp;Temperature (F);Flowsheet>Vitals;10
-20;Pulse;Pulse / Heart Rate (HR);Flowsheet>Vitals;20
-30;SBP;Blood Pressure, Systolic (SBP);Flowsheet>Vitals;30
-40;DBP;Blood Pressure, Diastolic (DBP);Flowsheet>Vitals;40
-50;Resp;Respirations (RR);Flowsheet>Vitals;50
-60;FiO2;Fraction Inspired Oxygen;Flowsheet>Vitals;60
-70;Urine;Urine Output (UOP);Flowsheet>Vitals;70
-11000;WBC;WBC;LAB BLOOD ORDERABLES>Hematology>Automated Blood Count;11000
-11010;HGB;HEMOGLOBIN;LAB BLOOD ORDERABLES>Hematology>Automated Blood Count;11010
-11020;HCT;HEMATOCRIT;LAB BLOOD ORDERABLES>Hematology>Automated Blood Count;11020
-11030;PLT;PLATELET COUNT;LAB BLOOD ORDERABLES>Hematology>Automated Blood Count;11030
-13010;NA;SODIUM, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13010
-13020;K;POTASSIUM, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13020
-13030;CL;CHLORIDE, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13030
-13040;CO2;CO2, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13040
-13050;BUN;UREA NITROGEN,SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13050
-13060;CR;CREATININE, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13060
-13070;GLU;GLUCOSE, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13070
-13090;CA;CALCIUM, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13090
-13110;MG;MAGNESIUM, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13110
-13120;PHOS;PHOSPHORUS, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13120
-13210;TBIL;TOTAL BILIRUBIN;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13210
-13220;DBIL;CONJUGATED BILI;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13220
-13230;IBIL;UNCONJUGATED BILIRUBIN;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13230
-13240;AST;AST (SGOT), SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13240
-13250;ALT;ALT (SGPT), SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13250
-13260;ALKP;ALK P'TASE, TOTAL, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13260
-13270;ALB;ALBUMIN, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13270
-13280;TP;PROTEIN, TOTAL, SER/PLAS;LAB BLOOD ORDERABLES>Chemistry>General Chemistry;13280
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_result", delim=";");

        # Map orders to expected results.
        # Simplify expect vital signs to result in 5 minutes. Basic chemistry labs in 10 minutes, CBC in 15 minutes
        dataTextStr = \
"""sim_order_result_map_id;clinical_item_id;sim_result_id;turnaround_time
-1;-15;-10;300
-2;-15;-20;300
-3;-15;-30;300
-4;-15;-40;300
-5;-15;-50;300
-6;-1;-11000;900
-7;-1;-11010;900
-8;-1;-11020;900
-9;-1;-11030;900
-10;-2;-13010;600
-11;-2;-13020;600
-12;-2;-13030;600
-13;-2;-13040;600
-14;-2;-13050;600
-15;-2;-13060;600
-16;-2;-13070;600
-17;-2;-13090;600
-18;-3;-13210;600
-19;-3;-13240;600
-20;-3;-13250;600
-21;-3;-13260;600
-22;-3;-13270;600
-23;-3;-13280;600
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_order_result_map", delim=";");


        dataTextStr = \
"""sim_state_id;name;description
0;Test 0; Test State 0
-1;Test 1;Test State 1
-2;Test 2;Test State 2
-3;Test 3;Test State 3
-4;Test 4;Test State 4
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_state", delim=";");

        dataTextStr = \
"""sim_state_transition_id;pre_state_id;post_state_id;clinical_item_id;time_trigger;description
-1;-1;-2;None;9000;Passive time from 1 to 2
-2;-2;-3;-11;None;Transition 2 to 3 if order for 11 (Enoxaparin)
-3;-2;-3;-12;None;Transition 2 to 3 if order for 12 (Warfarin) (don't need both anti-coagulants. One adequate to trigger transition)
-4;-2;-4;-13;None;Transition 2 to 4 if order for 13 (Ceftriaxone)
-5;-3;-1;-10;9000;Transition 3 back to 1 if order for 10 (Carvedilol) OR 9000 seconds pass
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_state_transition", delim=";");

        dataTextStr = \
"""sim_patient_state_id;sim_patient_id;sim_state_id;relative_time_start;relative_time_end
-1;-1;-1;-7200;0
-3;-1;-1;0;1800
-2;-1;-2;1800;None
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_patient_state", delim=";");

        # Order Vital Signs at time 0, then basic labs (CBC, BMP, LFTs) at 10 minutes (600 seconds)
        dataTextStr = \
"""sim_patient_order_id;sim_user_id;sim_patient_id;sim_state_id;clinical_item_id;relative_time_start;relative_time_end
-1;-1;-1;-1;-15;0;None
-2;-1;-1;-1;-1;600;None
-3;-1;-1;-1;-2;600;None
-4;-1;-1;-1;-3;600;None
-5;-1;-1;-2;-15;1800;None
-6;-1;-1;-2;-1;1800;None
-7;-1;-1;-2;-2;1800;None
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_patient_order", delim=";");

        dataTextStr = \
"""sim_state_result_id;sim_result_id;sim_state_id;num_value;num_value_noise;text_value;result_flag
-1;-10;0;98.7;0.2;;
-2;-20;0;75;3;;
-3;-30;0;130;4;;
-4;-40;0;85;2;;
-5;-50;0;12;1;;
-6;-60;0;0.21;0;;
-7;-70;0;500;100;;
-8;-11000;0;7;1;;
-9;-11010;0;13;0.5;;
-10;-11020;0;40;1;;
-11;-11030;0;300;25;;
-12;-13010;0;140;4;;
-13;-13020;0;4.5;0.4;;
-14;-13030;0;95;3;;
-15;-13040;0;24;1;;
-16;-13050;0;12;3;;
-17;-13060;0;0.7;0.2;;
-18;-13070;0;140;12;;
-19;-13090;0;9;0.4;;
-20;-13110;0;2;0.3;;
-21;-13120;0;3;0.5;;
-22;-13210;0;0.2;0.1;;
-23;-13240;0;29;5;;
-24;-13250;0;20;4;;
-25;-13260;0;85;8;;
-26;-13270;0;4;0.4;;
-27;-13280;0;6;0.5;;
-28;-10;-1;101.4;0.4;Fever;H
-29;-20;-1;115;4;Tachycardia;H
-30;-30;-1;92;5;Hypotension;L
-31;-40;-1;55;3;Hypotension;L
-32;-70;-1;50;10;Low UOP;L
-33;-11000;-1;12;1;Leukocytosis;H
-34;-13060;-1;2.4;0.3;AKI;H
-35;-20;-2;105;4;Tachycardia;H
-36;-11000;-2;10;1;;
-37;-13060;-2;1.9;0.3;AKI;H
-38;-13070;-2;250;13;;H
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_state_result", delim=";");

        dataTextStr = \
"""sim_note_id;sim_state_id;relative_state_time;content
-1;-1;7200;Initial Note
-2;-2;0;Later Note
"""     # Parse into DB insertion object
        DBUtil.insertFile( StringIO(dataTextStr), "sim_note", delim=";");
예제 #17
0
    def test_analyzePatientItems(self):
        # Run the association analysis against the mock test data above and verify
        #   expected stats afterwards.

        associationQuery = \
            """
            select
                clinical_item_id, subsequent_item_id,
                patient_count_0, patient_count_3600, patient_count_86400, patient_count_604800,
                patient_count_2592000, patient_count_7776000, patient_count_31536000,
                patient_count_any,
                patient_time_diff_sum, patient_time_diff_sum_squares
            from
                clinical_item_association
            where
                clinical_item_id < 0
            order by
                clinical_item_id, subsequent_item_id
            """

        log.debug("Use incremental update, including date filters to start.")
        analysisOptions = AnalysisOptions()
        analysisOptions.patientIds = [-22222, -33333]
        analysisOptions.startDate = datetime(2000, 1, 9)
        analysisOptions.endDate = datetime(2000, 2, 11)
        self.analyzer.analyzePatientItems(analysisOptions)

        expectedAssociationStats = \
            [
                [-11,-11,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [-11, -6,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -6,-11,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -6, -6,   2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],
            ]

        associationStats = DBUtil.execute(associationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        log.debug(
            "Use incremental update, only doing the update based on a part of the data."
        )
        analysisOptions = AnalysisOptions()
        analysisOptions.patientIds = [-22222, -33333]
        self.analyzer.analyzePatientItems(analysisOptions)

        expectedAssociationStats = \
            [
                [-11,-11,   2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],
                [-11, -7,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [-11, -6,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -7,-11,   0, 0, 0, 1, 1, 1, 1, 1,  345600.0, 119439360000.0],
                [ -7, -7,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -7, -6,   0, 0, 0, 1, 1, 1, 1, 1,  345600.0, 119439360000.0],

                [ -6,-11,   1, 1, 1, 2, 2, 2, 2, 2, 172800.0, 29859840000.0],
                [ -6, -7,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -6, -6,   2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],
            ]

        associationStats = DBUtil.execute(associationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        log.debug(
            "Expand incremental update, by now including additional clinical items whose analysis status previously excluded them."
        )
        DBUtil.updateRow("clinical_item", {"analysis_status": 1}, -2)
        analysisOptions.patientIds = [-22222, -33333]
        self.analyzer.analyzePatientItems(analysisOptions)

        expectedAssociationStats = \
            [
                [-11,-11,   2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],
                [-11, -7,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [-11, -6,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [-11, -2,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -7,-11,   0, 0, 0, 1, 1, 1, 1, 1,  345600.0, 119439360000.0],
                [ -7, -7,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -7, -6,   0, 0, 0, 1, 1, 1, 1, 1,  345600.0, 119439360000.0],

                [ -6,-11,   1, 1, 1, 2, 2, 2, 2, 2, 172800.0, 29859840000.0],
                [ -6, -7,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -6, -6,   2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],

                [ -2,-11,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -2, -2,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
            ]

        associationStats = DBUtil.execute(associationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        log.debug(
            "Incremental update that includes a single patient data being split, so have to account for all of those dependencies"
        )

        headers = [
            "patient_item_id", "encounter_id", "patient_id",
            "clinical_item_id", "item_date"
        ]
        dataModels = \
            [
                RowItemModel( [-1111, -334, -33333, -3,  datetime(2000, 2,11, 8)], headers ),
            ]
        for dataModel in dataModels:
            (dataItemId,
             isNew) = DBUtil.findOrInsertItem("patient_item", dataModel)

        analysisOptions.patientIds = [-22222, -33333]
        self.analyzer.analyzePatientItems(analysisOptions)

        expectedAssociationStats = \
            [
                [-11,-11,   2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],
                [-11, -7,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [-11, -6,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [-11, -3,   0, 0, 1, 1, 1, 1, 1, 1,  28800.0, 829440000.0],
                [-11, -2,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -7,-11,   0, 0, 0, 1, 1, 1, 1, 1,  345600.0, 119439360000.0],
                [ -7, -7,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -7, -6,   0, 0, 0, 1, 1, 1, 1, 1,  345600.0, 119439360000.0],

                [ -6,-11,   1, 1, 1, 2, 2, 2, 2, 2,  172800.0, 29859840000.0],
                [ -6, -7,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -6, -6,   2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],
                [ -6, -3,   0, 0, 0, 1, 1, 1, 1, 1,  201600.0, 40642560000.0],

                [ -3,-11,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -3, -6,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -3, -3,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -3, -2,   0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],

                [ -2,-11,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -2, -3,   0, 0, 1, 1, 1, 1, 1, 1,  28800.0, 829440000.0],
                [ -2, -2,   1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
            ]
        associationStats = DBUtil.execute(associationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        log.debug(
            "Negative test case, repeating analysis should not change any results"
        )
        analysisOptions.patientIds = [-22222, -33333]
        self.analyzer.analyzePatientItems(analysisOptions)
        associationStats = DBUtil.execute(associationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        log.debug("Complete the remaining incremental update")
        analysisOptions.patientIds = [-11111, -22222, -33333]
        self.analyzer.analyzePatientItems(analysisOptions)

        expectedAssociationStats = \
            [   # Note that sum-squares in particular gets rounded off due to large values
                [-12, -12, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [-12, -10, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [-12,  -8, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [-12,  -4, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [-11, -11, 2, 2, 2, 2, 2, 2, 2, 2,  0.0, 0.0],
                [-11,  -7, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [-11,  -6, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [-11,  -3, 0, 0, 1, 1, 1, 1, 1, 1,  28800.0, 829440000.0],
                [-11,  -2, 1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [-10, -12, 0, 0, 0, 0, 0, 1, 1, 1, 2678400.0, 7173830000000.0],    # Longer time diff?
                [-10, -10, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [-10,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                [-10,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [ -8, -12, 0, 0, 0, 0, 0, 1, 1, 1, 2671200.0, 7135310000000.0],     # Longer diff
                [ -8, -10, 0, 0, 1, 1, 1, 1, 1, 1, 79200.0, 6272640000.0],
                [ -8,  -8, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [ -8,  -4, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -7, -11, 0, 0, 0, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                [ -7,  -7, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [ -7,  -6, 0, 0, 0, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                [ -6, -11, 1, 1, 1, 2, 2, 2, 2, 2, 172800.0, 29859840000.0],
                [ -6,  -7, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -6,  -6, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],
                [ -6,  -3, 0, 0, 0, 1, 1, 1, 1, 1, 201600.0, 40642600000.0],
                [ -4, -12, 0, 0, 0, 0, 0, 1, 1, 1, 2678400.0, 7173830000000.0], # ???
                [ -4, -10, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [ -4,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                [ -4,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [ -3, -11, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -3,  -6, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -3,  -3, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                [ -3,  -2, 0, 0, 0, 0, 0, 0, 0, 0,  0.0, 0.0],
                [ -2, -11, 1, 1, 1, 1, 1, 1, 1, 1,  0.0, 0.0],
                [ -2,  -3, 0, 0, 1, 1, 1, 1, 1, 1, 28800.0, 829440000.0],
                [ -2,  -2, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0]
            ]

        associationStats = DBUtil.execute(associationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        # Check the association stats for non-unique counts as well (allowing for repeats)
        nonUniqueAssociationQuery = \
            """
            select
                clinical_item_id, subsequent_item_id,
                count_0, count_3600, count_86400, count_604800,
                count_2592000, count_7776000, count_31536000, count_126144000,
                count_any,
                time_diff_sum, time_diff_sum_squares
            from
                clinical_item_association
            where
                clinical_item_id < 0
            order by
                clinical_item_id, subsequent_item_id
            """
        expectedAssociationStats = \
            [   # Note that sum-squares in particular gets rounded off due to large values
                 [-12, -12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-12, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-12,  -8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-12,  -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-11, -11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],
                 [-11,  -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-11,  -6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-11,  -3, 0, 0, 1, 1, 1, 1, 1, 1, 1, 28800.0, 829440000.0],
                 [-11,  -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-10, -12, 0, 0, 0, 0, 1, 2, 2, 2, 2, 5270400.0, 13892300000000.0],
                 [-10, -10, 2, 2, 3, 3, 3, 3, 3, 3, 3, 86400.0, 7464960000.0],
                 [-10,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                 [-10,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -8, -12, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2671200.0, 7135310000000.0],
                 [ -8, -10, 0, 0, 1, 1, 1, 1, 1, 1, 1, 79200.0, 6272640000.0],
                 [ -8,  -8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -8,  -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -7, -11, 0, 0, 0, 1, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                 [ -7,  -7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -7,  -6, 0, 0, 0, 1, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                 [ -6, -11, 1, 1, 1, 2, 2, 2, 2, 2, 2, 172800.0, 29859800000.0],
                 [ -6,  -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -6,  -6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],
                 [ -6,  -3, 0, 0, 0, 1, 1, 1, 1, 1, 1, 201600.0, 40642600000.0],
                 [ -4, -12, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2678400.0, 7173830000000.0],
                 [ -4, -10, 1, 1, 2, 2, 2, 2, 2, 2, 2, 86400.0, 7464960000.0],
                 [ -4,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                 [ -4,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -3, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -3,  -6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -3,  -3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -3,  -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -2, -11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -2,  -3, 0, 0, 1, 1, 1, 1, 1, 1, 1, 28800.0, 829440000.0],
                 [ -2,  -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
            ]
        associationStats = DBUtil.execute(nonUniqueAssociationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        # Again for patient level counts
        patientAssociationQuery = \
            """
            select
                clinical_item_id, subsequent_item_id,
                patient_count_0, patient_count_3600, patient_count_86400, patient_count_604800,
                patient_count_2592000, patient_count_7776000, patient_count_31536000, patient_count_126144000,
                patient_count_any,
                patient_time_diff_sum, patient_time_diff_sum_squares
            from
                clinical_item_association
            where
                clinical_item_id < 0
            order by
                clinical_item_id, subsequent_item_id
            """
        expectedAssociationStats = \
            [   # Note that sum-squares in particular gets rounded off due to large values
                 [-12, -12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-12, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-12,  -8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-12,  -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-11, -11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],
                 [-11,  -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-11,  -6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-11,  -3, 0, 0, 1, 1, 1, 1, 1, 1, 1, 28800.0, 829440000.0],
                 [-11,  -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-10, -12, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2678400.0, 2678400.0*2678400.0],    # Main difference.  Duplicates within a single patient, only count once
                 [-10, -10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],   # Don't count duplicates
                 [-10,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                 [-10,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -8, -12, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2671200.0, 7135310000000.0],
                 [ -8, -10, 0, 0, 1, 1, 1, 1, 1, 1, 1, 79200.0, 6272640000.0],
                 [ -8,  -8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -8,  -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -7, -11, 0, 0, 0, 1, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                 [ -7,  -7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -7,  -6, 0, 0, 0, 1, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                 [ -6, -11, 1, 1, 1, 2, 2, 2, 2, 2, 2, 172800.0, 29859800000.0],
                 [ -6,  -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -6,  -6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],
                 [ -6,  -3, 0, 0, 0, 1, 1, 1, 1, 1, 1, 201600.0, 40642600000.0],
                 [ -4, -12, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2678400.0, 7173830000000.0],
                 [ -4, -10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],  # Don't count repeats
                 [ -4,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                 [ -4,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -3, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -3,  -6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -3,  -3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -3,  -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -2, -11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -2,  -3, 0, 0, 1, 1, 1, 1, 1, 1, 1, 28800.0, 829440000.0],
                 [ -2,  -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
            ]
        associationStats = DBUtil.execute(patientAssociationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)

        # Again for encounter level counts
        encounterAssociationQuery = \
            """
            select
                clinical_item_id, subsequent_item_id,
                encounter_count_0, encounter_count_3600, encounter_count_86400, encounter_count_604800,
                encounter_count_2592000, encounter_count_7776000, encounter_count_31536000, encounter_count_126144000,
                encounter_count_any,
                encounter_time_diff_sum, encounter_time_diff_sum_squares
            from
                clinical_item_association
            where
                clinical_item_id < 0
            order by
                clinical_item_id, subsequent_item_id
            """
        expectedAssociationStats = \
            [   # Note that sum-squares in particular gets rounded off due to large values
                 [-12, -12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-12, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-12,  -8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-12,  -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-11, -11, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],
                 [-11,  -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [-11,  -6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-11,  -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],   # No longer related in separate encounters
                 [-11,  -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [-10, -12, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2592000.0, 2592000.0*2592000.0],    # Only count the relation within a common encounter
                 [-10, -10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],   # Now count for separate encounters
                 [-10,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                 [-10,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -8, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0], # No longer related in separate encounters
                 [ -8, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],  # No longer related in separate encounters
                 [ -8,  -8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -8,  -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -7, -11, 0, 0, 0, 1, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                 [ -7,  -7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -7,  -6, 0, 0, 0, 1, 1, 1, 1, 1, 1, 345600.0, 119439000000.0],
                 [ -6, -11, 1, 1, 1, 2, 2, 2, 2, 2, 2, 172800.0, 29859800000.0],
                 [ -6,  -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -6,  -6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0.0, 0.0],
                 [ -6,  -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],   # No longer related in separate encounters
                 [ -4, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0], # No longer related in separate encounters
                 [ -4, -10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -4,  -8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 7200.0, 51840000.0],
                 [ -4,  -4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -3, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -3,  -6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -3,  -3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -3,  -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],
                 [ -2, -11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
                 [ -2,  -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0],   # No longer related in separate encounters
                 [ -2,  -2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0, 0.0],
            ]
        associationStats = DBUtil.execute(encounterAssociationQuery)
        self.assertEqualTable(expectedAssociationStats,
                              associationStats,
                              precision=3)