Skip to content

Commit

Permalink
docs: zeros be gone - add information on how to sanitize Patient_ID (#…
Browse files Browse the repository at this point in the history
…189)

* docs: add information on how sanitize Patient_ID

closes #188

* docs: add sql syntax highlighting
  • Loading branch information
pcvolkmer authored Jul 18, 2024
1 parent 1480267 commit bc71206
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions docker-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,40 @@ SELECT * FROM (
SELECT YEAR(STR_TO_DATE(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), '%d.%c.%Y')) AS YEAR, versionsnummer AS VERSIONSNUMMER, lme.id AS ID, CONVERT(lme.xml_daten using utf8) AS XML_DATEN
FROM lkr_meldung_export lme
WHERE lme.typ != '-1' AND lme.versionsnummer IS NOT NULL AND lme.XML_DATEN LIKE '%ICD_Version%'
) o;
) o
```

To remove leading zeros from `Patient_ID` (see: https://github.com/bzkf/onco-analytics-on-fhir/issues/188), you could use the following query.
It will update `XML_DATEN` by replacing the attribute `Patient_ID` by using an `INT` if the value found can be casted into an integer but keeps the original value
if any other (e.g. alphanumeric value) is used and the cast will result in `0` value.

```sql
SELECT * FROM (
SELECT
YEAR(STR_TO_DATE(EXTRACTVALUE(lme.xml_daten, '//Diagnosedatum'), '%d.%c.%Y')) AS YEAR,
versionsnummer AS VERSIONSNUMMER,
lme.id AS ID,
CASE
# Patient_ID can be casted into number
WHEN CAST(EXTRACTVALUE(lme.xml_daten, '//Patienten_Stammdaten/@Patient_ID') AS INT) > 0
THEN CONVERT(
UPDATEXML(
lme.xml_daten,
'//Patienten_Stammdaten/@Patient_ID',
CONCAT('Patient_ID="', EXTRACTVALUE(lme.xml_daten, '//Patienten_Stammdaten/@Patient_ID'),'"')
) USING utf8
)
ELSE
# else fallback - do not touch Patient_ID
CONVERT(lme.xml_daten USING UTF8)
END AS XML_DATEN
FROM lkr_meldung_export lme
WHERE
typ != '-1'
AND versionsnummer IS NOT NULL
AND lme.XML_DATEN LIKE '%ICD_Version%'
AND EXTRACTVALUE(lme.xml_daten, '//ADT_GEKID/@Schema_Version') LIKE '2.%'
) o
```

If you are not using direct access to Onkostar MySQL/MariaDB database, you should use the following query that will fetch
Expand All @@ -81,7 +114,7 @@ SELECT * FROM (
JOIN lkr_meldung lm ON lme.lkr_meldung = lm.id
JOIN erkrankung e ON lm.erkrankung_id = e.id
WHERE lme.typ != '-1' AND lme.versionsnummer IS NOT NULL AND lme.XML_DATEN LIKE '%ICD_Version%'
) o;
) o
```

```sh
Expand Down

0 comments on commit bc71206

Please sign in to comment.