• 分享一个基于python+django的医院药品库存管理系统 医药配药系统源码 调试 lw


    💕💕作者:计算机源码社
    💕💕个人简介:本人七年开发经验,擅长Java、Python、PHP、.NET、微信小程序、爬虫、大数据等,大家有这一块的问题可以一起交流!
    💕💕学习资料、程序开发、技术解答、文档报告

    💕💕JavaWeb项目
    💕💕微信小程序项目
    💕💕Python项目
    💕💕Android项目

    1、绪论

       基于Python和Django的医院药品库存管理系统的开发背景源于对医疗卫生领域的迫切需求。随着医院规模和患者数量的增加,药品库存管理变得更为复杂且重要。传统的手动管理方式容易导致错误、浪费和药品短缺,因此,借助现代信息技术,开发一个高效、准确和可靠的系统对医疗机构和患者都具有重要意义。

       基于Python和Django的医院药品库存管理系统的意义在于:1.提高药品管理效率: 系统可以自动跟踪库存,减少了手动盘点的时间和错误率,确保医院随时有足够的药品供应。2.减少药品浪费: 系统可以根据药品的过期日期和使用情况进行管理,有助于降低药品浪费和成本。3.改善医患关系: 医生可以更轻松地开具处方,患者能够获得及时的用药服务,提高了医患关系的满意度。4.确保用药安全: 系统可以检查药物相互作用和禁忌症,减少了患者用药错误的风险。5.提供决策支持: 系统可以生成报表和统计数据,帮助医院管理层做出更明智的决策,优化库存和成本控制。

    2、核心功能模块

       该系统旨在实现医院内药品库存的高效管理和流程的优化。通过用户、医生和管理员三个角色的互动,实现了个人中心管理、公告信息发布、医生和患者信息管理、药品信息的全面管理、药品的入库和出库操作、开药记录的追踪以及药品盘点功能。系统将提高医院内部药品管理的可视性和效率,确保患者能够获得及时、准确的药物治疗,同时为医生和管理员提供了更好的决策支持和操作便利性,有助于提高医疗服务的质量和效率。

    3、项目Ui展示

    基于python+django的医院药品库存管理系统

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    4、 核心代码

    # models.py
    from django.db import models
    
    class Medicine(models.Model):
        name = models.CharField(max_length=100)
        quantity = models.PositiveIntegerField()
        # 其他药品信息字段
    
    class StockEntry(models.Model):
        medicine = models.ForeignKey(Medicine, on_delete=models.CASCADE)
        entry_type = models.CharField(max_length=20)  # '入库'或'出库'
        quantity = models.PositiveIntegerField()
        date = models.DateField()
        # 其他入库/出库信息字段
    
    # views.py
    from django.shortcuts import render, redirect
    from .models import Medicine, StockEntry
    
    def stock_entry(request):
        if request.method == 'POST':
            medicine_id = request.POST['medicine_id']
            entry_type = request.POST['entry_type']
            quantity = int(request.POST['quantity'])
            date = request.POST['date']
    
            medicine = Medicine.objects.get(id=medicine_id)
    
            if entry_type == '入库':
                medicine.quantity += quantity
            elif entry_type == '出库':
                if medicine.quantity >= quantity:
                    medicine.quantity -= quantity
                else:
                    return render(request, 'error_page.html', {'message': '库存不足'})
    
            medicine.save()
    
            stock_entry = StockEntry(medicine=medicine, entry_type=entry_type, quantity=quantity, date=date)
            stock_entry.save()
    
            return redirect('stock_entry_success')
    
        medicines = Medicine.objects.all()
        return render(request, 'stock_entry.html', {'medicines': medicines})
    
    # stock_entry.html
    <form method="POST" action="{% url 'stock_entry' %}">
        {% csrf_token %}
        <label for="medicine_id">选择药品:</label>
        <select name="medicine_id" id="medicine_id">
            {% for medicine in medicines %}
                <option value="{{ medicine.id }}">{{ medicine.name }}</option>
            {% endfor %}
        </select><br><br>
        <label for="entry_type">出库/入库类型:</label>
        <select name="entry_type" id="entry_type">
            <option value="入库">入库</option>
            <option value="出库">出库</option>
        </select><br><br>
        <label for="quantity">数量:</label>
        <input type="number" name="quantity" id="quantity" required><br><br>
        <label for="date">日期:</label>
        <input type="date" name="date" id="date" required><br><br>
        <input type="submit" value="提交">
    </form>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    # models.py
    from django.db import models
    
    class Medicine(models.Model):
        name = models.CharField(max_length=100)
        quantity = models.PositiveIntegerField()
        # 其他药品信息字段
    
    class Prescription(models.Model):
        doctor = models.ForeignKey(User, on_delete=models.CASCADE)  # 关联医生
        patient = models.ForeignKey(User, on_delete=models.CASCADE)  # 关联患者
        medicines = models.ManyToManyField(Medicine, through='PrescribedMedicine')
        date = models.DateField(auto_now_add=True)
    
    class PrescribedMedicine(models.Model):
        medicine = models.ForeignKey(Medicine, on_delete=models.CASCADE)
        prescription = models.ForeignKey(Prescription, on_delete=models.CASCADE)
        quantity = models.PositiveIntegerField()
        # 其他处方药品信息字段
    
    # views.py
    from django.shortcuts import render, redirect
    from .models import Medicine, Prescription, PrescribedMedicine
    
    def prescribe_medicine(request):
        if request.method == 'POST':
            doctor = request.user  # 获取当前登录的医生
            patient_id = request.POST['patient_id']
            medicine_ids = request.POST.getlist('medicine_ids')
            quantities = request.POST.getlist('quantities')
    
            patient = User.objects.get(id=patient_id)
            prescription = Prescription(doctor=doctor, patient=patient)
            prescription.save()
    
            for i in range(len(medicine_ids)):
                medicine_id = medicine_ids[i]
                quantity = quantities[i]
    
                medicine = Medicine.objects.get(id=medicine_id)
    
                if medicine.quantity >= quantity:
                    medicine.quantity -= quantity
                    medicine.save()
    
                    prescribed_medicine = PrescribedMedicine(medicine=medicine, prescription=prescription, quantity=quantity)
                    prescribed_medicine.save()
                else:
                    return render(request, 'error_page.html', {'message': '库存不足'})
    
            return redirect('prescription_success')
    
        patients = User.objects.filter(role='患者')  # 根据系统用户角色过滤患者列表
        medicines = Medicine.objects.all()
        return render(request, 'prescribe_medicine.html', {'patients': patients, 'medicines': medicines})
    
    # prescribe_medicine.html
    <form method="POST" action="{% url 'prescribe_medicine' %}">
        {% csrf_token %}
        <label for="patient_id">选择患者:</label>
        <select name="patient_id" id="patient_id">
            {% for patient in patients %}
                <option value="{{ patient.id }}">{{ patient.username }}</option>
            {% endfor %}
        </select><br><br>
        <label for="medicine_ids">选择药品:</label>
        <select multiple name="medicine_ids" id="medicine_ids">
            {% for medicine in medicines %}
                <option value="{{ medicine.id }}">{{ medicine.name }}</option>
            {% endfor %}
        </select><br><br>
        <label for="quantities">药品数量:</label>
        <input type="number" name="quantities" id="quantities" required><br><br>
        <input type="submit" value="开药">
    </form>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
  • 相关阅读:
    vue 部分知识点总结
    ROS小车2_ROS多机通信
    设计模式之原型模式
    如何使用PyTorch训练LLM
    数据结构——堆排序
    (2) Java后端从0硬撸vite3+vue3+ts项目 | 规范
    Qt 日志模块的个性化使用
    湖仓一体电商项目(九):业务实现之编写写入DIM层业务代码
    给电脑重装系统有什么坏处吗
    阿里云企业邮箱的替代方案有哪些?
  • 原文地址:https://blog.csdn.net/m0_72599287/article/details/132796302