The SFM migration data format
File structure
The exported data is stored as files in an export folder and sub-folders for pasients and reports.
The following files are exported:
- Organization file (non-patient data). A single encrypted and compressed (zip) XML file. Contains organizations, users, local medication templates etc.. Organization data is stored in the export folder.
- Index file (Index.txt). A text file containing relative path to all exported patients. The index file is stored in the export folder.
- Patient files. A patient file si an encrypted and compressed (zip) file which contains pasient data XML file and possible several message files. The patient data XML file contains patient data such as personal information, medication treatments, allergies etc.. The patient file is stored in the Patient folder.
- Report files. Several encrypted files may be stored in the Report folder.
Due to technical reasons, each folder can contain no more than 16.000 patient files, so therefore, multiple sub-folders may be needed if the EHR database contains information for more than 16.000 patients. The folders will be named "Patients0", "Patients1", "Patients2", etc
The same applies to report files.
Organization file (non-patient data)
A single encrypted and compressed (zip) XML file containing all non-patient related data is stored in the export folder. The name of the file is ExportData.dat
Patient files
Patient files The Patient folder(s) contains one compressed and encrypted file for each exported patient.
The patient file for each patient contains the following files:
- Patient data is stored in a single xml file.
- Each message file in the message history (M1, M2, etc.) for the patient is saved as a separate xml file.
The procedure for exporting data for a single patient are as follows:
Build the PasientExport xml structure for patient related data and save this in a separate file named “PatientData.xml” in a an empty temporary folder.
Save each message file in the message history for the patient into the temporary folder. The file name is the message id of the message, where this exists (e.g. MsgHead/AppRec messages). For other messages, the file name will be auto-generated GUID. The file name is referenced in the PatientExport XML structure (PasientExport/Meldinger/Melding/MeldingsFil).
Package the files created in steps 1-2 into a zip archive
Delete the original files created in steps 1-2.
Encrypt the zip file created in step 3. The name of the compressed and encrypted patient file will be the internal patient GUID, with a file extension ".pat" (e.g. "d8a7ead8-aa42-4d90-9eaf-7e770e6c8ab3.pat").
Move the patient file to the patient data export folder (creating a new folder if needed)
Report files
The Report folder(s) contains one encrypted XPS file for each exported report.
The XPS is a compressed file, so there is no need to compress it before encrypting.
The file name is referenced in the ExportImport XML structure: ExportImport/Rapporter/Rapport/RapportFil.
Encryption of files
In order to export data, you must have a certificate that contains the public key that will be used for the encryption. This certificate can be downloaded from the Address Register. It is available under the service Sentral Forskrivningsmodul, SFM Migrering.
The encryption is based on this Microsoft example: Walkthrough: Create a Cryptographic Application
The files are encrypted with AES256.
The encryption package uses the following format:
- Key length, bytes 0 - 3
- IV length, bytes 4 - 7
- file extension length bytes 8-11
- Encrypted key
- IV
- file extension
- Cipher text
The elements in bold are not a part of the Microsoft example.
Definition and examples
The formal definition of the format, as well as examples may be downloaded from NHN public github: NHN Githib - SFM Data Migration