An open API service indexing awesome lists of open source software.

https://github.com/zdavatz/oddb2xml

oddb2xml, create xml files using refdata, swissmedic and bag xml files
https://github.com/zdavatz/oddb2xml

bag data drug open refdata ruby source swissmedic switzerland xml

Last synced: 16 days ago
JSON representation

oddb2xml, create xml files using refdata, swissmedic and bag xml files

Awesome Lists containing this project

README

          

# oddb2xml

[![Build Status](https://github.com/zdavatz/oddb2xml/workflows/Ruby/badge.svg)](https://github.com/zdavatz/oddb2xml/actions)

* oddb2xml -a nonpharma -o fi

creates the following xml files:

* oddb_substance.xml
* oddb_limitation.xml
* oddb_interaction.xml
* oddb_code.xml
* oddb_product.xml
* oddb_article.xml
* oddb_fi.xml
* oddb_fi_product.xml

and

* oddb2xml -f dat
* oddb2xml -f dat -a nonpharma

creates .dat files according to ([IGM-11](http://dev.ywesee.com/uploads/att/IGM.pdf)). IGM-11 describes the structure of the zurrose_transfer.dat.

* oddb.dat
* oddb_with_migel.dat

the files are using [Refdata](https://files.refdata.ch/simis-public-prod/Articles/1.0/Refdata.Articles.zip), [BAG-XML](http://bag.e-mediat.net/SL2007.Web.External/Default.aspx?webgrab=ignore) and [Swissmedic](http://www.swissmedic.ch/daten/00080/00251/index.html?lang=de) as sources.

The following additional data is in the files:

* [Wirkstoffe](http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip) (BAG XML)
* [Kühlkette](http://www.swissmedic.ch/daten/00080/00254/index.html?lang=de&download=NHzLpZeg7t,lnp6I0NTU042l2Z6ln1acy4Zn4Z2qZpnO2Yuq2Z6gpJCDdH57e2ym162epYbg2c_JjKbNoKOn6A--) (Swissmedic)
* [Orphan Drugs](http://www.swissmedic.ch/daten/00081/index.html?lang=de&download=NHzLpZeg7t,lnp6I0NTU042l2Z6ln1acy4Zn4Z2qZpnO2Yuq2Z6gpJCDdH55f2ym162epYbg2c_JjKbNoKSn6A--&.xls) (Swissmedic)
* [FI: de, fr](http://download.swissmedicinfo.ch) (Swissmedic)
* Limitation-Texte (BAG XML)
* Interaktionen [EPha.ch](http://epha.ch)
* [Betäubungsmittel](http://www.swissmedic.ch/produktbereiche/00447/00536/index.html?lang=de&download=NHzLpZeg7t,lnp6I0NTU042l2Z6ln1acy4Zn4Z2qZpnO2Yuq2Z6gpJCDdH1,fWym162epYbg2c_JjKbNoKSn6A--&.pdf) und psychotrope Stoffe (Swissmedic)
* Non-Pharma from Refdata and Suppliers (swissINDEX)

The top elements of all XML files have a SHA256 attribute over their content. The content corresponds to Nokogiris text method of the node which is essentially join by "\n" + some whitespaces of each element.
Consumers of the data file may use it to check whether they have to replace the corresponding nodes.

Generating files for Elexis Artikelstamm is discussed in the [Readme for the Artikelstamm](artikelstamm.md)

## usage

HIN (http://hin.ch) creates daily the actual file. They can be downloaded from `https://download.hin.ch/download/oddb2xml`, e.g. using `wget https://download.hin.ch/download/oddb2xml/oddb_article.xml`

see `--help`.

```
/opt/src/oddb2xml/bin/oddb2xml version 3.0.7
Usage:
oddb2xml [option]
produced files are found under data
-a, --append Additional target nonpharma
-r, --artikelstamm Create Artikelstamm Version 3 and 5 for Elexis >= 3.1
-c, --compress-ext= format F. {tar.gz|zip}
-e, --extended pharma, non-pharma plus prices and non-pharma from zurrose.
Products without EAN-Code will also be listed.
File oddb_calc.xml will also be generated
--fhir Use FHIR NDJSON format from FOPH/BAG instead of XML
from Spezialitätenliste. Downloads per-language
NDJSON files (de, fr, it) from epl.bag.admin.ch.
--fhir-url= Specific FHIR NDJSON URL to download (implies --fhir)
-f, --format= File format F, default is xml. {xml|dat}
If F is given, -o option is ignored. (Default: xml)
-i, --include Include target option for ean14 for 'dat' format.
'xml' format includes always ean14 records.
-I, --increment= Increment price by x percent. Forces -f dat -p zurrose.
create additional field price_resellerpub as
price_extfactory incremented by x percent (rounded to the next 0.05 francs)
in oddb_article.xml. In generated zurrose_transfer.dat PRPU is set to this price
Forces -f dat -p zurrose.
-o, --fi Optional fachinfo output.
-p, --price Price source (transfer.dat) from ZurRose
-t, --tag-suffix= XML tag suffix S. Default is none. [A-z0-9]
If S is given, it is also used as prefix of filename.
-x, --context= {product|address}. product is default. (Default: product)
-l, --calc create only oddb_calc.xml with GTIN, name and galenic information
-s, --skip-download skips downloading files it the file is already under downloads.
Downloaded files are saved under downloads
--log log important actions
-u, --use-ra11zip= Use the ra11.zip (a zipped transfer.dat from Galexis)
-b, --firstbase Build all NONPHARMA articles on firstbase
(GS1 Switzerland CSV from id.gs1.ch)
-v, --version Print version and exit
-h, --help Show this message
```

## Option examples

```
$ oddb2xml -t md # => md_article.xml, md_product.xml, md_substance.xml
$ oddb2xml -a nonpharma -t md -c tar.gz # => md_xml_dd.mm.yyyy_hh.mm.tar.gz
$ oddb2xml -f dat # => oddb.dat
$ oddb2xml -f dat -a nonpharma # => oddb_with_migel.dat
$ oddb2xml -e # => oddb_article.xml
```

output.

```
$ oddb2xml
DE
Pharma products: 14801
FR
Pharma products: 14801
```

## Supported ruby version

You will need ruby >= 2.5 to work correctly. Current development happens on Ruby 3.3 (`.ruby-version`).
CI runs on Ruby 3.0, 3.1 and 3.2 via GitHub Actions — see the badge above for the latest spec results.

## XSD files

The file oddb2xml.xsd was manually created by merging the output of the xmlbeans tools inst2xsd and trang

* http://xmlbeans.apache.org/docs/2.0.0/guide/tools.html#inst2xsd
* http://www.thaiopensource.com/relaxng/trang.html

Running rake spec will validated the XML-files generated during the tests using the Nokogiri validator.
We have two XSD files. One for oddb_calc.xml and one for the rest.

Manually you can also validate (assuming that you have installed the xmlbeans tools) all generated XML-files using

* xsdvalidate oddb_calc.xsd oddb_article.xml oddb_calc.xml
* xsdvalidate oddb2xml.xsd oddb_article.xml oddb_code.xml oddb_interaction.xml oddb_product.xml oddb_substance.xml

## XML files

xml files generated are:

* oddb_substance.xml
* oddb_limitation.xml
* oddb_interaction.xml
* oddb_code.xml
* oddb_product.xml
* oddb_article.xml
* oddb_fi.xml
* oddb_fi_product.xml

### article.xml

oddb2xml creates article.xml as oddb_article.xml by default.

```


1
2731179
D
16105058
161051
2
A
N
N
HIRUDOID Creme 3 mg/g 40 g
HIRUDOID crème 3 mg/g 40 g
HIRUDOID CREME 3 MG/G 40 G
HIRUDOID CRèME 3 MG/G 40 G
Hirudoid
Hirudoid
2

7601001002258


E13
7680161050583
A


PEXF
4.768575


PPUB
8.8


ZURROSE
4.77


ZURROSEPUB
8.80


10


...

OK
14801


```

### product.xml

For example, if `-t _swiss` is given then oddb2xml creates product.xml as swiss_product.xml.

```


7680353660163
353661
KENDURAL Depottabl 30 Stk
KENDURAL cpr dépot 30 pce
B03AE10
06.07.1.


0
5
105
mg


1
1
500
mg


30
Tablette(n)
ferrum(II), acidum ascorbicum
ferrum(II) 105 mg ut ferrosi sulfas dessiccatus, acidum ascorbicum 500 mg ut natrii ascorbas, color.: E 124, excipiens pro compresso obducto.

...

OK
14336


```

### substance.xml

product.xml has relation to substance as ``.

```


1
Acidum ascorbicum (Vitamin C, E300)


2
Alprostadilum

...

OK
1441


```

## Data sources

We use the following files:

* https://www.swissmedic.ch/arzneimittel/00156/00221/00222/00230/index.html?lang=de (Präparateliste und zugelassene Packungen)
* https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/interactions_de_utf8.csv
* https://files.refdata.ch/simis-public-prod/Articles/1.0/Refdata.Articles.zip
* http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip
* https://www.medregbm.admin.ch/Publikation/CreateExcelListBetriebs
* https://www.medregbm.admin.ch/Publikation/CreateExcelListMedizinalPersons
* http://zurrose.com/fileadmin/main/lib/download.php?file=/fileadmin/user_upload/downloads/ProduktUpdate/IGM11_mit_MwSt/Vollstamm/transfer.dat
* https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/NON-Pharma.xls
* http://download.swissmedicinfo.ch/ (AipsDownload)
* https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/LPPV.txt
* https://raw.githubusercontent.com/zdavatz/cpp2sqlite/master/input/atc_codes_multi_lingual.txt
* https://epl.bag.admin.ch/static/fhir/foph-sl-export-latest-{de,fr,it}.ndjson (FHIR NDJSON, used with `--fhir`)
* https://id.gs1.ch/01/07612345000961 (GS1 Switzerland firstbase CSV — full barcode registry, used with `-b`/`--firstbase`)

## Indikationscode (BAG XXXXX.NN)

In `--fhir` mode, oddb2xml extracts the BAG **Indikationscode** for SL
price-model drugs and emits one repeated `` child per
indication on each `` in `oddb_product.xml`:

```xml

7680123456789
...
In Kombination mit Paclitaxel für die Behandlung ...
In Kombination mit FOLFIRI ...
...

```

The code is built per FHIR bundle by combining the
`FOPHDossierNumber` from the reimbursement `RegulatedAuthorization`
(`XXXXX`) with the `.NN` suffix of each sibling
`ClinicalUseDefinition` whose `type == "indication"` (e.g.
`CYRAMZA.01` / `CYRAMZA.02` → `20403.01` / `20403.02`). The element
body carries the human-readable indication text from
`indication.diseaseSymptomProcedure.concept.text`.

The same data is also exposed in-memory on each item and package as
`item[:indication_codes]` (an array of `{code:, cud_id:, text:}`
hashes) for downstream consumers that build their own emitters.

Counted on the live FOPH feed (`foph-sl-export-latest-de.ndjson`,
6'775 bundles): **539** products carry a total of **1'293** codes.

Per BAG Rundschreiben vom 19. Februar 2026, the Indikationscode must
be transmitted with every prescription and invoice for SL price-model
drugs from **2026-07-01**; from **2027-01-01** insurers may reject
invoices without it. See issue
[#113](https://github.com/zdavatz/oddb2xml/issues/113).

## Refdata data-quality compensation

Refdata.Articles.xml from `files.refdata.ch` ships with a number of recurring
data-quality issues that propagate into downstream systems unchanged. oddb2xml
applies a small set of conservative cleanups before emitting any output. See
GitHub issue [#112](https://github.com/zdavatz/oddb2xml/issues/112) for the
full catalogue and the parallel report sent to Refdata.

Currently active fixes (`lib/oddb2xml/refdata_cleanup.rb`):

* **Doubled dose token** — Refdata sometimes emits the strength twice in
``, e.g. `MIRTAZAPIN Sandoz eco 30 mg / 30 mg / 100 Tablette`.
When the matching Swissmedic entry shows a single active substance, the
duplicate token is collapsed to a single occurrence. Real combination
products (e.g. PHESGO 600 mg / 600 mg / 10 ml — pertuzumab + trastuzumab)
are detected via the comma in `substance_swissmedic` and left untouched.

The cleanup runs at the start of `prepare_articles` in `Builder` and is
idempotent. Each rule is guarded by a Swissmedic-side heuristic so genuine
data is never altered.

## Rules for matching GTIN (aka EAN13), product number and IKSNR

For drugs which appear in Packungen.xlsx file published by Swissmedic the following rule is used to create the GTIN
* First 4 digits identify SwissMedic and are fixed to 7680
* next 5 digits corresponding to IKSNR (authorization) number
* next 3 digits corresponding to Packungscode
* last digit is checksum

The product number is calculated as
* 5 digits corresponding to IKSNR (authorization) number
* 2 digits corresponding to Dosisstärke (aka sequence number)

In oddb_article.xml you find
* GTIN is found as "BC" inside "ARTBAR"
* The product number as field PRODNO

Example given. For the IKSNR 48305 sequence number 1 named "Felden, Gel" with Packungscode "024" we get GTIN 7680483050247 and a product number 483051.

## SSLv3 cert for Windows Users

Some websites need SSLv3 connection.
If you don't have these root CA files (x509), Please install these Certificates before running.
see [cURL Website](http://curl.haxx.se/ca/)

You can confirm wit `ruby -ropenssl -e 'p OpenSSL::X509::DEFAULT_CERT_FILE'`.

### Windows User: Making your SSL Certificate permanent via your PATH

1. Download this [cacert.pem](http://curl.haxx.se/ca/cacert.pem) (cURL) into your HOME directory.
* or directly select cacert.pem from your oddb2xml-x.x.x gems directory.
* tools/cacert.pem is bundled with the oddb2xml gem.
2. Then Choose Menu "Control Panel" > "System" > "Advanced system settings"
* This opens the "System Properties" Window.
3. Click "Advanced" Tab.
4. Click "Environment Variables" button.
5. Add set variable entry "SSL\_CERT\_FILE=%HOMEPATH%\cacert.pem"
* Variable name: SSL\_CERT\_FILE
* Variable value: %HOMEPATH%\cacert.pem
* with "New..." button into upper are "User variables for xxx"
6. Do not remove this cacert.pem. All SSLv3 connections use this file.

### win_fetch_cacerts.rb
You can also run

* tools/win_fetch_cacerts.rb

for your currently open Terminal to download and set the Certificate.

## Testing

* Calling rake spec runs spec tests.
* Calling rake test installs the gems and runs oddb2xml with the most commonly used combinations. All output is placed under under ausgabe/. These files should be manually compared to the ones generated by the last release to check for possible problems.
* we use the gem VCR to record real HTTP responses.
** Removing the directory fixtures and running @bundle exec rspec spec/downloader_spec.rb@ gets the actual content from the different servers
** To minimize the downloaded size we use several @before_record@ hooks to select the desired content, eg. only the 5 items from EPha.