Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishi2003Das authored Aug 23, 2024
1 parent f4d591f commit 4eeb7ad
Showing 1 changed file with 272 additions and 0 deletions.
272 changes: 272 additions & 0 deletions DonarEligibilityTest.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "9277f5b1-2eec-45b5-9f97-bb5701e22afd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== Blood Donor Eligibility Check ===\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter your age: 21\n",
"Enter your weight in kg: 70\n",
"Enter your biological sex (male/female): male\n",
"Enter your hemoglobin level (g/dL): 15\n",
"Enter your systolic blood pressure (mmHg): 100\n",
"Enter your diastolic blood pressure (mmHg): 70\n",
"Enter your pulse rate (beats per minute): 73\n",
"Are you in good general health today? (yes/no): yes\n",
"Do you have any chronic medical conditions (e.g., HIV/AIDS, hepatitis)? (yes/no): no\n",
"Are you currently taking any medications? (yes/no): no\n",
"Have you traveled outside the country in the last 12 months? (yes/no): no\n",
"Have you had any tattoos or piercings in the last 12 months? (yes/no): no\n",
"Have you donated blood in the last 8 weeks? (yes/no): no\n",
"Have you had any recent illnesses, colds, or flu symptoms? (yes/no): no\n",
"Have you engaged in any high-risk behaviors (e.g., drug use, unprotected sex with multiple partners)? (yes/no): no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Congratulations! You are eligible to donate blood.\n"
]
}
],
"source": [
"import datetime\n",
"\n",
"def check_age(age):\n",
" if 17 <= age <= 65:\n",
" return True, \"\"\n",
" elif age == 16:\n",
" consent = input(\"Do you have parental consent? (yes/no): \").strip().lower()\n",
" if consent == 'yes':\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Parental consent required for donors aged 16.\"\n",
" else:\n",
" return False, \"Age must be between 17 and 65.\"\n",
"\n",
"def check_weight(weight):\n",
" if weight >= 50:\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Weight must be at least 50 kg (110 lbs).\"\n",
"\n",
"def check_hemoglobin(hemoglobin, sex):\n",
" if sex.lower() == 'male' and hemoglobin >= 13.0:\n",
" return True, \"\"\n",
" elif sex.lower() == 'female' and hemoglobin >= 12.5:\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Hemoglobin levels are below the minimum required.\"\n",
"\n",
"def check_blood_pressure(systolic, diastolic):\n",
" if 90 <= systolic <= 140 and 60 <= diastolic <= 90:\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Blood pressure is outside the acceptable range (90/60 mmHg to 140/90 mmHg).\"\n",
"\n",
"def check_pulse(pulse):\n",
" if 50 <= pulse <= 100:\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Pulse rate is outside the acceptable range (50-100 beats per minute).\"\n",
"\n",
"def check_general_health():\n",
" health = input(\"Are you in good general health today? (yes/no): \").strip().lower()\n",
" if health == 'yes':\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Donor should be in good general health.\"\n",
"\n",
"def check_medical_history():\n",
" medical_conditions = input(\"Do you have any chronic medical conditions (e.g., HIV/AIDS, hepatitis)? (yes/no): \").strip().lower()\n",
" if medical_conditions == 'no':\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Certain medical conditions disqualify you from donating blood.\"\n",
"\n",
"def check_medications():\n",
" medications = input(\"Are you currently taking any medications? (yes/no): \").strip().lower()\n",
" if medications == 'no':\n",
" return True, \"\"\n",
" else:\n",
" meds_list = input(\"Please list the medications you are taking separated by commas: \").strip().lower().split(',')\n",
" disqualifying_meds = ['accutane', 'antibiotics', 'blood thinners']\n",
" for med in meds_list:\n",
" if med.strip() in disqualifying_meds:\n",
" return False, f\"Medication '{med.strip()}' disqualifies you from donating blood.\"\n",
" return True, \"\"\n",
"\n",
"def check_travel_history():\n",
" travel = input(\"Have you traveled outside the country in the last 12 months? (yes/no): \").strip().lower()\n",
" if travel == 'no':\n",
" return True, \"\"\n",
" else:\n",
" countries = input(\"Please list the countries you have visited separated by commas: \").strip().lower().split(',')\n",
" high_risk_countries = ['malaria endemic region', 'zika virus affected area']\n",
" for country in countries:\n",
" if country.strip() in high_risk_countries:\n",
" return False, f\"Recent travel to '{country.strip()}' requires temporary deferral.\"\n",
" return True, \"\"\n",
"\n",
"def check_tattoos_piercings():\n",
" tp = input(\"Have you had any tattoos or piercings in the last 12 months? (yes/no): \").strip().lower()\n",
" if tp == 'no':\n",
" return True, \"\"\n",
" else:\n",
" date_str = input(\"Enter the date of your last tattoo or piercing (YYYY-MM-DD): \").strip()\n",
" try:\n",
" tp_date = datetime.datetime.strptime(date_str, '%Y-%m-%d')\n",
" today = datetime.datetime.today()\n",
" difference = today - tp_date\n",
" if difference.days >= 12*30:\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Must wait at least 12 months after a tattoo or piercing.\"\n",
" except ValueError:\n",
" return False, \"Invalid date format for tattoo/piercing date.\"\n",
"\n",
"def check_pregnancy(sex):\n",
" if sex.lower() == 'female':\n",
" pregnant = input(\"Are you currently pregnant or have been in the last 6 months? (yes/no): \").strip().lower()\n",
" if pregnant == 'no':\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Pregnant women are not eligible to donate blood.\"\n",
" else:\n",
" return True, \"\"\n",
"\n",
"def check_recent_donation():\n",
" donation = input(\"Have you donated blood in the last 8 weeks? (yes/no): \").strip().lower()\n",
" if donation == 'no':\n",
" return True, \"\"\n",
" else:\n",
" date_str = input(\"Enter the date of your last donation (YYYY-MM-DD): \").strip()\n",
" try:\n",
" donation_date = datetime.datetime.strptime(date_str, '%Y-%m-%d')\n",
" today = datetime.datetime.today()\n",
" difference = today - donation_date\n",
" if difference.days >= 56:\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Must wait at least 8 weeks (56 days) between whole blood donations.\"\n",
" except ValueError:\n",
" return False, \"Invalid date format for last donation date.\"\n",
"\n",
"def check_recent_illness():\n",
" illness = input(\"Have you had any recent illnesses, colds, or flu symptoms? (yes/no): \").strip().lower()\n",
" if illness == 'no':\n",
" return True, \"\"\n",
" else:\n",
" return False, \"Recent illnesses may temporarily defer you from donating blood.\"\n",
"\n",
"def check_lifestyle():\n",
" lifestyle = input(\"Have you engaged in any high-risk behaviors (e.g., drug use, unprotected sex with multiple partners)? (yes/no): \").strip().lower()\n",
" if lifestyle == 'no':\n",
" return True, \"\"\n",
" else:\n",
" return False, \"High-risk behaviors may disqualify you from donating blood.\"\n",
"\n",
"def main():\n",
" print(\"=== Blood Donor Eligibility Check ===\")\n",
" reasons = []\n",
" \n",
" try:\n",
" age = int(input(\"Enter your age: \").strip())\n",
" except ValueError:\n",
" print(\"Invalid input for age.\")\n",
" return\n",
"\n",
" weight = float(input(\"Enter your weight in kg: \").strip())\n",
" sex = input(\"Enter your biological sex (male/female): \").strip().lower()\n",
" hemoglobin = float(input(\"Enter your hemoglobin level (g/dL): \").strip())\n",
" \n",
" try:\n",
" systolic = int(input(\"Enter your systolic blood pressure (mmHg): \").strip())\n",
" diastolic = int(input(\"Enter your diastolic blood pressure (mmHg): \").strip())\n",
" except ValueError:\n",
" print(\"Invalid input for blood pressure.\")\n",
" return\n",
"\n",
" try:\n",
" pulse = int(input(\"Enter your pulse rate (beats per minute): \").strip())\n",
" except ValueError:\n",
" print(\"Invalid input for pulse rate.\")\n",
" return\n",
"\n",
" checks = [\n",
" check_age(age),\n",
" check_weight(weight),\n",
" check_hemoglobin(hemoglobin, sex),\n",
" check_blood_pressure(systolic, diastolic),\n",
" check_pulse(pulse),\n",
" check_general_health(),\n",
" check_medical_history(),\n",
" check_medications(),\n",
" check_travel_history(),\n",
" check_tattoos_piercings(),\n",
" check_pregnancy(sex),\n",
" check_recent_donation(),\n",
" check_recent_illness(),\n",
" check_lifestyle()\n",
" ]\n",
"\n",
" for check, reason in checks:\n",
" if not check:\n",
" reasons.append(reason)\n",
"\n",
" if not reasons:\n",
" print(\"\\nCongratulations! You are eligible to donate blood.\")\n",
" else:\n",
" print(\"\\nUnfortunately, you are not eligible to donate blood due to the following reasons:\")\n",
" for reason in reasons:\n",
" print(f\"- {reason}\")\n",
"\n",
"if __name__ == \"__main__\":\n",
" main()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d95739c1-c583-4614-85a6-974369dbedb7",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.12.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 4eeb7ad

Please sign in to comment.