Skip to main content

A module to read german health insurance cards with python

Project description

https://img.shields.io/badge/code%20style-black-000000.svg https://github.com/Blueshoe/python-healthcard/actions/workflows/lint.yml/badge.svg

This package aims to provide a simple way to read smart cards (healthcards from) the German health insurance system.

It is based off of this repo: https://github.com/asdil12/python-egk/

Installation

Simply install the package via pip:

pip install python-healthcard

Usage

HealthCardReader

The usage a pretty straightforward.

from healthcard.reader import HealthCardReader

reader = HealthCardReader()
healthcard = reader.get_health_card()

print(healthcard.patient.first_name)
Max

The HealthCardReader object is automatically looking for a card reader. If there are multiple card readers available it uses the first one be default. This behavior can be changed however:

# change the index of the used reader
reader = HealthCardReader(index=1)

# or instantiate a cardservice yourself
from smartcard.CardType import ATRCardType
from smartcard.CardRequest import CardRequest
from smartcard.util import toHexString, toBytes
cardtype = ATRCardType( toBytes( "3B 16 94 20 02 01 00 00 0D" ) )  # just an example APDU
cardrequest = CardRequest( timeout=1, cardType=cardtype )
cardservice = cardrequest.waitforcard()

# This example code is taken from https://pyscard.sourceforge.io/user-guide.html
reader = HealthCardReader(cardservice=cardservice)

There are currently 3 versions of healthcards defined: G1, G1plus and G2.

The package automatically detects the version and reads the data accordingly.

HealthCard

The HealthCard object provides a simple interface to access insurance and patient data:

healthcard.patient  # Patient object
healthcard.insurance  # Insurance object
healthcard.version  # G1, G1plus or G2

It provides 2 JSON formatted outputs - a flattened as well as a hierarchical one:

healthcard.to_json()
# and
healthcard.to_flattened_json()

Patient

The Patient object contains the personal data of the healthcard:

patient.first_name
patient.insurant_id
patient.birthdate
patient.first_name
patient.last_name
patient.gender
patient.prefix
patient.name_addition
patient.title

# depends on version
patient.postal_address
# or
patient.residential_address

PostalAddress

address.city
address.zip_code
address.country_code
address.zip_code
address.mailbox

ResidenceAddress

address.city
address.zip_code
address.country_code
address.city
address.street
address.street_number
address.address_addition

Insurance

This object only contains the name of the insurance.

insurance.insurance_name

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-healthcard-1.0.5.tar.gz (13.3 kB view hashes)

Uploaded Source

Built Distribution

python_healthcard-1.0.5-py3-none-any.whl (14.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page