1178 lines
49 KiB
Plaintext
1178 lines
49 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9de5907f-18f5-4cb1-903e-26028ff1fa03",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"pd.set_option('display.max_rows', 100)\n",
|
|
"pd.set_option('display.max_columns', None)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a271254b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"class VaersDescrReader:\n",
|
|
" \n",
|
|
" def __init__(self, dataDir):\n",
|
|
" self.dataDir = dataDir \n",
|
|
"\n",
|
|
" def readAllVaersDescrs(self):\n",
|
|
" return self.readVaersDescrs([\"2021\", \"2022\"])\n",
|
|
" \n",
|
|
" def readVaersDescrs(self, years):\n",
|
|
" return [self.readVaersDescr(year) for year in years]\n",
|
|
"\n",
|
|
" def readVaersDescr(self, year):\n",
|
|
" folder = self.dataDir + \"/\" + year + \"VAERSData/\"\n",
|
|
" return {\n",
|
|
" 'VAERSDATA': self._readVAERSDATA(folder + year + \"VAERSDATA.csv\"),\n",
|
|
" 'VAERSVAX': self._readVAERSVAX(folder + year + \"VAERSVAX.csv\")\n",
|
|
" }\n",
|
|
"\n",
|
|
" def readNonDomesticVaersDescr(self):\n",
|
|
" folder = self.dataDir + \"/NonDomesticVAERSData/\"\n",
|
|
" return {\n",
|
|
" 'VAERSDATA': self._readVAERSDATA(folder + \"NonDomesticVAERSDATA.csv\"),\n",
|
|
" 'VAERSVAX': self._readVAERSVAX(folder + \"NonDomesticVAERSVAX.csv\")\n",
|
|
" }\n",
|
|
"\n",
|
|
" def _readVAERSDATA(self, file):\n",
|
|
" return self._read_csv(\n",
|
|
" file = file,\n",
|
|
" usecols = ['VAERS_ID', 'RECVDATE', 'DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT', 'SPLTTYPE'],\n",
|
|
" parse_dates = ['RECVDATE'],\n",
|
|
" date_parser = lambda dateStr: pd.to_datetime(dateStr, format = \"%m/%d/%Y\"))\n",
|
|
"\n",
|
|
" def _readVAERSVAX(self, file):\n",
|
|
" return self._read_csv(\n",
|
|
" file = file,\n",
|
|
" usecols = ['VAERS_ID', 'VAX_DOSE_SERIES', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT'],\n",
|
|
" dtype = {\"VAX_DOSE_SERIES\": \"string\"})\n",
|
|
"\n",
|
|
" def _read_csv(self, file, **kwargs):\n",
|
|
" return pd.read_csv(\n",
|
|
" file,\n",
|
|
" index_col = 'VAERS_ID',\n",
|
|
" encoding = 'latin1',\n",
|
|
" low_memory = False,\n",
|
|
" **kwargs)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7b5d6df0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"class VaersDescr2DataFrameConverter:\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def createDataFrameFromDescr(vaersDescr):\n",
|
|
" return pd.merge(\n",
|
|
" vaersDescr['VAERSDATA'],\n",
|
|
" vaersDescr['VAERSVAX'],\n",
|
|
" how = 'left',\n",
|
|
" left_index = True,\n",
|
|
" right_index = True,\n",
|
|
" validate = 'one_to_many')\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def createDataFrameFromDescrs(vaersDescrs):\n",
|
|
" dataFrames = [VaersDescr2DataFrameConverter.createDataFrameFromDescr(vaersDescr) for vaersDescr in vaersDescrs]\n",
|
|
" return pd.concat(dataFrames)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6b639196",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class DataFrameNormalizer:\n",
|
|
" \n",
|
|
" @staticmethod\n",
|
|
" def normalize(dataFrame):\n",
|
|
" DataFrameNormalizer.convertVAX_LOTColumnToUpperCase(dataFrame)\n",
|
|
" DataFrameNormalizer._convertColumnsOfDataFrame_Y_to_1_else_0(\n",
|
|
" dataFrame,\n",
|
|
" ['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT'])\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def convertVAX_LOTColumnToUpperCase(dataFrame):\n",
|
|
" dataFrame['VAX_LOT'] = dataFrame['VAX_LOT'].str.upper()\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _convertColumnsOfDataFrame_Y_to_1_else_0(dataFrame, columns):\n",
|
|
" for column in columns:\n",
|
|
" DataFrameNormalizer._convertColumnOfDataFrame_Y_to_1_else_0(dataFrame, column)\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _convertColumnOfDataFrame_Y_to_1_else_0(dataFrame, column):\n",
|
|
" dataFrame[column] = DataFrameNormalizer._where(\n",
|
|
" condition = dataFrame[column] == 'Y',\n",
|
|
" trueValue = 1,\n",
|
|
" falseValue = 0)\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _where(condition, trueValue, falseValue):\n",
|
|
" return np.where(condition, trueValue, falseValue) \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "3ebcba86",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"class DataFrameFilter:\n",
|
|
" \n",
|
|
" def filterByCovid19(self, dataFrame):\n",
|
|
" return dataFrame[self._isCovid19(dataFrame)]\n",
|
|
"\n",
|
|
" def filterByCountry(self, dataFrame, country, countryColumnName):\n",
|
|
" return dataFrame[dataFrame[countryColumnName] == country]\n",
|
|
"\n",
|
|
" def filterBy(self, dataFrame, manufacturer = None, dose = None):\n",
|
|
" return dataFrame[self._isManufacturer(dataFrame, manufacturer) & self._isDose(dataFrame, dose)]\n",
|
|
"\n",
|
|
" def _isCovid19(self, dataFrame):\n",
|
|
" return dataFrame[\"VAX_TYPE\"] == \"COVID19\"\n",
|
|
"\n",
|
|
" def _isManufacturer(self, dataFrame, manufacturer):\n",
|
|
" return dataFrame[\"VAX_MANU\"] == manufacturer if manufacturer is not None else True\n",
|
|
"\n",
|
|
" def _isDose(self, dataFrame, dose):\n",
|
|
" return dataFrame[\"VAX_DOSE_SERIES\"].str.contains(dose) if dose is not None else True\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c62cfaff",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class SummationTableFactory:\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def createSummationTable(\n",
|
|
" groupBy,\n",
|
|
" # FK-TODO: rename \"ADRs\" and \"Total reports\" to \"Total Number of Adverse Reaction Reports\" in all places\n",
|
|
" columnNameMappingsDict = {\n",
|
|
" \"DIED_size\": \"ADRs\",\n",
|
|
" \"DIED_sum\": \"DEATHS\",\n",
|
|
" \"L_THREAT_sum\": \"LIFE THREATENING ILLNESSES\",\n",
|
|
" \"DISABLE_sum\": \"DISABILITIES\",\n",
|
|
" 'HOSPITAL_sum': 'HOSPITALISATIONS',\n",
|
|
" 'ER_VISIT_sum': 'EMERGENCY ROOM OR DOCTOR VISITS'\n",
|
|
" }):\n",
|
|
"\n",
|
|
" summationTable = groupBy.agg({\n",
|
|
" 'DIED': ['sum', 'size'],\n",
|
|
" 'L_THREAT': 'sum',\n",
|
|
" 'DISABLE': 'sum',\n",
|
|
" 'HOSPITAL': 'sum',\n",
|
|
" 'ER_VISIT': 'sum'\n",
|
|
" })\n",
|
|
" SummationTableFactory._flattenColumns(summationTable)\n",
|
|
" return summationTable.rename(columns = columnNameMappingsDict)\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _flattenColumns(dataFrame):\n",
|
|
" dataFrame.columns = [\"_\".join(a) for a in dataFrame.columns.to_flat_index()]\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "99945ca8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"class BatchCodeTableFactory:\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def createBatchCodeTable(dataFrame : pd.DataFrame, manufacturer, dose):\n",
|
|
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
|
" dataFrame = DataFrameFilter().filterBy(dataFrame, manufacturer = manufacturer, dose = dose)\n",
|
|
" return BatchCodeTableFactory._createSummationTableByVAX_LOT(dataFrame)[['ADRs', 'DEATHS', 'DISABILITIES', 'LIFE THREATENING ILLNESSES']]\n",
|
|
"\n",
|
|
" # create table from https://www.howbadismybatch.com/combined.html\n",
|
|
" @staticmethod\n",
|
|
" def createSevereEffectsBatchCodeTable(dataFrame : pd.DataFrame, dose):\n",
|
|
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
|
" dataFrame = DataFrameFilter().filterBy(dataFrame, dose = dose)\n",
|
|
" return BatchCodeTableFactory._createSummationTableByVAX_LOT(dataFrame)\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _createSummationTableByVAX_LOT(dataFrame):\n",
|
|
" batchCodeTable = SummationTableFactory.createSummationTable(dataFrame.groupby('VAX_LOT'))\n",
|
|
" batchCodeTable = batchCodeTable[['ADRs', 'DEATHS', 'DISABILITIES', 'LIFE THREATENING ILLNESSES', 'HOSPITALISATIONS', 'EMERGENCY ROOM OR DOCTOR VISITS']]\n",
|
|
" batchCodeTable = batchCodeTable.sort_values(by = 'ADRs', ascending = False)\n",
|
|
" return BatchCodeTableFactory._addCompanyColumn(batchCodeTable, BatchCodeTableFactory._createCompanyByBatchCodeTable(dataFrame))\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _addCompanyColumn(batchCodeTable, companyByBatchCodeTable):\n",
|
|
" return pd.merge(\n",
|
|
" batchCodeTable,\n",
|
|
" companyByBatchCodeTable,\n",
|
|
" how = 'left',\n",
|
|
" left_index = True,\n",
|
|
" right_index = True,\n",
|
|
" validate = 'one_to_one')\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _createCompanyByBatchCodeTable(dataFrame):\n",
|
|
" return BatchCodeTableFactory._createManufacturerByBatchCodeTable(dataFrame).rename(columns = {\"VAX_MANU\": \"COMPANY\"})\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _createManufacturerByBatchCodeTable(dataFrame):\n",
|
|
" manufacturerByBatchCodeTable = dataFrame[['VAX_LOT', 'VAX_MANU']]\n",
|
|
" manufacturerByBatchCodeTable = manufacturerByBatchCodeTable.drop_duplicates(subset = ['VAX_LOT'])\n",
|
|
" return manufacturerByBatchCodeTable.set_index('VAX_LOT')\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "41d4fa30",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class DoseTableFactory:\n",
|
|
" \n",
|
|
" @staticmethod\n",
|
|
" def createDoseTable(dataFrame):\n",
|
|
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
|
" return DoseTableFactory._createDoseTable(\n",
|
|
" dataFrame.groupby(\n",
|
|
" dataFrame['VAX_DOSE_SERIES'].rename('Dose')))\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def createDoseByMonthTable(dataFrame):\n",
|
|
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
|
" return DoseTableFactory._createDoseTable(\n",
|
|
" dataFrame.groupby(\n",
|
|
" [\n",
|
|
" dataFrame['RECVDATE'].dt.year.rename('Year'),\n",
|
|
" dataFrame['RECVDATE'].dt.month.rename('Month'),\n",
|
|
" dataFrame['VAX_DOSE_SERIES'].rename('Dose')\n",
|
|
" ]))\n",
|
|
"\n",
|
|
" # FK-TODO: rename _createDoseTable()\n",
|
|
" @staticmethod\n",
|
|
" def _createDoseTable(dataFrame):\n",
|
|
" doseTable = SummationTableFactory.createSummationTable(\n",
|
|
" dataFrame,\n",
|
|
" columnNameMappingsDict = {\n",
|
|
" \"DIED_size\": \"Total reports\",\n",
|
|
" \"DIED_sum\": \"Deaths\",\n",
|
|
" \"L_THREAT_sum\": \"Life Threatening Illnesses\",\n",
|
|
" \"DISABLE_sum\": \"Disabilities\"\n",
|
|
" })\n",
|
|
" doseTable = doseTable[['Total reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses']]\n",
|
|
" doseTable['Severe reports (%)'] = (doseTable['Deaths'] + doseTable['Disabilities'] + doseTable['Life Threatening Illnesses']) / doseTable['Total reports'] * 100\n",
|
|
" return doseTable\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c40bd0f0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pycountry\n",
|
|
"\n",
|
|
"class CountryColumnAdder:\n",
|
|
" \n",
|
|
" @staticmethod\n",
|
|
" def addCountryColumn(dataFrame, countryColumnName):\n",
|
|
" dataFrame[countryColumnName] = dataFrame.apply(\n",
|
|
" lambda row:\n",
|
|
" CountryColumnAdder._getCountryNameOfSplttypeOrDefault(\n",
|
|
" splttype = row['SPLTTYPE'],\n",
|
|
" default = 'Unknown Country'),\n",
|
|
" axis = 'columns')\n",
|
|
" return dataFrame.astype({countryColumnName: \"string\"})\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _getCountryNameOfSplttypeOrDefault(splttype, default):\n",
|
|
" if not isinstance(splttype, str):\n",
|
|
" return default\n",
|
|
" \n",
|
|
" country = pycountry.countries.get(alpha_2 = splttype[:2])\n",
|
|
" return country.name if country is not None else default"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "09e6b511",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class InternationalLotTableFactory:\n",
|
|
" \n",
|
|
" @staticmethod\n",
|
|
" def createInternationalLotTable(dataFrame):\n",
|
|
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
|
" internationalLotTable = InternationalLotTableFactory._createInternationalLotTable(dataFrame)\n",
|
|
" return internationalLotTable.sort_values(by = 'Severe reports (%)', ascending = False)\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def createBatchCodeTableByCountry(dataFrame : pd.DataFrame, country):\n",
|
|
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
|
" batchCodeTable = InternationalLotTableFactory._createBatchCodeTableByCountry(dataFrame, country)\n",
|
|
" return batchCodeTable.sort_values(by = 'Severe reports (%)', ascending = False)\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _createInternationalLotTable(dataFrame):\n",
|
|
" countryColumnName = 'Country'\n",
|
|
" dataFrame = CountryColumnAdder.addCountryColumn(dataFrame, countryColumnName = countryColumnName)\n",
|
|
" return DoseTableFactory._createDoseTable(dataFrame.groupby(dataFrame[countryColumnName]))\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def _createBatchCodeTableByCountry(dataFrame : pd.DataFrame, country):\n",
|
|
" countryColumnName = 'Country'\n",
|
|
" dataFrame = CountryColumnAdder.addCountryColumn(dataFrame, countryColumnName = countryColumnName)\n",
|
|
" dataFrame = DataFrameFilter().filterByCountry(dataFrame, country = country, countryColumnName = countryColumnName)\n",
|
|
" return DoseTableFactory._createDoseTable(dataFrame.groupby('VAX_LOT'))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "3dacedfd",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import unittest"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "fcc855dd",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class TestHelper:\n",
|
|
"\n",
|
|
" @staticmethod\n",
|
|
" def createDataFrame(index, columns, data, dtypes = {}):\n",
|
|
" return pd.DataFrame(index = index, columns = columns, data = data).astype(dtypes)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ccb9838d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pandas.testing import assert_frame_equal\n",
|
|
"\n",
|
|
"class DataFrameNormalizerTest(unittest.TestCase):\n",
|
|
"\n",
|
|
" def test_convertVAX_LOTColumnToUpperCase(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_LOT'],\n",
|
|
" data = [ ['037K20A'],\n",
|
|
" ['025l20A'],\n",
|
|
" ['025L20A']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\",\n",
|
|
" \"1996874\"])\n",
|
|
" \n",
|
|
" # When\n",
|
|
" DataFrameNormalizer.convertVAX_LOTColumnToUpperCase(dataFrame)\n",
|
|
" \n",
|
|
" # Then\n",
|
|
" dataFrameExpected = TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_LOT'],\n",
|
|
" data = [ ['037K20A'],\n",
|
|
" ['025L20A'],\n",
|
|
" ['025L20A']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\",\n",
|
|
" \"1996874\"])\n",
|
|
" assert_frame_equal(dataFrame, dataFrameExpected, check_dtype = False)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e59a1825",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pandas.testing import assert_frame_equal\n",
|
|
"\n",
|
|
"class DataFrameFilterTest(unittest.TestCase):\n",
|
|
"\n",
|
|
" def test_filterByCovid19_filterBy(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(\n",
|
|
" [\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE'],\n",
|
|
" data = [ [1, 0, 0],\n",
|
|
" [0, 0, 1]],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['COVID19', 'MODERNA', '037K20A', '1'],\n",
|
|
" ['COVID19', 'MODERNA', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" },\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE'],\n",
|
|
" data = [ [0, 0, 0],\n",
|
|
" [0, 0, 1]],\n",
|
|
" index = [\n",
|
|
" \"1996873\",\n",
|
|
" \"1996874\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['HPV9', 'MERCK & CO. INC.', 'R017624', 'UNK'],\n",
|
|
" ['COVID19', 'MODERNA', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"1996873\",\n",
|
|
" \"1996874\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" }\n",
|
|
" ])\n",
|
|
" dataFrameFilter = DataFrameFilter()\n",
|
|
" \n",
|
|
" # When\n",
|
|
" dataFrame = dataFrameFilter.filterByCovid19(dataFrame)\n",
|
|
" dataFrame = dataFrameFilter.filterBy(dataFrame, manufacturer = \"MODERNA\", dose = '1')\n",
|
|
" \n",
|
|
" # Then\n",
|
|
" dataFrameExpected = TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ [1, 0, 0, 'COVID19', 'MODERNA', '037K20A', '1'],\n",
|
|
" [0, 0, 1, 'COVID19', 'MODERNA', '025L20A', '1'],\n",
|
|
" [0, 0, 1, 'COVID19', 'MODERNA', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\",\n",
|
|
" \"1996874\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" assert_frame_equal(dataFrame, dataFrameExpected, check_dtype = False)\n",
|
|
"\n",
|
|
" def test_filterByDose(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(\n",
|
|
" [\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [1, 1, 0, 1, 1],\n",
|
|
" [0, 0, 1, 0, 1]],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['COVID19', 'MODERNA', '037K20A', '1'],\n",
|
|
" ['COVID19', 'PFIZER\\BIONTECH', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" }\n",
|
|
" ])\n",
|
|
" dataFrameFilter = DataFrameFilter()\n",
|
|
" dataFrame = dataFrameFilter.filterByCovid19(dataFrame)\n",
|
|
"\n",
|
|
" # When\n",
|
|
" dataFrame = dataFrameFilter.filterBy(dataFrame, dose = '1')\n",
|
|
" \n",
|
|
" # Then\n",
|
|
" dataFrameExpected = TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ [1, 1, 0, 1, 1, 'COVID19', 'MODERNA', '037K20A', '1'],\n",
|
|
" [0, 0, 1, 0, 1, 'COVID19', 'PFIZER\\BIONTECH', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" assert_frame_equal(dataFrame, dataFrameExpected, check_dtype = False)\n",
|
|
"\n",
|
|
" def test_filterByFirstDose(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(\n",
|
|
" [\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE'],\n",
|
|
" data = [ [1, 0, 0]],\n",
|
|
" index = [\n",
|
|
" \"1048786\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['COVID19', 'MODERNA', '016M20A', '2'],\n",
|
|
" ['COVID19', 'MODERNA', '030L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"1048786\",\n",
|
|
" \"1048786\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" }\n",
|
|
" ])\n",
|
|
" dataFrameFilter = DataFrameFilter()\n",
|
|
" \n",
|
|
" # When\n",
|
|
" dataFrame = dataFrameFilter.filterByCovid19(dataFrame)\n",
|
|
" dataFrame = dataFrameFilter.filterBy(dataFrame, manufacturer = \"MODERNA\", dose = '1')\n",
|
|
" \n",
|
|
" # Then\n",
|
|
" dataFrameExpected = TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ [1, 0, 0, 'COVID19', 'MODERNA', '030L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"1048786\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" assert_frame_equal(dataFrame, dataFrameExpected, check_dtype = False)\n",
|
|
"\n",
|
|
" def test_filterBySecondDose(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(\n",
|
|
" [\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE'],\n",
|
|
" data = [ [1, 0, 0]],\n",
|
|
" index = [\n",
|
|
" \"1048786\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['COVID19', 'MODERNA', '016M20A', '2'],\n",
|
|
" ['COVID19', 'MODERNA', '030L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"1048786\",\n",
|
|
" \"1048786\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" }\n",
|
|
" ])\n",
|
|
" dataFrameFilter = DataFrameFilter()\n",
|
|
"\n",
|
|
" # When\n",
|
|
" dataFrame = dataFrameFilter.filterByCovid19(dataFrame)\n",
|
|
" dataFrame = dataFrameFilter.filterBy(dataFrame, manufacturer = \"MODERNA\", dose = '2')\n",
|
|
" \n",
|
|
" # Then\n",
|
|
" dataFrameExpected = TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ [1, 0, 0, 'COVID19', 'MODERNA', '016M20A', '2']],\n",
|
|
" index = [\n",
|
|
" \"1048786\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" assert_frame_equal(dataFrame, dataFrameExpected, check_dtype = False)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e14465d7",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pandas.testing import assert_frame_equal\n",
|
|
"\n",
|
|
"class BatchCodeTableFactoryTest(unittest.TestCase):\n",
|
|
"\n",
|
|
" def testcreateSummationTable(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(\n",
|
|
" [\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [1, 1, 0, 1, 1],\n",
|
|
" [0, 0, 1, 0, 1]],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['COVID19', 'MODERNA', '037K20A', '1'],\n",
|
|
" ['COVID19', 'PFIZER\\BIONTECH', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" }\n",
|
|
" ])\n",
|
|
"\n",
|
|
" # When\n",
|
|
" batchCodeTable = BatchCodeTableFactory.createSevereEffectsBatchCodeTable(dataFrame, '1')\n",
|
|
"\n",
|
|
" # Then\n",
|
|
" batchCodeTableExpected = pd.DataFrame(\n",
|
|
" data = {\n",
|
|
" 'ADRs': [1, 1],\n",
|
|
" 'DEATHS': [0, 1],\n",
|
|
" 'DISABILITIES': [1, 0],\n",
|
|
" 'LIFE THREATENING ILLNESSES': [0, 1],\n",
|
|
" 'HOSPITALISATIONS': [0, 1],\n",
|
|
" 'EMERGENCY ROOM OR DOCTOR VISITS': [1, 1],\n",
|
|
" 'COMPANY': ['PFIZER\\BIONTECH', 'MODERNA']\n",
|
|
" },\n",
|
|
" index = pd.Index(['025L20A', '037K20A'], name = 'VAX_LOT'))\n",
|
|
" assert_frame_equal(batchCodeTable, batchCodeTableExpected, check_dtype = False)\n",
|
|
"\n",
|
|
" def test_createBatchCodeTable2(self):\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(\n",
|
|
" [\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [1, 0, 0, 0, 0],\n",
|
|
" [0, 0, 1, 0, 0]],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['COVID19', 'MODERNA', '037K20A', '1'],\n",
|
|
" ['COVID19', 'MODERNA', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"0916600\",\n",
|
|
" \"0916601\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" },\n",
|
|
" {\n",
|
|
" 'VAERSDATA': TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [0, 0, 0, 0, 0],\n",
|
|
" [0, 0, 1, 0, 0]],\n",
|
|
" index = [\n",
|
|
" \"1996873\",\n",
|
|
" \"1996874\"]),\n",
|
|
" 'VAERSVAX': TestHelper.createDataFrame(\n",
|
|
" columns = ['VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES'],\n",
|
|
" data = [ ['HPV9', 'MERCK & CO. INC.', 'R017624', 'UNK'],\n",
|
|
" ['COVID19', 'MODERNA', '025L20A', '1']],\n",
|
|
" index = [\n",
|
|
" \"1996873\",\n",
|
|
" \"1996874\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" }\n",
|
|
" ])\n",
|
|
" self._test_createBatchCodeTable(dataFrame, \"MODERNA\", '1')\n",
|
|
"\n",
|
|
" def test_createBatchCodeTable(self):\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(\n",
|
|
" VaersDescrReader(dataDir = \"test/VAERS\").readAllVaersDescrs())\n",
|
|
" DataFrameNormalizer.normalize(dataFrame)\n",
|
|
" self._test_createBatchCodeTable(dataFrame, \"MODERNA\", '1')\n",
|
|
"\n",
|
|
" def _test_createBatchCodeTable(self, dataFrame, manufacturer, dose):\n",
|
|
" # When\n",
|
|
" batchCodeTable = BatchCodeTableFactory.createBatchCodeTable(dataFrame, manufacturer, dose)\n",
|
|
"\n",
|
|
" # Then\n",
|
|
" batchCodeTableExpected = pd.DataFrame(\n",
|
|
" data = {\n",
|
|
" 'ADRs': [2, 1],\n",
|
|
" 'DEATHS': [0, 1],\n",
|
|
" 'DISABILITIES': [2, 0],\n",
|
|
" 'LIFE THREATENING ILLNESSES': [0, 0]\n",
|
|
" },\n",
|
|
" index = pd.Index(['025L20A', '037K20A'], name = 'VAX_LOT'))\n",
|
|
" assert_frame_equal(batchCodeTable, batchCodeTableExpected, check_dtype = False)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "44c121ec",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pandas.testing import assert_frame_equal\n",
|
|
"\n",
|
|
"class DoseTableFactoryTest(unittest.TestCase):\n",
|
|
"\n",
|
|
" def test_createDoseTable(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [1, 0, 0, 'COVID19', 'MODERNA', '016M20A', '2', 0, 0],\n",
|
|
" [1, 0, 0, 'COVID19', 'MODERNA', '030L20A', '1', 0, 0],\n",
|
|
" [1, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 0, 0]],\n",
|
|
" index = [\n",
|
|
" \"1048786\",\n",
|
|
" \"1048786\",\n",
|
|
" \"4711\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" \n",
|
|
" # When\n",
|
|
" doseTable = DoseTableFactory.createDoseTable(dataFrame)\n",
|
|
"\n",
|
|
" # Then\n",
|
|
" assert_frame_equal(\n",
|
|
" doseTable,\n",
|
|
" pd.DataFrame(\n",
|
|
" data = {\n",
|
|
" 'Total reports': [2, 1],\n",
|
|
" 'Deaths': [2, 1],\n",
|
|
" 'Disabilities': [1, 0],\n",
|
|
" 'Life Threatening Illnesses': [1, 0],\n",
|
|
" 'Severe reports (%)': [(2 + 1 + 1)/2 * 100, (1 + 0 + 0)/1 * 100]\n",
|
|
" },\n",
|
|
" index = pd.Index(['1', '2'], dtype = \"string\", name = 'Dose')))\n",
|
|
" \n",
|
|
" def test_createDoseByMonthTable(self):\n",
|
|
" # Given\n",
|
|
" parseDate = lambda dateStr: pd.to_datetime(dateStr, format = \"%m/%d/%Y\")\n",
|
|
" dataFrame = TestHelper.createDataFrame(\n",
|
|
" columns = ['RECVDATE', 'DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [parseDate('01/01/2021'), 1, 0, 0, 'COVID19', 'MODERNA', '016M20A', '2', 0, 0],\n",
|
|
" [parseDate('01/01/2021'), 1, 0, 0, 'COVID19', 'MODERNA', '030L20A', '1', 0, 0],\n",
|
|
" [parseDate('01/01/2021'), 1, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 0, 0]],\n",
|
|
" index = [\n",
|
|
" \"1048786\",\n",
|
|
" \"1048786\",\n",
|
|
" \"4711\"],\n",
|
|
" dtypes = {'VAX_DOSE_SERIES': \"string\"})\n",
|
|
" \n",
|
|
" # When\n",
|
|
" doseByMonthTable = DoseTableFactory.createDoseByMonthTable(dataFrame)\n",
|
|
"\n",
|
|
" # Then\n",
|
|
" assert_frame_equal(\n",
|
|
" doseByMonthTable,\n",
|
|
" pd.DataFrame(\n",
|
|
" data = {\n",
|
|
" 'Total reports': [2, 1],\n",
|
|
" 'Deaths': [2, 1],\n",
|
|
" 'Disabilities': [1, 0],\n",
|
|
" 'Life Threatening Illnesses': [1, 0],\n",
|
|
" 'Severe reports (%)': [(2 + 1 + 1)/2 * 100, (1 + 0 + 0)/1 * 100]\n",
|
|
" },\n",
|
|
" index = pd.MultiIndex.from_tuples(\n",
|
|
" [\n",
|
|
" (2021, 1, '1'),\n",
|
|
" (2021, 1, '2'),\n",
|
|
" ],\n",
|
|
" names = ('Year', 'Month', 'Dose'))),\n",
|
|
" check_index_type = False)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c784bfef",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pandas.testing import assert_frame_equal\n",
|
|
"\n",
|
|
"class InternationalLotTableFactoryTest(unittest.TestCase):\n",
|
|
"\n",
|
|
" def test_createInternationalLotTable(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES', 'SPLTTYPE', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [1, 0, 0, 'COVID19', 'MODERNA', '016M20A', '2', 'GBPFIZER INC2020486806', 0, 0],\n",
|
|
" [1, 0, 0, 'COVID19', 'MODERNA', '030L20A', '1', 'FRMODERNATX, INC.MOD20224', 0, 0],\n",
|
|
" [1, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 'FRMODERNATX, INC.MOD20224', 0, 0],\n",
|
|
" [0, 0, 0, 'COVID19', 'MODERNA', '030L20B', '1', 'dummy'],\n",
|
|
" [0, 0, 0, 'COVID19', 'MODERNA', '030L20B', '1', 123]],\n",
|
|
" index = [\n",
|
|
" \"1048786\",\n",
|
|
" \"1048786\",\n",
|
|
" \"4711\",\n",
|
|
" \"0815\",\n",
|
|
" \"0816\"])\n",
|
|
" \n",
|
|
" # When\n",
|
|
" internationalLotTable = InternationalLotTableFactory.createInternationalLotTable(dataFrame)\n",
|
|
"\n",
|
|
" # Then\n",
|
|
" assert_frame_equal(\n",
|
|
" internationalLotTable,\n",
|
|
" TestHelper.createDataFrame(\n",
|
|
" columns = ['Total reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Severe reports (%)'],\n",
|
|
" data = [ [2, 2, 1, 1, (2 + 1 + 1) / 2 * 100],\n",
|
|
" [1, 1, 0, 0, (1 + 0 + 0) / 1 * 100],\n",
|
|
" [2, 0, 0, 0, (0 + 0 + 0) / 2 * 100]],\n",
|
|
" index = pd.Index(\n",
|
|
" [\n",
|
|
" 'France',\n",
|
|
" 'United Kingdom',\n",
|
|
" 'Unknown Country'\n",
|
|
" ],\n",
|
|
" dtype = \"string\",\n",
|
|
" name = 'Country')))\n",
|
|
"\n",
|
|
" def test_createBatchCodeTableByCountry(self):\n",
|
|
" # Given\n",
|
|
" dataFrame = TestHelper.createDataFrame(\n",
|
|
" columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES', 'SPLTTYPE', 'HOSPITAL', 'ER_VISIT'],\n",
|
|
" data = [ [1, 0, 0, 'COVID19', 'MODERNA', '016M20A', '2', 'GBPFIZER INC2020486806', 0, 0],\n",
|
|
" [1, 0, 0, 'COVID19', 'MODERNA', '030L20A', '1', 'FRMODERNATX, INC.MOD20224', 0, 0],\n",
|
|
" [1, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 'FRMODERNATX, INC.MOD20224', 0, 0],\n",
|
|
" [0, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 'FRMODERNATX, INC.MOD20224', 0, 0]],\n",
|
|
" index = [\n",
|
|
" \"1048786\",\n",
|
|
" \"1048786\",\n",
|
|
" \"4711\",\n",
|
|
" \"0815\"])\n",
|
|
" \n",
|
|
" # When\n",
|
|
" batchCodeTable = InternationalLotTableFactory.createBatchCodeTableByCountry(dataFrame, 'France')\n",
|
|
"\n",
|
|
" # Then\n",
|
|
" assert_frame_equal(\n",
|
|
" batchCodeTable,\n",
|
|
" TestHelper.createDataFrame(\n",
|
|
" columns = ['Total reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Severe reports (%)'],\n",
|
|
" data = [ [2, 1, 2, 2, (1 + 2 + 2) / 2 * 100],\n",
|
|
" [1, 1, 0, 0, (1 + 0 + 0) / 1 * 100]],\n",
|
|
" index = pd.Index(\n",
|
|
" [\n",
|
|
" '030L20B',\n",
|
|
" '030L20A'\n",
|
|
" ],\n",
|
|
" name = 'VAX_LOT')),\n",
|
|
" check_dtype = False)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5a8bff1b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"unittest.main(argv = [''], verbosity = 2, exit = False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "49f3544e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"def ensurePath(file):\n",
|
|
" directory = os.path.dirname(file)\n",
|
|
" if not os.path.exists(directory):\n",
|
|
" os.makedirs(directory)\n",
|
|
"\n",
|
|
"def saveDataFrameAsExcelFile(dataFrame, file):\n",
|
|
" ensurePath(file)\n",
|
|
" dataFrame.to_excel(file)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "86e0e4f2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def saveBatchCodeTable(manufacturer, excelFile):\n",
|
|
" vaersDescrs = VaersDescrReader(dataDir = \"VAERS\").readAllVaersDescrs()\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(vaersDescrs)\n",
|
|
" DataFrameNormalizer.normalize(dataFrame)\n",
|
|
" batchCodeTable = BatchCodeTableFactory.createBatchCodeTable(dataFrame, manufacturer = manufacturer, dose = '1')\n",
|
|
" display(batchCodeTable)\n",
|
|
" saveDataFrameAsExcelFile(batchCodeTable, excelFile)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "987a04d1",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Moderna batch codes"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ab170c16",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# https://www.howbadismybatch.com/moderna.html\n",
|
|
"saveBatchCodeTable(\"MODERNA\", \"results/batchCodes/moderna.xlsx\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "29dd4daa",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Pfizer batch codes"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6121e2b3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# https://www.howbadismybatch.com/pfizer.html\n",
|
|
"saveBatchCodeTable(\"PFIZER\\BIONTECH\", \"results/batchCodes/pfizer.xlsx\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7e83a551",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Janssen batch codes "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "1a64eef5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# https://www.howbadismybatch.com/janssen.html\n",
|
|
"saveBatchCodeTable(\"JANSSEN\", \"results/batchCodes/janssen.xlsx\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f677b620",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Short-list of 2000 batches having severe effects"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bc56831d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def saveSevereEffectsBatchCodeTable(excelFile):\n",
|
|
" vaersDescrs = VaersDescrReader(dataDir = \"VAERS\").readAllVaersDescrs()\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(vaersDescrs)\n",
|
|
" DataFrameNormalizer.normalize(dataFrame)\n",
|
|
" severeEffectsBatchCodeTable = BatchCodeTableFactory.createSevereEffectsBatchCodeTable(dataFrame, dose = '1')\n",
|
|
" display(severeEffectsBatchCodeTable)\n",
|
|
" saveDataFrameAsExcelFile(severeEffectsBatchCodeTable, excelFile)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ace3fed9",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"saveSevereEffectsBatchCodeTable('results/severeEffects.xlsx')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "1b228a16",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Variation in Effect of First and Second Doses"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "202f7c3f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# https://www.howbadismybatch.com/firstsecond.html\n",
|
|
"\n",
|
|
"def createDoseTable():\n",
|
|
" vaersDescrs = VaersDescrReader(dataDir = \"VAERS\").readAllVaersDescrs()\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(vaersDescrs)\n",
|
|
" DataFrameNormalizer.normalize(dataFrame)\n",
|
|
" return DoseTableFactory.createDoseTable(dataFrame)\n",
|
|
"\n",
|
|
"def createDoseByMonthTable():\n",
|
|
" vaersDescrs = VaersDescrReader(dataDir = \"VAERS\").readAllVaersDescrs()\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(vaersDescrs)\n",
|
|
" DataFrameNormalizer.normalize(dataFrame)\n",
|
|
" return DoseTableFactory.createDoseByMonthTable(dataFrame)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "394fa19d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"createDoseTable()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b333e5fb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"doseByMonthTable = createDoseByMonthTable()\n",
|
|
"saveDataFrameAsExcelFile(doseByMonthTable, 'results/firstsecond/doseByMonthTable.xlsx')\n",
|
|
"doseByMonthTable"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "075aa6c9",
|
|
"metadata": {},
|
|
"source": [
|
|
"### International Deadly Lots"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "8f8880f4",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# https://www.howbadismybatch.com/international.html\n",
|
|
"\n",
|
|
"def getNonDomesticVaers():\n",
|
|
" vaersDescr = VaersDescrReader(dataDir = 'VAERS').readNonDomesticVaersDescr()\n",
|
|
" dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescr(vaersDescr)\n",
|
|
" DataFrameNormalizer.normalize(dataFrame)\n",
|
|
" return dataFrame\n",
|
|
"\n",
|
|
"nonDomesticVaers = getNonDomesticVaers()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "54e03231",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"internationalLotTable = InternationalLotTableFactory.createInternationalLotTable(nonDomesticVaers)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7e80e958",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"internationalLotTable = internationalLotTable[internationalLotTable['Total reports'] > 50]\n",
|
|
"saveDataFrameAsExcelFile(internationalLotTable, 'results/international/International_Deadly_Lots.xlsx')\n",
|
|
"internationalLotTable"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ff259a35",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def createAndSaveAndDisplayBatchCodeTableByCountry(country):\n",
|
|
" batchCodeTable = InternationalLotTableFactory.createBatchCodeTableByCountry(nonDomesticVaers, country)\n",
|
|
" batchCodeTable = batchCodeTable[batchCodeTable['Total reports'] > 50]\n",
|
|
" saveDataFrameAsExcelFile(batchCodeTable, 'results/international/' + country + '.xlsx')\n",
|
|
" display(country + \":\", batchCodeTable)\n",
|
|
"\n",
|
|
"def createAndSaveAndDisplayBatchCodeTablesByCountry(countries):\n",
|
|
" for country in countries:\n",
|
|
" createAndSaveAndDisplayBatchCodeTableByCountry(country)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7e7e01a5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"createAndSaveAndDisplayBatchCodeTablesByCountry(\n",
|
|
" [\n",
|
|
" 'United Kingdom',\n",
|
|
" 'France',\n",
|
|
" 'Germany',\n",
|
|
" 'Japan',\n",
|
|
" 'Italy',\n",
|
|
" 'Austria',\n",
|
|
" 'Netherlands',\n",
|
|
" 'Spain',\n",
|
|
" 'Belgium',\n",
|
|
" 'Sweden',\n",
|
|
" 'Portugal',\n",
|
|
" 'Australia'\n",
|
|
" ])"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.9.7"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|