def _get_status(self, batch_id, wait, auth_user=None, auth_password=None):
     try:
         result = self._send_request(
             'batch_statuses?id={}&wait={}'.format(batch_id, wait),
             auth_user=auth_user,
             auth_password=auth_password)
         return yaml.safe_load(result)['data'][0]['status']
     except BaseException as err:
         raise HealthCareException(err)
    def _send_request(self,
                      suffix,
                      data=None,
                      content_type=None,
                      name=None,
                      auth_user=None,
                      auth_password=None):
        if self._base_url.startswith("http://"):
            url = "{}/{}".format(self._base_url, suffix)
        else:
            url = "http://{}/{}".format(self._base_url, suffix)

        headers = {}
        if auth_user is not None:
            auth_string = "{}:{}".format(auth_user, auth_password)
            b64_string = base64.b64encode(auth_string.encode()).decode()
            auth_header = 'Basic {}'.format(b64_string)
            headers['Authorization'] = auth_header

        if content_type is not None:
            headers['Content-Type'] = content_type

        try:
            if data is not None:
                result = requests.post(url, headers=headers, data=data)
            else:
                result = requests.get(url, headers=headers)

            if result.status_code == 404:
                raise HealthCareException("No such operator: {}".format(name))

            elif not result.ok:
                raise HealthCareException("Error {}: {}".format(
                    result.status_code, result.reason))

        except requests.ConnectionError as err:
            raise HealthCareException(
                'Failed to connect to {}: {}'.format(url, str(err)))

        except BaseException as err:
            raise HealthCareException(err)

        return result.text
    def __init__(self, base_url, keyfile=None):

        self._base_url = base_url

        if keyfile is None:
            self._signer = None
            return

        try:
            with open(keyfile) as fd:
                private_key_str = fd.read().strip()
        except OSError as err:
            raise HealthCareException(
                'Failed to read private key {}: {}'.format(
                    keyfile, str(err)))

        try:
            private_key = Secp256k1PrivateKey.from_hex(private_key_str)
        except ParseError as e:
            raise HealthCareException(
                'Unable to load private key: {}'.format(str(e)))

        self._signer = CryptoFactory(create_context('secp256k1')) \
            .new_signer(private_key)
Пример #4
0
def do_list_patients(args):
    url = _get_url(args)
    auth_user, auth_password = _get_auth_info(args)

    client = HealthCareClient(base_url=url, keyfile=None)

    patient_list = client.list_patients(auth_user=auth_user,
                                        auth_password=auth_password)

    if patient_list is not None:
        fmt = "%-15s %-15s %-15s %-15s"
        print(fmt % ('PATIENT HEX', 'NAME', 'SURNAME', 'PUBLIC_KEY'))
        for key, value in patient_list.items():
            print(fmt % (key, value.name, value.surname, value.public_key))
    else:
        raise HealthCareException("Could not retrieve patient listing.")
Пример #5
0
def do_list_doctors(args):
    url = _get_url(args)
    auth_user, auth_password = _get_auth_info(args)

    client = HealthCareClient(base_url=url, keyfile=None)

    doctors_list = client.list_doctors(auth_user=auth_user,
                                       auth_password=auth_password)

    if doctors_list is not None:
        fmt = "%-15s %-15s %-15s"
        print(fmt % ('NAME', 'SURNAME', 'PUBLIC_KEY'))
        for doctor in doctors_list:
            print(fmt % (doctor.name, doctor.surname, doctor.public_key))
    else:
        raise HealthCareException("Could not retrieve doctors listing.")
Пример #6
0
def do_list_claims(args):
    url = _get_url(args)
    auth_user, auth_password = _get_auth_info(args)

    client = HealthCareClient(base_url=url, keyfile=None)

    claims_list = client.list_claims(auth_user=auth_user,
                                     auth_password=auth_password)

    if claims_list is not None:
        fmt = "%-15s %-15s %-15s %-15s"
        print(fmt % ('CLAIM HEX', 'CLAIM ID', 'CLINIC PKEY', 'PATIENT PKEY'))
        for key, value in claims_list.items():
            print(fmt %
                  (key, value.claim_id, value.clinic_pkey, value.patient_pkey))
    else:
        raise HealthCareException("Could not retrieve claims listing.")
Пример #7
0
def main(prog_name=os.path.basename(sys.argv[0]), args=None):
    if args is None:
        args = sys.argv[1:]
    parser = create_parser(prog_name)
    args = parser.parse_args(args)

    if args.verbose is None:
        verbose_level = 0
    else:
        verbose_level = args.verbose

    setup_loggers(verbose_level=verbose_level)

    if args.command == 'create_clinic':
        do_create_clinic(args)
    elif args.command == 'create_claim':
        do_create_claim(args)
    elif args.command == 'create_doctor':
        do_create_doctor(args)
    elif args.command == 'create_patient':
        do_create_patient(args)
    elif args.command == 'assign_doctor':
        do_assign_doctor(args)
    elif args.command == 'pass_tests':
        do_pass_tests(args)
    elif args.command == 'attend_procedures':
        do_attend_procedures(args)
    elif args.command == 'eat_pills':
        do_eat_pills(args)
    elif args.command == 'next_visit':
        do_next_visit(args)
    elif args.command == 'first_visit':
        do_first_visit(args)
    elif args.command == 'list_clinics':
        do_list_clinics(args)
    elif args.command == 'list_doctors':
        do_list_doctors(args)
    elif args.command == 'list_patients':
        do_list_patients(args)
    elif args.command == 'list_claims':
        do_list_claims(args)
    elif args.command == 'list_claim_details':
        do_list_claim_details(args)
    else:
        raise HealthCareException("invalid command: {}".format(args.command))
Пример #8
0
def do_list_claim_details(args):
    clinic_pkey = args.clinic_pkey
    claim_id = args.claim_id
    url = _get_url(args)
    auth_user, auth_password = _get_auth_info(args)

    client = HealthCareClient(base_url=url, keyfile=None)

    claim_details_list = client.list_claim_details(claim_id,
                                                   clinic_pkey,
                                                   auth_user=auth_user,
                                                   auth_password=auth_password)

    if claim_details_list is not None:
        fmt = "%-15s %-15s %-15s %-15s %-15s %-15s"
        print(fmt % ('EVENT HEX', 'CLAIM ID', 'CLINIC PKEY', 'EVENT',
                     'DESCRIPTION', 'EVENT TIME'))
        for key, value in claim_details_list.items():
            print(fmt % (key, value.claim_id, value.clinic_pkey, value.event,
                         value.description, value.event_time))
    else:
        raise HealthCareException("Could not retrieve claim details listing.")