示例#1
0
def make_program(domain, name, code):
    p = Program()
    p.domain = domain
    p.name = name
    p.code = code.lower()
    p.save()
    return p
示例#2
0
def make_program(domain, name, code):
    p = Program()
    p.domain = domain
    p.name = name
    p.code = code.lower()
    p.save()
    return p
示例#3
0
def make_program(domain, name, code, default=False):
    p = Program()
    p.domain = domain
    p.name = name
    p.code = code.lower()
    p.default = default
    p.save()
    return p
示例#4
0
class SignalsTest(OpenLMISTestBase):
    requisitions_enabled = True
    program = None

    def createProgram(self):
        self.program = Program()
        self.program.domain = TEST_DOMAIN
        self.program.code = 'QYZ'
        self.program.name = "hiv_program"

        self.program.save()

    def createProducts(self):
        with open(os.path.join(self.datapath, 'sample_product_1.json')) as f:
            lmis_product_1 = json.loads(f.read())

        with open(os.path.join(self.datapath, 'sample_product_2.json')) as f:
            lmis_product_2 = json.loads(f.read())

        lmis_product_1['program_id'] =  self.program._id
        lmis_product_2['program_id'] =  self.program._id

        product_1 = Product(lmis_product_1)
        product_2 = Product(lmis_product_2)
        product_1.save()
        product_2.save()

        self.products = []
        self.products.append(product_1)
        self.products.append(product_2)

    def setUp(self):
        super(SignalsTest, self).setUp()
        self.datapath = os.path.join(os.path.dirname(__file__), 'data')
        self.spps.clear()
        self.createProgram()
        self.createProducts()

    def fixmetestSyncStockRequisition(self):
        from corehq.apps.commtrack.stockreport import Requisition
        requisition_cases = []
        config = self.domain.commtrack_settings
        for spp in self.spps.values():
            transaction = Requisition(
                config=config,
                product_id=spp.product,
                case_id=spp._id,
                action_name=config.get_action_by_type(RequisitionActions.REQUEST).action_name,
                value=20,
            )
            req = create_requisition(self.user._id, spp, transaction)
            requisition_cases.append(req)
        endpoint = MockOpenLMISSubmitEndpoint("uri://mock/lmis/endpoint", username='******', password='******')
        stock_data_submission(sender=None, cases=requisition_cases, endpoint=endpoint)

        for req in requisition_cases:
            self.assertEqual(req.external_id, 'REQ_123')
示例#5
0
def sync_openlmis_program(domain, lmis_program):
    program = get_program(domain, lmis_program)
    if program is None:
        program = Program(domain=domain)

    program.name = lmis_program.name
    program.code = lmis_program.code.lower()
    program._doc_type_attr = "Program"
    program.save()
    if lmis_program.products:
        for lmis_product in lmis_program.products:
            sync_openlmis_product(domain, program, lmis_product)
    return program
示例#6
0
def sync_openlmis_program(domain, lmis_program):
    program = get_program(domain, lmis_program)
    if program is None:
        program = Program(domain=domain)
    else:
        # currently impossible
        raise NotImplementedError('updating existing programs is not yet supported')
    program.name = lmis_program.name
    program.code = lmis_program.code
    program.save()
    if lmis_program.products:
        for lmis_product in lmis_program.products:
            sync_openlmis_product(domain, program, lmis_product)
    return program