Esempio n. 1
0
 def _load_claim_hex(self, claim_hex):
     claim = None
     state_entries = self._context.get_state([claim_hex],
                                             timeout=self.TIMEOUT)
     if state_entries:
         claim = payload_pb2.CreateClaim()
         claim.ParseFromString(state_entries[0].data)
     return claim
Esempio n. 2
0
    def _store_claim(self, claim_id, clinic_pkey, patient_pkey):
        claim_hex = helper.make_claim_address(claim_id, clinic_pkey)
        claim = payload_pb2.CreateClaim()
        claim.claim_id = claim_id
        claim.clinic_pkey = clinic_pkey
        claim.patient_pkey = patient_pkey

        state_data = claim.SerializeToString()
        self._context.set_state({claim_hex: state_data}, timeout=self.TIMEOUT)
Esempio n. 3
0
 def _load_claim(self, claim_id, clinic_pkey):
     claim = None
     claim_hex = [] if clinic_pkey is None and claim_id is None \
         else [helper.make_claim_address(claim_id, clinic_pkey)]
     state_entries = self._context.get_state(claim_hex,
                                             timeout=self.TIMEOUT)
     if state_entries:
         claim = payload_pb2.CreateClaim()
         claim.ParseFromString(state_entries[0].data)
     return claim
    def add_claim(self, claim_id, patient_pkey, wait=None, auth_user=None,
                  auth_password=None):
        batch_key = txn_key = self._signer.get_public_key().as_hex()

        clinic_hex = helper.make_clinic_address(clinic_pkey=txn_key)
        claim_hex = helper.make_claim_address(claim_id=claim_id, clinic_pkey=txn_key)

        claim = payload_pb2.CreateClaim(
            claim_id=claim_id,
            clinic_pkey=txn_key,
            patient_pkey=patient_pkey,
        )

        payload = payload_pb2.TransactionPayload(
            payload_type=payload_pb2.TransactionPayload.CREATE_CLAIM,
            create_claim=claim)

        return self._send_healthcare_txn(txn_key, batch_key, [claim_hex, clinic_hex], [claim_hex], payload,
                                         wait=wait,
                                         auth_user=auth_user,
                                         auth_password=auth_password)
    def list_claims(self, auth_user=None, auth_password=None):
        claim_list_prefix = helper.make_claim_list_address()

        result = self._send_request(
            "state?address={}".format(claim_list_prefix),
            auth_user=auth_user,
            auth_password=auth_password)
        orders = {}

        try:
            data = yaml.safe_load(result)["data"]
            if data is not None:
                for value in data:
                    dec_ord = base64.b64decode(value["data"])
                    o = payload_pb2.CreateClaim()
                    o.ParseFromString(dec_ord)
                    orders[value["address"]] = o

        except BaseException:
            pass

        return orders