-
Notifications
You must be signed in to change notification settings - Fork 183
[redcap] bulk importer #9808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
regisoc
wants to merge
30
commits into
aces:27.0-release
Choose a base branch
from
regisoc:20250522_redcap_bulk_import_script
base: 27.0-release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[redcap] bulk importer #9808
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1a6dc39
redcap config - load all config file
regisoc df7d062
redcap tool - bulk importer - draft
regisoc a7842ea
lint
regisoc f28abd7
lint
regisoc 0be46d1
lint
regisoc c49657a
generic include path
regisoc 7016b29
arg parse
regisoc b152c5a
candid str
regisoc bfaf8cb
db select query iterator to array
regisoc 046d2d7
array to query object
regisoc 9cc984e
lint
regisoc 1fc591b
mv tools to redcap module
regisoc 6e31301
query - loris instrument/commentIDs to be imported
regisoc a6b334a
queries
regisoc 0db9994
loris instrument to import to queries
regisoc f03fb51
trigger notifications fn
regisoc 1b662f7
rm override mention
regisoc e95a7e8
url path
regisoc 96d052b
guzzle exception mgmt
regisoc 549024b
lint
regisoc 44a3dda
queries method/parameters renaming
regisoc 4f6d65c
renaming
regisoc 6a6f500
importer - docstring types
regisoc e1fcb3a
lint - docstring test
regisoc 72f4ca1
lint - docstring test
regisoc 3ed3cc2
multiline docblock longtype test
regisoc 7fcc61f
multiline docblock longtype simplified types
regisoc be17705
phan neon redcap update
regisoc 07e09c7
phan neon redcap update
regisoc 50176a5
phan neon redcap update
regisoc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,4 +448,85 @@ class RedcapConfigParser | |
. " (redcap-project-id: {$this->_redcap_project_id}): $message" | ||
); | ||
} | ||
|
||
/** | ||
* Get the full REDCap configuration as described in 'config.xml' file. | ||
* Returns a struct ordered by REDCap instance and project. | ||
* Expected structure is: | ||
* [REDCap instance URL => [REDCap Project ID => REDCapConfig object]] | ||
* else null if no configurations are found. | ||
* | ||
* @param \LORIS\LorisInstance $loris the loris instance | ||
* | ||
* @throws \LorisException | ||
* | ||
* @return array<mixed|RedcapConfig|null>[] a REDCap configuration with the form | ||
* [REDCap instance URL => [REDCap Project ID => REDCapConfig object]] | ||
* else null | ||
*/ | ||
public static function getConfiguration( | ||
\LORIS\LorisInstance $loris | ||
): array { | ||
// final REDCap configuration struct | ||
$redcapConfig = []; | ||
|
||
// list of REDCap instances and projects | ||
$rawRedcapConfig = $loris->getConfiguration()->getSetting('redcap'); | ||
if ($rawRedcapConfig === null || empty($rawRedcapConfig)) { | ||
throw new \LorisException("No REDCap configuration."); | ||
} | ||
|
||
// instances, must at least have one | ||
$redcapInstances = $rawRedcapConfig['instance'] ?? null; | ||
if ($redcapInstances === null || empty($redcapInstances)) { | ||
throw new \LorisException( | ||
"No REDCap instance defined in configuration file." | ||
); | ||
} | ||
|
||
// only one instance, wrap it in an array to be able to iterate | ||
if (!array_key_exists(0, $redcapInstances)) { | ||
$redcapInstances = [$redcapInstances]; | ||
} | ||
|
||
// going throught REDCap defined instances | ||
foreach ($redcapInstances as $instanceStruct) { | ||
// instance URL | ||
$redcapInstanceURL = $instanceStruct['redcap-url']; | ||
|
||
// project of this instance | ||
$redcapProjects = $instanceStruct['project'] ?? null; | ||
if ($redcapProjects === null || empty($redcapProjects)) { | ||
// no project for that instance, next REDCap instance | ||
continue; | ||
} | ||
|
||
// only one project, wrap it in an array to be able to iterate | ||
if (!array_key_exists(0, $redcapProjects)) { | ||
$redcapProjects = [$redcapProjects]; | ||
} | ||
|
||
// add REDCap configuration | ||
foreach ($redcapProjects as $redcapProject) { | ||
// project ID | ||
$redcapProjectID = $redcapProject['redcap-project-id']; | ||
|
||
// parser object | ||
$configParser = new RedcapConfigParser( | ||
$loris, | ||
$redcapInstanceURL, | ||
$redcapProjectID | ||
); | ||
Comment on lines
+515
to
+519
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally I guess I should refactor the parser to more elegantly handle the "get all project configurations" and "get single project configuration" cases, but this is out of scope for this PR, your code is fine 👍 |
||
|
||
// add the parsed REDCap configuration to the final struct | ||
$redcapConfig[$redcapInstanceURL] = [ | ||
...$redcapConfig[$redcapInstanceURL] ?? [], | ||
$redcapProjectID => $configParser->parse() | ||
]; | ||
} | ||
} | ||
|
||
// return struct | ||
return empty($redcapConfig) ? null : $redcapConfig; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return type is too complex IMO. I would prefer to return a simple list of
RedcapConfig
. The caller can handle special cases like the empty list itself, and the instance URLs and project IDs are available in eachRedcapConfig
if needed.