コード例 #1
0
ファイル: dashboard.py プロジェクト: yeleman/red_nut
def dashboard(request):

    context = {"category": 'dashboard', 'user': request.user}

    # le nombre total d'enfant
    patients = Patient.by_uren.all().all_uren()
    nbr_total_patient = len(patients)

    # Taux guerison
    nbr_healing = len(ProgramIO.healing.all().all_uren())
    healing_rates = percentage_calculation(nbr_healing,
                                                      nbr_total_patient)

    # Taux abandon
    nbr_abandonment = len(ProgramIO.abandon.all().all_uren())
    abandonment_rates = percentage_calculation(nbr_abandonment,
                                                      nbr_total_patient)
    # Taux déces
    nbr_deaths = len(ProgramIO.death.all().all_uren())
    deaths_rates = percentage_calculation(nbr_deaths, nbr_total_patient)

    # Taux non repondant
    nbr_non_response = len(ProgramIO.nonresp.all().all_uren())

    non_response_rates = percentage_calculation(nbr_non_response,
                                                      nbr_total_patient)

    context.update({"nbr_total_patient": nbr_total_patient,
                    "nbr_healing": nbr_healing,
                    "healing_rates": healing_rates,
                    "nbr_abandonment": nbr_abandonment,
                    "abandonment_rates": abandonment_rates,
                    "nbr_deaths": nbr_deaths,
                    "deaths_rates": deaths_rates,
                    "nbr_non_response": nbr_non_response,
                    "non_response_rates": non_response_rates})

    # Durées de tous les programmes puis moyenne
    context.update({"avg_days": ProgramIO.out.avg_days()})

    # Gain de poids moyen
    context.update({"avg_weight": "%.2f" % Patient.avg_weight_gain()})

    # graphic
    total_patient = []
    graph_date = []
    diagnose_samp = []
    diagnose_sam = []
    # Ordonne les programio par order décroissante
    programio = ProgramIO.by_uren.order_by('-date').all_uren()

    nbr_date_graph = len(programio)
    if len(programio) > 100:
        nbr_date_graph = 100

    try:
        week_dates = week_range(programio[nbr_date_graph].date)
    except IndexError:
        week_dates = []

    for dat in week_dates:

        active_patients = []
        for p in patients:
            try:
                if not p.programios.filter(date__lte=dat).latest().is_output:
                    active_patients.append(p)
            except ProgramIO.DoesNotExist:
                pass

        total_patient.append(len(active_patients))
        graph_date.append(dat.strftime('%d/%m'))

        l_diagnose = []
        for patient in active_patients:
            try:
                l_diagnose.append(patient.uren)
            except NutritionalData.DoesNotExist:
                pass
        diagnose_samp.append(l_diagnose.count(NutritionalData.SAMP))
        diagnose_sam.append(l_diagnose.count(NutritionalData.SAM))

        graph_data = [{'name': "Total", 'data': total_patient},
                      {'name': "MAS+", 'data': diagnose_samp},
                      {'name': "MAS", 'data': diagnose_sam}]

        context.update({"graph_date": graph_date, "graph_data": graph_data})

    # Diagnose
    SAMP_count = extract(diagnose_samp, -1, default=0)
    SAM_count = extract(diagnose_sam, -1, default=0)

    # Nbre d'enfant dans le programme
    children_in_program = extract(total_patient, -1, default=0)

    # Nbre d'enfant en retard de consultation
    patients_late = []
    for patient in patients:
        if not patient.last_data_event().is_output and patient.is_late:
            patients_late.append(patient)
    patients_late = len(patients_late)

    # message
    received = Inbox.objects.count()
    sent = SentItems.objects.count()

    context.update({"children_in_program": children_in_program, \
                    "sent": sent, "received": received, \
                    "SAMP_count": SAMP_count, "SAM_count": SAM_count, \
                    "patients_late": patients_late})

    return render(request, 'dashboard.html', context)
コード例 #2
0
def details_health_center(request, *args, **kwargs):
    """ Details of a health center """

    context = {"category": "health_center", "user": request.user}

    num = kwargs["id"]
    health_center = HealthCenter.objects.get(id=num)

    def avg_(list_):
        ''' calcule la moyenne de jours'''
        if list_ != []:
            return sum(list_) / len(list_)
        else:
            return None

    # Les patients de ce centre
    patients = Patient.by_uren.all().filter(health_center=health_center) \
                                                                .all_uren()
    consumption_reports = ConsumptionReport.objects \
                                           .filter(health_center=health_center)

    nbr_total_patient = len(patients)
    # Taux guerison
    nbr_healing = len(
        ProgramIO.healing.filter(
            patient__health_center=health_center).all_uren())
    healing_rates = percentage_calculation(nbr_healing, nbr_total_patient)
    # Taux abandon
    nbr_abandonment = len(
        ProgramIO.abandon.filter(
            patient__health_center=health_center).all_uren())
    abandonment_rates = percentage_calculation(nbr_abandonment, \
                                                        nbr_total_patient)
    # Taux déces
    nbr_deaths = len(
        ProgramIO.death.filter(
            patient__health_center=health_center).all_uren())
    deaths_rates = percentage_calculation(nbr_deaths, nbr_total_patient)
    # Taux non repondant
    nbr_non_response = len(
        ProgramIO.nonresp.filter(
            patient__health_center=health_center).all_uren())
    non_response_rates = percentage_calculation(nbr_non_response, \
                                                        nbr_total_patient)

    dict_ = {}

    dict_["health_center"] = health_center.name
    dict_["code"] = health_center.code
    dict_["abandon"] = nbr_abandonment
    dict_["taux_abandon"] = abandonment_rates
    dict_["guerison"] = nbr_healing
    dict_["taux_guerison"] = healing_rates
    dict_["deces"] = nbr_deaths
    dict_["taux_deces"] = deaths_rates
    dict_["non_repondant"] = nbr_non_response
    dict_["taux_non_repondant"] = non_response_rates

    # graphic
    total_patient = []
    graph_date = []
    diagnose_samp = []
    diagnose_sam = []
    programio = ProgramIO.by_uren.order_by('-date').all_uren()

    nbr_date_graph = len(programio)
    if len(programio) > 100:
        nbr_date_graph = 100

    try:
        week_dates = week_range(programio[nbr_date_graph].date)
    except IndexError:
        week_dates = []

    for dat in week_dates:

        active_patients = []
        for p in patients:
            try:
                if not p.programios.filter(date__lte=dat).latest().is_output:
                    active_patients.append(p)
            except ProgramIO.DoesNotExist:
                pass

        total_patient.append(len(active_patients))
        graph_date.append(dat.strftime('%d/%m'))

        l_diagnose = []
        for patient in active_patients:
            try:
                l_diagnose.append(patient.uren)
            except NutritionalData.DoesNotExist:
                pass

        diagnose_samp.append(l_diagnose.count(NutritionalData.SAMP))
        diagnose_sam.append(l_diagnose.count(NutritionalData.SAM))

        graph_data = [{
            'name': "Total",
            'data': total_patient
        }, {
            'name': "MAS+",
            'data': diagnose_samp
        }, {
            'name': "MAS",
            'data': diagnose_sam
        }]

        context.update({"graph_date": graph_date, "graph_data": graph_data})

    # Diagnose
    dict_["SAMP_count"] = extract(diagnose_samp, -1, default=0)
    dict_["SAM_count"] = extract(diagnose_sam, -1, default=0)

    # Nbre d'enfants dans le programme
    dict_["actif"] = extract(total_patient, -1, default=0)
    # Nbre d'enfants enregistres
    dict_["total"] = nbr_total_patient or 0

    try:
        dict_["avg_days"] = "%.0f" % ProgramIO.out\
                                .filter(patient__health_center=health_center)\
                                .avg_days()
    except:
        dict_["avg_days"] = 0

    dict_["avg_diff_weight"] = "%.2f" % Patient.avg_weight_gain(patients)

    context.update({'dict_': dict_, \
                    'consumption_reports': consumption_reports})

    return render(request, 'details_health_center.html', context)
コード例 #3
0
ファイル: dashboard.py プロジェクト: yeleman/red_nut
def dashboard(request):

    context = {"category": 'dashboard', 'user': request.user}

    # le nombre total d'enfant
    patients = Patient.by_uren.all().all_uren()
    nbr_total_patient = len(patients)

    # Taux guerison
    nbr_healing = len(ProgramIO.healing.all().all_uren())
    healing_rates = percentage_calculation(nbr_healing, nbr_total_patient)

    # Taux abandon
    nbr_abandonment = len(ProgramIO.abandon.all().all_uren())
    abandonment_rates = percentage_calculation(nbr_abandonment,
                                               nbr_total_patient)
    # Taux déces
    nbr_deaths = len(ProgramIO.death.all().all_uren())
    deaths_rates = percentage_calculation(nbr_deaths, nbr_total_patient)

    # Taux non repondant
    nbr_non_response = len(ProgramIO.nonresp.all().all_uren())

    non_response_rates = percentage_calculation(nbr_non_response,
                                                nbr_total_patient)

    context.update({
        "nbr_total_patient": nbr_total_patient,
        "nbr_healing": nbr_healing,
        "healing_rates": healing_rates,
        "nbr_abandonment": nbr_abandonment,
        "abandonment_rates": abandonment_rates,
        "nbr_deaths": nbr_deaths,
        "deaths_rates": deaths_rates,
        "nbr_non_response": nbr_non_response,
        "non_response_rates": non_response_rates
    })

    # Durées de tous les programmes puis moyenne
    context.update({"avg_days": ProgramIO.out.avg_days()})

    # Gain de poids moyen
    context.update({"avg_weight": "%.2f" % Patient.avg_weight_gain()})

    # graphic
    total_patient = []
    graph_date = []
    diagnose_samp = []
    diagnose_sam = []
    # Ordonne les programio par order décroissante
    programio = ProgramIO.by_uren.order_by('-date').all_uren()

    nbr_date_graph = len(programio)
    if len(programio) > 100:
        nbr_date_graph = 100

    try:
        week_dates = week_range(programio[nbr_date_graph].date)
    except IndexError:
        week_dates = []

    for dat in week_dates:

        active_patients = []
        for p in patients:
            try:
                if not p.programios.filter(date__lte=dat).latest().is_output:
                    active_patients.append(p)
            except ProgramIO.DoesNotExist:
                pass

        total_patient.append(len(active_patients))
        graph_date.append(dat.strftime('%d/%m'))

        l_diagnose = []
        for patient in active_patients:
            try:
                l_diagnose.append(patient.uren)
            except NutritionalData.DoesNotExist:
                pass
        diagnose_samp.append(l_diagnose.count(NutritionalData.SAMP))
        diagnose_sam.append(l_diagnose.count(NutritionalData.SAM))

        graph_data = [{
            'name': "Total",
            'data': total_patient
        }, {
            'name': "MAS+",
            'data': diagnose_samp
        }, {
            'name': "MAS",
            'data': diagnose_sam
        }]

        context.update({"graph_date": graph_date, "graph_data": graph_data})

    # Diagnose
    SAMP_count = extract(diagnose_samp, -1, default=0)
    SAM_count = extract(diagnose_sam, -1, default=0)

    # Nbre d'enfant dans le programme
    children_in_program = extract(total_patient, -1, default=0)

    # Nbre d'enfant en retard de consultation
    patients_late = []
    for patient in patients:
        if not patient.last_data_event().is_output and patient.is_late:
            patients_late.append(patient)
    patients_late = len(patients_late)

    # message
    received = Inbox.objects.count()
    sent = SentItems.objects.count()

    context.update({"children_in_program": children_in_program, \
                    "sent": sent, "received": received, \
                    "SAMP_count": SAMP_count, "SAM_count": SAM_count, \
                    "patients_late": patients_late})

    return render(request, 'dashboard.html', context)
コード例 #4
0
def details_health_center(request, *args, **kwargs):
    """ Details of a health center """

    context = {"category": "health_center", "user": request.user}

    num = kwargs["id"]
    health_center = HealthCenter.objects.get(id=num)

    def avg_(list_):
        """ calcule la moyenne de jours"""
        if list_ != []:
            return sum(list_) / len(list_)
        else:
            return None

    # Les patients de ce centre
    patients = Patient.by_uren.all().filter(health_center=health_center).all_uren()
    consumption_reports = ConsumptionReport.objects.filter(health_center=health_center)

    nbr_total_patient = len(patients)
    # Taux guerison
    nbr_healing = len(ProgramIO.healing.filter(patient__health_center=health_center).all_uren())
    healing_rates = percentage_calculation(nbr_healing, nbr_total_patient)
    # Taux abandon
    nbr_abandonment = len(ProgramIO.abandon.filter(patient__health_center=health_center).all_uren())
    abandonment_rates = percentage_calculation(nbr_abandonment, nbr_total_patient)
    # Taux déces
    nbr_deaths = len(ProgramIO.death.filter(patient__health_center=health_center).all_uren())
    deaths_rates = percentage_calculation(nbr_deaths, nbr_total_patient)
    # Taux non repondant
    nbr_non_response = len(ProgramIO.nonresp.filter(patient__health_center=health_center).all_uren())
    non_response_rates = percentage_calculation(nbr_non_response, nbr_total_patient)

    dict_ = {}

    dict_["health_center"] = health_center.name
    dict_["code"] = health_center.code
    dict_["abandon"] = nbr_abandonment
    dict_["taux_abandon"] = abandonment_rates
    dict_["guerison"] = nbr_healing
    dict_["taux_guerison"] = healing_rates
    dict_["deces"] = nbr_deaths
    dict_["taux_deces"] = deaths_rates
    dict_["non_repondant"] = nbr_non_response
    dict_["taux_non_repondant"] = non_response_rates

    # graphic
    total_patient = []
    graph_date = []
    diagnose_samp = []
    diagnose_sam = []
    programio = ProgramIO.by_uren.order_by("-date").all_uren()

    nbr_date_graph = len(programio)
    if len(programio) > 100:
        nbr_date_graph = 100

    try:
        week_dates = week_range(programio[nbr_date_graph].date)
    except IndexError:
        week_dates = []

    for dat in week_dates:

        active_patients = []
        for p in patients:
            try:
                if not p.programios.filter(date__lte=dat).latest().is_output:
                    active_patients.append(p)
            except ProgramIO.DoesNotExist:
                pass

        total_patient.append(len(active_patients))
        graph_date.append(dat.strftime("%d/%m"))

        l_diagnose = []
        for patient in active_patients:
            try:
                l_diagnose.append(patient.uren)
            except NutritionalData.DoesNotExist:
                pass

        diagnose_samp.append(l_diagnose.count(NutritionalData.SAMP))
        diagnose_sam.append(l_diagnose.count(NutritionalData.SAM))

        graph_data = [
            {"name": "Total", "data": total_patient},
            {"name": "MAS+", "data": diagnose_samp},
            {"name": "MAS", "data": diagnose_sam},
        ]

        context.update({"graph_date": graph_date, "graph_data": graph_data})

    # Diagnose
    dict_["SAMP_count"] = extract(diagnose_samp, -1, default=0)
    dict_["SAM_count"] = extract(diagnose_sam, -1, default=0)

    # Nbre d'enfants dans le programme
    dict_["actif"] = extract(total_patient, -1, default=0)
    # Nbre d'enfants enregistres
    dict_["total"] = nbr_total_patient or 0

    try:
        dict_["avg_days"] = "%.0f" % ProgramIO.out.filter(patient__health_center=health_center).avg_days()
    except:
        dict_["avg_days"] = 0

    dict_["avg_diff_weight"] = "%.2f" % Patient.avg_weight_gain(patients)

    context.update({"dict_": dict_, "consumption_reports": consumption_reports})

    return render(request, "details_health_center.html", context)