def list(self, request):
        if user_management_views.get_facilities_by_user(request).count() > 0:
            facility_list = user_management_views.get_facilities_by_user(request).values('id')

        query_commodity_balance = master_data_models.HealthCommodityBalance.objects.filter \
            (location_id__in=facility_list, is_active=True)
        queryset = master_data_models.PostingSchedule.objects.filter(health_commodity_balance__in=query_commodity_balance)
        serializer = PostingScheduleSerializer(queryset, many=True)
        return Response(serializer.data)
Esempio n. 2
0
def get_post_consumption_page(request):
    facility_list = user_management_views.get_facilities_by_user(
        request).values('id')

    query_health_commodity_balance = master_data_models.HealthCommodityBalance.objects.filter(
        location__in=facility_list,
        health_commodity__is_active=True).order_by('health_commodity')

    table = PostConsumptionTable(query_health_commodity_balance)

    # RequestConfig(request, paginate={'per_page': 25}).configure(table)

    notifications = flow_management_views.get_dashboard_notification_count(
        request)

    unread_messages = notifications[0]
    scheduled_items = notifications[1]

    locations = user_management_views.get_parent_child_relationship(request)

    return render(
        request, 'MasterDataManagement/PostConsumptionFromELIMS.html', {
            'table': table,
            'unread_messages': unread_messages,
            'scheduled_items': scheduled_items,
            'locations': locations
        })
def get_scheduled_transaction_page(request):
    if user_management_views.get_facilities_by_user(request).count() > 0:
        facility_list = user_management_views.get_facilities_by_user(request).values('id')

        locations = user_management_views.get_parent_child_relationship(request)

        query_health_commodity_balance = master_data_models.HealthCommodityBalance.objects. \
            filter(location__in=facility_list, health_commodity__is_active=True)

        table_scheduled_transactions = ScheduledTransactionTable(master_data_models.PostingSchedule.objects.
                                                                 filter(health_commodity_balance__is_active=True,status="pending", health_commodity_balance__in=
        query_health_commodity_balance).order_by('scheduled_date'))

        RequestConfig(request, paginate={'per_page': 50}).configure(table_scheduled_transactions)

        notifications = get_dashboard_notification_count(request)

        unread_messages = notifications[0]
        scheduled_items = notifications[1]

        return render(request, 'FlowManagement/ScheduledTransactions.html',
                      {'table_scheduled_transactions': table_scheduled_transactions,'unread_messages':unread_messages,
                       'scheduled_items':scheduled_items, 'locations':locations})
def check_for_commodities_to_post(request):
    facility_list = user_management_views.get_facilities_by_user(request).values('id')

    query_managed_commodities = master_data_models.HealthCommodityBalance.objects.filter \
        (location__in=facility_list)

    if query_managed_commodities.count() > 0:
        query_schedule = master_data_models.PostingSchedule.objects.filter \
            (health_commodity_balance__is_active=True,health_commodity_balance__in=query_managed_commodities, scheduled_date__lte=datetime.now(),
             status="pending")

        return query_schedule
    else:
        return None
def view_health_commodity_transactions(request):
    facility_list = user_management_views.get_facilities_by_user(request).values('id')

    query_transactions = master_data_models.HealthCommodityTransactions.objects.filter(is_active=True,
                                                                                       posting_schedule__health_commodity_balance__location__in=facility_list).order_by('-id')
    table_transactions = HealthCommodityTransactionTable(query_transactions)

    RequestConfig(request, paginate={'per_page': 50}).configure(table_transactions)

    notifications = get_dashboard_notification_count(request)

    unread_messages = notifications[0]
    scheduled_items = notifications[1]

    return render(request, 'FlowManagement/ViewTransactions.html', {'table_transactions':
                                                                        table_transactions, 'unread_messages':unread_messages,
                                                                    'scheduled_items':scheduled_items})
Esempio n. 6
0
def get_post_stock_on_hand_page(request):
    facility_list = user_management_views.get_facilities_by_user(
        request).values('id')

    table = PostStockBalanceTable(
        HealthCommodityBalance.objects.filter(quantity_available__isnull=True,
                                              health_commodity__is_active=True,
                                              location__in=facility_list))

    notifications = flow_management_views.get_dashboard_notification_count(
        request)

    unread_messages = notifications[0]
    scheduled_items = notifications[1]

    return render(
        request, 'MasterDataManagement/PostStockOnHand.html', {
            'table': table,
            'unread_messages': unread_messages,
            'scheduled_items': scheduled_items
        })
Esempio n. 7
0
def get_commodity_facility_mappings_page(request):
    facility_list = user_management_views.get_facilities_by_user(
        request).values('id')

    query_health_commodity_balance = master_data_models.HealthCommodityBalance.objects.filter(
        location__in=facility_list,
        health_commodity__is_active=True).order_by('health_commodity')

    unmanaged_commodities = query_health_commodity_balance.values(
        'health_commodity')

    query_unmanaged_health_commodities = HealthCommodity.objects.exclude(
        Q(id__in=unmanaged_commodities))

    query_categories = HealthCommoditiesCategory.objects.filter(is_active=True)

    table_managed_commodities = HealthCommodityBalanceTable(
        query_health_commodity_balance)

    table_unmanaged_commodities = ManageHealthCommoditiesTable(
        query_unmanaged_health_commodities)

    form_elims = eLIMSLogin()

    notifications = flow_management_views.get_dashboard_notification_count(
        request)

    unread_messages = notifications[0]
    scheduled_items = notifications[1]

    location_id = request.user.profile.location_id
    query_locations = master_data_models.Location.objects.all()

    children = []

    facility_ids = []

    for x in query_locations:
        if x.parent_id == location_id:

            if len((user_management_views.get_children_recursively(x.id))) > 0:
                children.append(
                    user_management_views.get_children_recursively(x.id))
            else:
                facility_ids.append(x.id)

    for y in children:
        for z in y:
            facility_ids.append(z['id'])

    locations = master_data_models.Location.objects.filter(id__in=facility_ids)

    return render(
        request, 'MasterDataManagement/CommodityFacilityMappings.html', {
            'table_managed_commodities': table_managed_commodities,
            'table_unmanaged_commodities': table_unmanaged_commodities,
            'query_categories': query_categories,
            'form': form_elims,
            'unread_messages': unread_messages,
            'scheduled_items': scheduled_items,
            'locations': locations
        })
Esempio n. 8
0
def export_posted_transactions_xls(request, date_from, date_to):
    facility_list = user_management_views.get_facilities_by_user(
        request).values('id')

    if date_from is not None and date_to is not None:
        date_time_from = "" + date_from + ""  # The date - 29 Dec 2017
        date_time_to = "" + date_to + ""  # The date - 29 Dec 2017

        format_str = '%m-%d-%Y'

        date_time_from_formatted = datetime.datetime.strptime(
            date_time_from, format_str)
        date__time_to_formatted = datetime.datetime.strptime(
            date_time_to, format_str)

        date_from_formatted = date_time_from_formatted.date()
        date_to_formatted = date__time_to_formatted.date()

        query_transactions = HealthCommodityTransactions.objects.filter(
            date_time_created__range=(date_from_formatted, date_to_formatted),
            is_active=True,
            posting_schedule__health_commodity_balance__location__in=
            facility_list)

    else:
        query_transactions = HealthCommodityTransactions.objects.filter(
            is_active=True,
            posting_schedule__health_commodity_balance__location__in=
            facility_list)

    response = HttpResponse(content_type='application/ms-excel')
    response[
        'Content-Disposition'] = 'attachment; filename="Posted Transactions.xls"'

    wb = xlwt.Workbook(encoding='utf-8')
    ws = wb.add_sheet('Disabled Interest')

    # Sheet header, first row
    row_num = 0

    font_style = xlwt.XFStyle()
    font_style.font.bold = True

    columns = [
        'Date Time Posted', 'Health Commodity', 'Quantity available',
        'Quantity Consumed', 'Has Patients', 'Stock Out Days'
    ]

    for col_num in range(len(columns)):
        ws.write(row_num, col_num, columns[col_num], font_style)

    # Sheet body, remaining rows
    font_style = xlwt.XFStyle()

    rows = query_transactions.values_list \
        ('date_time_created', 'posting_schedule__health_commodity_balance__health_commodity__health_commodity_name',
         'quantity_available', 'quantity_consumed', 'has_patients', 'stock_out_days')

    rows = [[
        x.strftime("%Y-%m-%d %H:%M") if isinstance(x, datetime.datetime) else x
        for x in row
    ] for row in rows]

    for row in rows:
        row_num += 1
        for col_num in range(len(row)):
            ws.write(row_num, col_num, row[col_num], font_style)

    wb.save(response)
    return response
    def list(self, request):
        facility_list = user_management_views.get_facilities_by_user(request).values('id')

        queryset = master_data_models.HealthCommodityBalance.objects.filter(location__in=facility_list, is_active=True)
        serializer = HealthCommodityBalanceSerializer(queryset, many=True)
        return Response(serializer.data)