Esempio n. 1
0
def stock_data_submission(sender, cases, endpoint=None, **kwargs):
    project = Domain.get_by_name(cases[0].domain)

    if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:

        if endpoint is None:
            endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)

        # get agentCode and programCode - I assume all cases are part of the same program
        agentCode = (cases[0].get_supply_point_case()).location.site_code
        programCode = Program.get(cases[0].get_product().program_id).code

        products = []
        for case in cases:
            product = case.get_product()

            product_json = {'productCode': product.code}
            product_json['stockInHand'] = int(case.get_default_value())

            products.append(product_json)

        stock_data = {  'agentCode': agentCode,
                        'programCode': programCode,
                        'products': products
        }
        response = sync_stock_data_to_openlmis(submission=stock_data, openlmis_endpoint=endpoint)

        if response['requisitionId'] is not None:
            for case in cases:
                case.external_id = response['requisitionId']
                case.save()

            cases, send_notification = sync_requisition_from_openlmis(project.name, response['requisitionId'], endpoint)
            if send_notification:
                send_notifications(xform=None, cases=cases)
Esempio n. 2
0
def stock_data_submission(sender, cases, endpoint=None, **kwargs):
    project = Domain.get_by_name(cases[0].domain)

    if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:

        if endpoint is None:
            endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)

        # get agentCode and programCode - I assume all cases are part of the same program
        agentCode = (cases[0].get_supply_point_case()).location.site_code
        programCode = Program.get(cases[0].get_product().program_id).code

        products = []
        for case in cases:
            product = case.get_product()

            product_json = {'productCode': product.code}
            product_json['stockInHand'] = int(case.get_default_value())

            products.append(product_json)

        stock_data = {  'agentCode': agentCode,
                        'programCode': programCode,
                        'products': products
        }
        response = sync_stock_data_to_openlmis(submission=stock_data, openlmis_endpoint=endpoint)

        if response['requisitionId'] is not None:
            for case in cases:
                case.external_id = response['requisitionId']
                case.save()

            cases, send_notification = sync_requisition_from_openlmis(project.name, response['requisitionId'], endpoint)
            if send_notification:
                send_notifications(xform=None, cases=cases)
Esempio n. 3
0
def confirm_delivery(sender, requisitions, **kwargs):
    if requisitions and requisitions[
            0].requisition_status == RequisitionStatus.RECEIVED:
        project = Domain.get_by_name(requisitions[0].domain)
        if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
            endpoint = OpenLMISEndpoint.from_config(
                project.commtrack_settings.openlmis_config)
            delivery_update(requisitions, endpoint)
Esempio n. 4
0
def approve_requisitions(sender, requisitions, **kwargs):
    if requisitions and requisitions[
            0].requisition_status == RequisitionStatus.APPROVED:
        project = Domain.get_by_name(requisitions[0].domain)
        if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
            endpoint = OpenLMISEndpoint.from_config(
                project.commtrack_settings.openlmis_config)
            approve_requisition(requisitions, endpoint)
Esempio n. 5
0
def supply_point_updated(sender, supply_point, created, **kwargs):
    project = Domain.get_by_name(supply_point.domain)
    if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
        # check if supply_point is of 'chw type'
        if supply_point.location and supply_point.location.location_type == "chw":
            #check if supply_point is linked to an OpenLMIS facility
            if supply_point.location.lineage and len(supply_point.location.lineage) > 0:
                endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
                sync_supply_point_to_openlmis(supply_point, endpoint, created)
Esempio n. 6
0
def supply_point_updated(sender, supply_point, created, **kwargs):
    project = Domain.get_by_name(supply_point.domain)
    if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
        # check if supply_point is of 'chw type'
        if supply_point.location and supply_point.location.location_type == "chw":
            #check if supply_point is linked to an OpenLMIS facility
            if supply_point.location.lineage and len(supply_point.location.lineage) > 0:
                endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
                sync_supply_point_to_openlmis(supply_point, endpoint, created)
Esempio n. 7
0
def check_requisition_updates():
    projects = Domain.get_all()
    for project in projects:
        if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
            endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
            requisitions = endpoint.get_all_requisition_statuses()
            for requisition in requisitions:
                cases, send_notification = sync_requisition_from_openlmis(project.name, requisition.requisition_id, endpoint)
                if cases and send_notification:
                    send_notifications(xform=None, cases=cases)
Esempio n. 8
0
def check_requisition_updates():
    projects = Domain.get_all()
    for project in projects:
        if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
            endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
            requisitions = endpoint.get_all_requisition_statuses()
            for requisition in requisitions:
                cases, send_notification = sync_requisition_from_openlmis(project.name, requisition.requisition_id, endpoint)
                if cases and send_notification:
                    send_notifications(xform=None, cases=cases)
Esempio n. 9
0
def supply_point_updated(sender, supply_point, created, **kwargs):
    project = Domain.get_by_name(supply_point.domain)
    if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:

        # check if supply_point is of 'chw type'
        if supply_point.location and supply_point.location.type is 'chw':

            #check if supply_point is linked to an OpenLMIS facility
            if supply_point.location.parent and supply_point.location.parent.external_id:
                endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
                sync_supply_point_to_openlmis(supply_point, endpoint)
Esempio n. 10
0
def bootstrap_domain(domain):
    project = Domain.get_by_name(domain)
    if project.commtrack_settings and project.commtrack_settings.openlmis_config.is_configured:
        endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
        for f in endpoint.get_all_facilities():
            try:
                sync_facility_to_supply_point(domain, f)
            except OpenLMISAPIException, e:
                logging.exception('Problem syncing facility %s' % f.code)

        for program in endpoint.get_all_programs(include_products=True):
            sync_openlmis_program(domain, program)
Esempio n. 11
0
def stock_data_submission(sender, cases, endpoint=None, **kwargs):
    project = Domain.get_by_name(cases[0].domain)

    if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:

        if endpoint is None:
            endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)

        # get agentCode and programCode - I assume all cases are part of the same program
        agentCode = (cases[0].get_supply_point_case()).location.site_code
        programCode = Program.get(cases[0].get_product().program_id).code

        products = []
        for rq in cases:
            product = rq.get_product()
            products.append({'productCode': product.code,
                             'beginningBalance': product.beginningBalance,
                             'quantityReceived': product.quantityReceived,
                             'quantityDispensed': product.quantityDispensed,
                             'lossesAndAdjustments': product.lossesAndAdjustments,
                             'newPatientCount': product.newPatientCount,
                             'stockOnHand': product.stockOnHand,
                             'stockOutDays': product.stockOutDays,
                             'quantityRequested': product.quantityRequested,
                             'reasonForRequestedQuantity': product.reasonForRequestedQuantity,
                             'remarks': product.remarks})

        stock_data = {  'agentCode': agentCode,
                        'programCode': programCode,
                        'products': products
        }
        response = sync_stock_data_to_openlmis(submission=stock_data, openlmis_endpoint=endpoint)

        if response['requisitionId'] is not None:
            for rq in cases:
                rq.external_id = response['requisitionId']
                rq.save()
Esempio n. 12
0
def confirm_delivery(sender, requisitions, **kwargs):
    if requisitions and requisitions[0].requisition_status == RequisitionStatus.RECEIVED:
        project = Domain.get_by_name(requisitions[0].domain)
        if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
            endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
            delivery_update(requisitions, endpoint)
Esempio n. 13
0
def approve_requisitions(sender, requisitions, **kwargs):
    if requisitions and requisitions[0].requisition_status == RequisitionStatus.APPROVED:
        project = Domain.get_by_name(requisitions[0].domain)
        if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled:
            endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config)
            approve_requisition(requisitions, endpoint)