Extracting senior care status from VAERS using Gemini Flash

This task will extract information about whether a VAERS death report was for someone who was in a nursing home or in some kind of senior care.

died due to cardiac arrest; This is a spontaneous report received from a contactable physician via regulatory authority with Regulatory authority report number CH-SM-2021-10701. A 94-year-old female patient received bnt162b2 (COMIRNATY, Solution for injection, lot number: EM0477/PAA156571), intramuscularly on 21Jan2021 at single dose for covid-19 immunisation. Medical history included distal femur fracture from 23Dec2020 and plate osteosynthesis from 02Jan2021; Peripheral obliterative arteriopathy stage I right from an unknown date, hypertensive heart disease from an unknown date, venous insufficiency from an unknown date; Cholangiocarcinoma from Jul2019, restless legs syndrome from an unknown date, erosive finger poly-arthrosis in the MPO-ANCA fingers of unclear significance due to age, comorbidities and poly-morbidity from an unknown date. Concomitant medication included rivaroxaban (XARELTO), methotrexate sodium (METOJECT), torasemide (TOREM), pramipexole dihydrochloride (SIFROL), calcium carbonate, colecalciferol (CALCIMAGON D3), glyceryl trinitrate (NITRODERM), metamizole sodium (NOVALGIN), naloxone hydrochloride, oxycodone hydrochloride (TARGIN), pantoprazole sodium sesquihydrate (PANTOZOL), amiodarone hydrochloride (AMIODAR). This concerns a 94 year old polymorbid female elderly home resident known for plate osteosynthesis on 02Jan2021 following distal femoral fracture on 23Dec2020, known for stage I peripheral obliterative arteriopathy on the right, venous insufficiency, hypertensive heart disease, cholangiocarcinoma (first diagnosed Jul2019), restless leg syndrome, and erosive finger poly-arthrosis in the MPO-ANCA fingers of unclear significance due to age, comorbidities and poly-morbidity. On 21Jan2021 the patient was administered Comirnaty vaccine and the following day, on 22Jan2021, the patient died. Further course unknown. The patient died due to cardiac arrest on 22Jan2021. An autopsy was not performed. The outcome of event cardiac arrest was fatal. Reporter''s comment: Death in a temporal correlation with the administration of Comirnaty. Sender''s comment: Death occurred 1 day after administration of COVID-19 vaccine Comirnaty, of a 94-year-old frail, polymorbid, poly-medicated elderly woman, compromised at the cardiac level by hypertensive heart disease and diagnosed with cholangiocarcinoma. In the immediate aftermath of vaccination, the patient did not manifest any adverse reactions. Specifically, she did not show any symptomatology referable to possible allergic reactions or anaphylaxis. In view of her already compromised state of health, the treating physician''s assessment of death due to cardiac arrest is likely, given her comorbidities and advanced age. We do not have imaging, laboratory or autopsy diagnostics to support the causal hypothesis because they have not been performed. At the current state of knowledge, despite the temporal link, in view of the compromised clinical picture and the advanced age of the patient, we consider it unlikely that there is a direct causal correlation between Comirnaty vaccination and the death of the patient. A causal relationship between Comirnaty and Death was assessed as being unlikely. Swissmedic assessed this case as serious, results in death.; Reporter''s Comments: Death in a temporal correlation with the administration of Comirnaty.; Reported Cause(s) of Death: Cardiac arrest

Python code for Gemini

import json

import pandas as pd
from google import genai
from pydantic import BaseModel, Field
import os
from dotenv import load_dotenv
from google.genai import types
import time
from enum import Enum
load_dotenv()
gemini_api_key = os.getenv('GEMINI_API_KEY')

class PatientInSeniorCare(BaseModel):
    """Model for extracting senior care from VAERS data."""
    patient_in_senior_care: bool = Field(description="Is the patient in senior care? Answer yes or no")
    patient_in_senior_care_explanation: str = Field(
        description="Either An explanation for the inference, or a verbatim sentence from the symptom_text which provides a citation")


client = genai.Client(api_key=gemini_api_key)

df: pd.DataFrame = pd.read_csv(f'../csv/llm/foreign_deaths_pfizer_100.csv')
df.columns = [x.upper() for x in df.columns]

model_name = 'gemini-2.5-flash-preview-05-20'
experiment = 'patient_in_senior_care'
full_json = {}
num_rows = 100
for index, row in df.head(num_rows).iterrows():
    symptom_text = row['SYMPTOM_TEXT']
    vaers_id = row['VAERS_ID']
    print(f'Processing {index} = {vaers_id}')
    start_time = time.time()
    prompt = symptom_text
    response = client.models.generate_content(
        model=model_name,
        contents=prompt,
        config=types.GenerateContentConfig(
            system_instruction="You are a VAERS expert, and your goal is to read the symptom_text and provide the output in the specified schema",
            response_mime_type='application/json',
            response_schema=PatientInSeniorCare,
        )
    )
    elapsed = time.time() - start_time
    response_json = json.loads(response.model_dump_json())
    full_json[vaers_id] = {
        "response": response_json,
        "parsed": response_json['parsed'],
        "duration": elapsed,
        "prompt": prompt
    }

file_name = f'../json/{experiment}/{experiment}_{model_name}.json'
with open(file_name, 'w+') as f:
    json.dump(full_json, f, indent=2)

Leave a Reply