Package: linuxforhealth-csvtofhir
CSV to FHIRLoads CSV records from file, and maps them to FHIR resources.Pre-requisitesPython>= 3.9 for application developmentQuickstart CLIOS X / Linux# clone the repogitclonehttps://github.com/LinuxForHealth/CsvToFHIR.gitcdCsvToFHIR# create virtual environment and create an "editable" installpython3-mvenvvenv--clear&&\sourcevenv/bin/activate&&\python3-mpipinstall--upgradepipsetuptoolswheelpython3-mpipinstall-e.[dev]# run testspython3-mpytestWindows SetupLaunch the Windows Command and "Run as Administrator"# clone the repogitclonehttps://github.com/LinuxForHealth/CsvToFHIR.gitcdCsvToFHIR# create the virtual environment (may take some time to complete)python-mvenvvenv--clear
.\venv\Scripts\activate
python-mpipinstall--upgradepipsetuptoolswheel# integrate the local development environment with the virtual environmentpython-mpipinstall-e".[dev]"Thepip installcommand for the local project will print a WARNING similar toWARNING:Thescriptcsvtofhir.exeisinstalledin'C:\Users\someuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts'whichisnotonPATH.

ConsideraddingthisdirectorytoPATHor,ifyouprefertosuppressthiswarning,use--no-warn-script-location.On Windows the csvtofhir CLI is "compiled" as an EXE and resides within a local cache directory. This directory must be
on the SYSTEM path in order to invoke csvtofhir without including the full path to the executable.To execute unit tests, simply run:python-mpytestOptimized Streaming SupportCsv To FHIR provides an optimized means of streaming files usingsmart_open. smart_open
supports streaming files from common cloud storage stores (AWS, Azure, GCS) as well as over common transfer protocols such
as HTTP, HTTPS, SFTP, HDFS, etc.To include smart_open, install the optimized-streaming extrapython-mpipinstall-e".[optimized-streaming]"CSVToFHIR CLIThe CLI supports:DataContract validationcsvtofhirvalidate-fdemo/config/data-contract.jsonCSV ConversionThe csvtofhir convert command has two processing modes, directory mode,-d, and file mode,-f.Directory ModeIndirectorymode the convert command is given a base directory path which contains the following subdirectories:input: where input, or source, data records are locatedconfig: where the CSVToFHIR data contract configuration, data-contract.json, and supporting files are located.The-oparameter is used to specify the location where output files are saved.csvtofhirconvert-ddemo-odemo/outputTheconvertutility creates a separate output directory for each unique patient record.File ModeInfilemode the convert command is provided a single file path to convert.
The-fflag is used to specify the input data file.
The-cflag is used to specify the configuration directory.
The-oflag is used in the same manner asdirectorymode.csvtofhirconvert-fdemo/input/patient.csv-cdemo/config-odemo/outputCode FormattingCSVToFHIR usesflake8for style checking andautopep8for formatting.
Flake8 is used to find and identify issues, while AutoPep8 will fix (most of) them.A simplified workflow to ensure uniform formatting is to . . .Run AutoPep8 against the source and test codepython3-mautopep8src/tests/--in-placeAnd then use Flake8 to find remaining issues, which will need to be manually addressed.python3-mflake8src/tests/Flake8 and AutoPep8 are configured usingsetup.cfgwithin theflake8section.In VS Code to format in the editor,- in-placemust be removed from the configuration.LoggingCSVToFHIR followsbest practicesfor logging configuration. Specifically,
the only handler supported is theNullHandler. This allows consuming applications and services to configure handlers as appropriate.The following table lists packages which emit logging information.PackagesDescriptioncsvtofhirCSVToFHIR converter entry pointcsvtofhir.fhirrsConverts CSV source records to FHIR Resourcescsvtofhir.pipelinePipeline tasks used to align source data with internal CSV modelsTo utilize logging within a local development environment, please review the comments within thesupport module.Optional Notebook SupportCsvToFhir includes optional support for using notebooks and visualization tools such asJupyterLab.To add notebook support run setup with the "notebook" extra:python3-mpipinstall-e.[notebook]Use the following commands to launch the notebook server# Windows Examplejupyter-lab--app_dir=src\--preferred_dir=notebooks\# Linux Examplejupyter-lab--app_dir=./src--preferred_dir=./notebooksAdditional DocumentationDataContract DesignImplementation GuideInternal Format GuideIDE ConfigurationContributing