diff --git a/docker/openemr/8.0.1/auto_import_codes.php b/docker/openemr/8.0.1/auto_import_codes.php new file mode 100644 index 00000000..ee9059d6 --- /dev/null +++ b/docker/openemr/8.0.1/auto_import_codes.php @@ -0,0 +1,120 @@ +#!/usr/bin/env php + + * @copyright Copyright (c) 2026 Luis M. Santos, MD + * @copyright Copyright (c) 2026 MedicalMasses L.L.C. + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ +$sitePath = '/var/www/localhost/htdocs/openemr'; +$_GET['site'] = 'default'; +$ignoreAuth = true; +$sessionAllowWrite = true; +chdir($sitePath); + +// Load OpenEMR's Composer autoloader +// This gives us access to all OpenEMR classes, including the Installer class +require_once 'interface/globals.php'; +require_once 'library/standard_tables_capture.inc.php'; + +function import_dir(string $type, $importFunction): void { + foreach (glob("*.zip") as $file) { + # Copy to temp + echo " [" . $type . "] Copying file => " . $file . "!\n"; + if (!temp_copy($file, $type)) { + error_log("Failed to copy " . $file . " of type " . $type); + return; + } + + # Unpack + echo " [" . $type . "] Uncompressing file => " . $file . "!\n"; + if (!temp_unarchive($file, $type)) { + error_log("Failed to unzip " . $file . " of type " . $type); + } + + # Import data + echo " [" . $type . "] Importing file => " . $file . "!\n"; + $importFunction($type); + + # Cleanup + echo " [" . $type . "] Cleaning up import for file => " . $file . "!\n"; + temp_dir_cleanup($type); + } +} + +function import_snomed(string $path): void { + // TODO: Consider including auto detection in OpenEMR at a later date. + try { + snomedRF2_import(); + } catch (Exception $e) { + try { + snomed_import(true); + } catch (Exception $e) { + snomed_import(); + } + } +} + +function import(string $path): void { + # Change to import directory + chdir($path); + + # Scan directory + $dirs = scandir('./'); + echo "Available directories => ". $dirs . "\n"; + foreach ($dirs as $dir) { + if ($dir == "." || $dir == "..") { + continue; + } + + if(is_dir($dir)) { + # Go into directory + echo "Entering directory => ". $dir . "\n"; + chdir($dir); + + match ($dir) { + "icd9" => import_dir("ICD9", function ($type) {icd_import($type);}), + "icd10" => import_dir("ICD10", function ($type) {icd_import($type);}), + "rxnorm" => import_dir("RXNORM", function () {rxnorm_import(false);}), + "snomed" => import_dir("SNOMED", function ($file) {import_snomed($file);}), + "cqm", "cqm_valueset" => import_dir("CQM_VALUESET", function ($type) {valueset_import($type);}), + default => import_dir("VALUESET", function ($type) {valueset_import($type);}), + }; + + # Restore parent path for the next iteration + echo "Exiting directory => ". $dir . " back to ". $path . "\n"; + chdir($path); + } + } +} + +// Ensure we're running from CLI +if (php_sapi_name() !== 'cli') { + throw RuntimeException('This tool can only be run from the command line'); +} + +$contribPath = realpath($sitePath . '/contrib'); +if ($argc > 1) { + if (strlen($argv[1])) { + $contribPath = realpath($argv[1]); + } +} + +import($contribPath); diff --git a/docker/openemr/flex/auto_import_codes.php b/docker/openemr/flex/auto_import_codes.php new file mode 100644 index 00000000..ee9059d6 --- /dev/null +++ b/docker/openemr/flex/auto_import_codes.php @@ -0,0 +1,120 @@ +#!/usr/bin/env php + + * @copyright Copyright (c) 2026 Luis M. Santos, MD + * @copyright Copyright (c) 2026 MedicalMasses L.L.C. + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ +$sitePath = '/var/www/localhost/htdocs/openemr'; +$_GET['site'] = 'default'; +$ignoreAuth = true; +$sessionAllowWrite = true; +chdir($sitePath); + +// Load OpenEMR's Composer autoloader +// This gives us access to all OpenEMR classes, including the Installer class +require_once 'interface/globals.php'; +require_once 'library/standard_tables_capture.inc.php'; + +function import_dir(string $type, $importFunction): void { + foreach (glob("*.zip") as $file) { + # Copy to temp + echo " [" . $type . "] Copying file => " . $file . "!\n"; + if (!temp_copy($file, $type)) { + error_log("Failed to copy " . $file . " of type " . $type); + return; + } + + # Unpack + echo " [" . $type . "] Uncompressing file => " . $file . "!\n"; + if (!temp_unarchive($file, $type)) { + error_log("Failed to unzip " . $file . " of type " . $type); + } + + # Import data + echo " [" . $type . "] Importing file => " . $file . "!\n"; + $importFunction($type); + + # Cleanup + echo " [" . $type . "] Cleaning up import for file => " . $file . "!\n"; + temp_dir_cleanup($type); + } +} + +function import_snomed(string $path): void { + // TODO: Consider including auto detection in OpenEMR at a later date. + try { + snomedRF2_import(); + } catch (Exception $e) { + try { + snomed_import(true); + } catch (Exception $e) { + snomed_import(); + } + } +} + +function import(string $path): void { + # Change to import directory + chdir($path); + + # Scan directory + $dirs = scandir('./'); + echo "Available directories => ". $dirs . "\n"; + foreach ($dirs as $dir) { + if ($dir == "." || $dir == "..") { + continue; + } + + if(is_dir($dir)) { + # Go into directory + echo "Entering directory => ". $dir . "\n"; + chdir($dir); + + match ($dir) { + "icd9" => import_dir("ICD9", function ($type) {icd_import($type);}), + "icd10" => import_dir("ICD10", function ($type) {icd_import($type);}), + "rxnorm" => import_dir("RXNORM", function () {rxnorm_import(false);}), + "snomed" => import_dir("SNOMED", function ($file) {import_snomed($file);}), + "cqm", "cqm_valueset" => import_dir("CQM_VALUESET", function ($type) {valueset_import($type);}), + default => import_dir("VALUESET", function ($type) {valueset_import($type);}), + }; + + # Restore parent path for the next iteration + echo "Exiting directory => ". $dir . " back to ". $path . "\n"; + chdir($path); + } + } +} + +// Ensure we're running from CLI +if (php_sapi_name() !== 'cli') { + throw RuntimeException('This tool can only be run from the command line'); +} + +$contribPath = realpath($sitePath . '/contrib'); +if ($argc > 1) { + if (strlen($argv[1])) { + $contribPath = realpath($argv[1]); + } +} + +import($contribPath);