def testSyncRequisition(self):
     with open(os.path.join(self.datapath, 'sample_program.json')) as f:
         lmis_program = Program.from_json(json.loads(f.read()))
     commtrack_program = sync_openlmis_program(TEST_DOMAIN, lmis_program)
     test_product = {
         'name': 'Test',
         'code': 'P151',
         'unit': 10,
         'description': 'decs',
         'category': 'category',
     }
     sync_openlmis_product(TEST_DOMAIN, commtrack_program, test_product)
     sync_requisition_from_openlmis(TEST_DOMAIN, 1, self.api)
     self.assertTrue(1, len(RequisitionCase.get_by_external(TEST_DOMAIN, 1)))
 def fixmetestSyncRequisition(self):
     with open(os.path.join(self.datapath, 'sample_program.json')) as f:
         lmis_program = Program.from_json(json.loads(f.read()))
     commtrack_program = sync_openlmis_program(TEST_DOMAIN, lmis_program)
     test_product = LMISProduct.from_json({
         "programCode": "ESS_MEDS",
         "programName": "ESSENTIAL MEDICINES",
         "productCode": "P26",
         "productName": "Erythromycin ethyl succinate, pwd oral suspension, 125mg/5ml",
         "description": "TDF/FTC/EFV",
         "unit": 10,
         "category": "Analgesics"
     })
     sync_openlmis_product(TEST_DOMAIN, commtrack_program, test_product)
     sync_requisition_from_openlmis(TEST_DOMAIN, 1, self.api)
     self.assertTrue(1, len(RequisitionCase.get_by_external(TEST_DOMAIN, 1)))
Exemple #3
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)
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)
 def fixmetestSyncRequisition(self):
     with open(os.path.join(self.datapath, 'sample_program.json')) as f:
         lmis_program = Program.from_json(json.loads(f.read()))
     commtrack_program = sync_openlmis_program(TEST_DOMAIN, lmis_program)
     test_product = LMISProduct.from_json({
         "programCode": "ESS_MEDS",
         "programName": "ESSENTIAL MEDICINES",
         "productCode": "P26",
         "productName":
         "Erythromycin ethyl succinate, pwd oral suspension, 125mg/5ml",
         "description": "TDF/FTC/EFV",
         "unit": 10,
         "category": "Analgesics"
     })
     sync_openlmis_product(TEST_DOMAIN, commtrack_program, test_product)
     sync_requisition_from_openlmis(TEST_DOMAIN, 1, self.api)
     self.assertTrue(1, len(RequisitionCase.get_by_external(TEST_DOMAIN,
                                                            1)))
Exemple #6
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)
Exemple #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)