The doctor, the bill and the engine

Coralie Collignon
Doctolib
Published in
6 min readNov 16, 2021

As we head into fall, there’s one thing you’ll probably do during the cold season: go to the doctor. You might think that a doctor’s office is quite the opposite of a Tech world. Well, you’ll step into a world of API calls, SMTP protocols and a Rust certified billing engine.

If you are living in France, chances are you’ve walked out of your doctor’s office without paying anything. How can this happen? This article focuses on billing and what’s behind the scenes for billing with the health insurance services.

Paper bill — Feuille de soin papier
Paper bill (Feuille de soin papier)

Notes before starting:

  • In this article “Electronic Bill” refers to “Feuille de Soin Électronique” (Electronic care sheet). It is the electronic counterpart of the old paper version, and is normalized by the SESAM Vitale standard.
  • The SESAM Vitale standard is a set of specifications. The objective of the SESAM-Vitale system is to dematerialize the paper documents necessary for reimbursement of care (treatment sheets, billing sections, paper account, pharmaceutical labels, LPP label, etc.)
  • The Carte Vitale is a free and personal card that can be ordered. It’s valid everywhere in France and can be ordered from 15 years old.

1. The doctor’s setup

The health insurance cards & the card reader

Something that you usually bring with you for a consultation is your public insurance card (Carte Vitale). With this card, the practitioner can securely identify patients. In France, the Carte Vitale is your passport to the health costs’ reimbursement. It certifies your registration and your rights to health public insurance.

In order to be able to read your Carte Vitale, the doctor can use the Doctolib card reader hardware. It communicates via Bluetooth (for phone) or via a USB cable (for computer). In the card reader, the doctor has already introduced his own card, the CPS (Carte de Professionnel de Santé, Healthcare professional card). We’ll learn more about its purpose later.

On desktop and mobile

The doctor probably works with our practice management system. If so, he uses Doctolib Practice for billing. It runs in Doctolib Desktop Version, an Electron application, on desktop and in React Native WebView on mobile for home visiting. Both technologies communicate with our certified billing engine, Billeo. At Doctolib, a Rails monolith is used for all the codebase. Except for the billing, as it is very specific and needs to comply with certifications.

Billeo, a certified billing engine

This back-end engine is a server written in Rust. It communicates both with the card reader, via C libraries, the public (Assurance Maladie Obligatoire) and private (Assurance Maladie Complémentaire) health insurance services in order to create and send electronic bills for each consultation.

The billing engine complies with SESAM Vitale standard specifications: it’s currently certified Addendum 7 for desktop; DI 3.93 for mobile devices.

Billeo engine

2. Electronic bill creation

During the consultation, the doctor can

  • either do a paper bill. The patient would have to pay the fees, and be reimbursed later by the health insurance
  • or generate an electronic bill. The patient won’t have to pay fees if the doctor does the third-party payment with teletransmission
Third-party payment

There are 5 steps to create an electronic bill: reading the CPS, reading the Carte Vitale, specifying the billing context (the reason why you’re visiting the doctor), specifying the medical act, signing.

Reading the cards: identifying the parties (steps 1 and 2)

In the initial setup of the software, the doctor configured his billing situation using his CPS. The first time he does an action for billing, a PIN code (code porteur) is asked by Billeo to confirm his identity. Billeo then retrieves the patient data from the Carte Vitale. This includes his identity information, social security number, health insurance plan, the identity of people attached to the card, and whether or not the patient is exempt from having to pay for the consultation.

What if you forget your Carte Vitale? The doctor can make an ADRi (Acquisition des DRoits intégrée) API call to the public health insurance service with your social security number only.

Billing context and medical act: creating valid bills through the user interface (steps 3 and 4)

In Doctolib Desktop Version, the doctor fills in information about the consultation. This includes why and which type of care was provided.

Our mission is to make the application as simple as possible to use so the doctors save time. For instance, through the user interface (UI), some fields are prefilled using information taken from the last bill for the same patient. The SESAM Vitale specifications regulate most of the information we provide in the software. Some fields (for example “Is it an accident of common law or of private life?” — “Est-ce un accident de droit commun ou de la vie privée ?”) must be manually filled by the doctor for each consultation as part of the certification.

By default, we offer a simplified view. There is an advanced view for complex bills that can be dynamically enabled if the doctor gives certain answers. A Q&A occurs under the hood between the billing engine and the front-end, checking for potential errors and missing elements. When the doctor answers a question, it’s sent to Billeo to check that the combination of all answers leads to a valid bill. The doctor can’t generate a bill until the status is valid.

Then, the doctor fills in information about payment: whether he applies third-party payment and final cost.

Signing (step 5)

The last step before teletransmitting to the health insurance services is securing the bill through a signature. There are several levels for securing it. The highest needs the two physical cards. With the combination of the Carte Vitale and the CPS in the reader, the bill is “SESAM Vitale secured”.

If you forget your Carte Vitale, securing the bill would be in degraded mode (paper bill has to be sent) or “SESAM sans vitale” (for teleconsultation).

3. Electronic bill teletransmission

This part is important because it’s what makes a reimbursement possible in case of third-party payment! The bill is sent to public (Assurance Maladie Obligatoire) and private (Assurance Maladie Complémentaire) health insurance services.

The teletransmission is done in 4steps:

  1. Formatting the bill by the doctor, in a format called “B2” which is the invoice format used by the health insurance. This step includes signing the invoice with the Carte Vitale and the CPS.
  2. The latest bills sent by the doctor are grouped together and formatted by batch.
  3. The batches are grouped by health fund, which depends on the patient’s address.
  4. The bills are teletransmitted as signed and encrypted attachments of a S/MIME message envelope using SMTP protocol.

The doctor is informed a few days later by the health insurance services of the payment status of each bill. If a bill is rejected, they provide an error code to specify the rejection reason.

The billing flow chart

Conclusion

Billing at the doctor is a key piece of a consultation. It contributes to making healthcare more accessible to all in France. It’s technically rich as we need to integrate official specifications, make the software easy to use for our doctors and communicate with health insurance services to manage third party paiement.

💙 I’d like to thank the three teams working on Billing for contributing to this article:

  • BUX (Billing User Experience) for the React front-end
  • BICS (BIlling Compliance and Scaling) and BIPX (BIlling eXperience) for the Rust backend (Billeo)

📖 If you want more technical news, follow our journey through our docto-tech-life newsletter.

Open positions: And if you want to join us in transforming the healthcare system, we are hiring talented people to grow our tech and product team (the Billing team is also hiring in Niort 🙌)

--

--