Методы предписания: проверка, генерация и хранение с примерами кода

Метод 1. Проверка рецепта.
Описание. Проверка рецепта на предмет его соответствия определенным критериям, таким как наличие подписи врача, правильная информация о пациенте и сведения о лекарстве.

def validate_prescription(prescription):
    # Check if prescription has a doctor's signature
    if not prescription.get('doctor_signature'):
        return False
    # Check if prescription has patient information
    if not prescription.get('patient_name') or not prescription.get('patient_age'):
        return False
    # Check if prescription has medication details
    if not prescription.get('medication_name') or not prescription.get('dosage'):
        return False
    # Additional validation rules can be added here
    return True

Метод 2. Создание рецепта.
Описание. Создание рецепта со случайной информацией о пациенте, лекарством и дозировкой.

import random
def generate_prescription():
    patients = ['John Doe', 'Jane Smith', 'Michael Johnson']
    medications = ['Aspirin', 'Amoxicillin', 'Ibuprofen']
    dosages = ['1 tablet', '500mg', '2 teaspoons']
    prescription = {
        'patient_name': random.choice(patients),
        'patient_age': random.randint(18, 60),
        'medication_name': random.choice(medications),
        'dosage': random.choice(dosages),
        'doctor_signature': 'Dr. Smith'  # Assuming the doctor's name is fixed
    }
    return prescription

Метод 3. Хранение рецептов.
Описание. Сохранение рецептов в базе данных для дальнейшего использования.

import sqlite3
def store_prescription(prescription):
    # Connect to the database
    conn = sqlite3.connect('prescriptions.db')
    cursor = conn.cursor()
    # Create a table if it doesn't exist
    cursor.execute('''CREATE TABLE IF NOT EXISTS prescriptions
                      (id INTEGER PRIMARY KEY AUTOINCREMENT,
                       patient_name TEXT,
                       patient_age INTEGER,
                       medication_name TEXT,
                       dosage TEXT,
                       doctor_signature TEXT)''')
    # Insert the prescription into the table
    cursor.execute('''INSERT INTO prescriptions
                      (patient_name, patient_age, medication_name, dosage, doctor_signature)
                      VALUES (?, ?, ?, ?, ?)''',
                   (prescription['patient_name'], prescription['patient_age'],
                    prescription['medication_name'], prescription['dosage'],
                    prescription['doctor_signature']))
    # Commit the transaction and close the connection
    conn.commit()
    conn.close()