-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore) (HCT, HP, Covid): Use concept keys from the schema for better…
… configurability. (#1863) * use config keys in our json(hct) * implement the changes in hp and covid jsons * fix the missing concept * use the schema from the framework instead of importing manually
- Loading branch information
1 parent
4f8533d
commit 82ff232
Showing
22 changed files
with
331 additions
and
243 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export function extractSchemaValues(schema) { | ||
const result = {}; | ||
function traverse(obj) { | ||
Object.entries(obj).forEach(([key, value]) => { | ||
if (typeof value === 'object' && !Array.isArray(value)) { | ||
traverse(value); | ||
} else { | ||
result[key] = value; | ||
} | ||
}); | ||
} | ||
|
||
traverse(schema); | ||
return result; | ||
} | ||
|
||
export function replaceWithConfigDefaults(obj, configDefaults) { | ||
if (Array.isArray(obj)) { | ||
return obj.map((item) => { | ||
if (typeof item === 'string' && configDefaults.hasOwnProperty(item)) { | ||
return configDefaults[item]; | ||
} else { | ||
return replaceWithConfigDefaults(item, configDefaults); | ||
} | ||
}); | ||
} else if (typeof obj === 'object' && obj !== null) { | ||
const newObj = {}; | ||
for (const key in obj) { | ||
if (typeof obj[key] === 'string') { | ||
if (configDefaults.hasOwnProperty(key)) { | ||
// Case where UUID is the value | ||
newObj[configDefaults[key]] = obj[key]; | ||
} else if (configDefaults.hasOwnProperty(obj[key])) { | ||
// Case where UUID is the key | ||
newObj[key] = configDefaults[obj[key]]; | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} else { | ||
newObj[key] = replaceWithConfigDefaults(obj[key], configDefaults); | ||
} | ||
} | ||
return newObj; | ||
} else { | ||
return obj; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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.