-
Notifications
You must be signed in to change notification settings - Fork 87
O3-5253: Create flags domain in Initializer #309
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2ede6b7
Implement flags domain
brandones 569dac0
Add @Component to everything
brandones 826773d
Add patientflags to more POMs
brandones 798d558
Get tests working; work around non-nullable Priority style
brandones c93076b
Add patientflags to aware_of_module
brandones 080b0e7
README: add flags module compatibility & changelog line
brandones d31a140
Fix component names
brandones 9e80d04
Move flags from api-2.4/ to api/
brandones 7944189
Check for blank UUID before trying to load flag
brandones 07864ab
Merge branch 'main' into flags
brandones 307f572
Clean up merge, clean up extra POM references
brandones 0758495
Fix Flags version compatibility in README
brandones d408a9e
Use release version of patientflags 3.0.9
brandones 5048c87
Merge branch 'main' into flags
brandones c4b6356
Fix annotations so that patientflags module linking is optional
brandones 2952ab8
Cleanup
brandones 16d99b8
Cleanup test context stuff
brandones aa0b8eb
Merge remote-tracking branch 'origin/main' into flags
brandones 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
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
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
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
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
47 changes: 47 additions & 0 deletions
47
...src/main/java/org/openmrs/module/initializer/api/patientflags/DisplayPointListParser.java
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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package org.openmrs.module.initializer.api.patientflags; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.patientflags.DisplayPoint; | ||
| import org.openmrs.module.patientflags.api.FlagService; | ||
| import org.openmrs.module.initializer.api.utils.ListParser; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Parses a list of DisplayPoint identifiers (UUID or name) and fetches the corresponding | ||
| * DisplayPoint entities. | ||
| */ | ||
| @Component("initializer.flagDisplayPointListParser") | ||
| @OpenmrsProfile(modules = { "patientflags:3.* - 9.*" }) | ||
| public class DisplayPointListParser extends ListParser<DisplayPoint> { | ||
|
|
||
| private FlagService flagService; | ||
|
|
||
| @Autowired | ||
| public DisplayPointListParser(@Qualifier("flagService") FlagService flagService) { | ||
| this.flagService = flagService; | ||
| } | ||
|
|
||
| @Override | ||
| protected DisplayPoint fetch(String id) { | ||
| if (StringUtils.isBlank(id)) { | ||
| return null; | ||
| } | ||
|
|
||
| // Try UUID first | ||
| DisplayPoint displayPoint = flagService.getDisplayPointByUuid(id); | ||
| if (displayPoint != null) { | ||
| return displayPoint; | ||
| } | ||
|
|
||
| // Try name | ||
| displayPoint = flagService.getDisplayPoint(id); | ||
| if (displayPoint != null) { | ||
| return displayPoint; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
api/src/main/java/org/openmrs/module/initializer/api/patientflags/FlagsCsvParser.java
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package org.openmrs.module.initializer.api.patientflags; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.patientflags.Flag; | ||
| import org.openmrs.module.patientflags.api.FlagService; | ||
| import org.openmrs.module.initializer.Domain; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.openmrs.module.initializer.api.CsvParser; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Parses CSV files for Flag entities. | ||
| */ | ||
| @Component("initializer.flagFlagsCsvParser") | ||
| @OpenmrsProfile(modules = { "patientflags:3.* - 9.*" }) | ||
| public class FlagsCsvParser extends CsvParser<Flag, BaseLineProcessor<Flag>> { | ||
|
|
||
| private final FlagService flagService; | ||
|
|
||
| @Autowired | ||
| public FlagsCsvParser(@Qualifier("flagService") FlagService flagService, | ||
| @Qualifier("initializer.flagsLineProcessor") FlagsLineProcessor processor) { | ||
| super(processor); | ||
| this.flagService = flagService; | ||
| } | ||
|
|
||
| @Override | ||
| public Domain getDomain() { | ||
| return Domain.FLAGS; | ||
| } | ||
|
|
||
| @Override | ||
| public Flag bootstrap(CsvLine line) throws IllegalArgumentException { | ||
| String uuid = line.getUuid(); | ||
| Flag flag = null; | ||
| if (uuid != null && uuid != "") { | ||
| flag = flagService.getFlagByUuid(uuid); | ||
| } | ||
| if (flag == null) { | ||
| flag = new Flag(); | ||
| if (StringUtils.isNotBlank(uuid)) { | ||
| flag.setUuid(uuid); | ||
| } | ||
| } | ||
| return flag; | ||
| } | ||
|
|
||
| @Override | ||
| public Flag save(Flag instance) { | ||
| flagService.saveFlag(instance); | ||
| return instance; | ||
| } | ||
| } |
114 changes: 114 additions & 0 deletions
114
api/src/main/java/org/openmrs/module/initializer/api/patientflags/FlagsLineProcessor.java
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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package org.openmrs.module.initializer.api.patientflags; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.patientflags.Flag; | ||
| import org.openmrs.module.patientflags.Priority; | ||
| import org.openmrs.module.patientflags.Tag; | ||
| import org.openmrs.module.patientflags.api.FlagService; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Processes CSV lines for Flag entities. | ||
| */ | ||
| @Component("initializer.flagsLineProcessor") | ||
| @OpenmrsProfile(modules = { "patientflags:3.* - 9.*" }) | ||
| public class FlagsLineProcessor extends BaseLineProcessor<Flag> { | ||
|
|
||
| protected static final String HEADER_CRITERIA = "criteria"; | ||
|
|
||
| protected static final String HEADER_EVALUATOR = "evaluator"; | ||
|
|
||
| protected static final String HEADER_MESSAGE = "message"; | ||
|
|
||
| protected static final String HEADER_PRIORITY = "priority"; | ||
|
|
||
| protected static final String HEADER_ENABLED = "enabled"; | ||
|
|
||
| protected static final String HEADER_TAGS = "tags"; | ||
|
|
||
| private FlagService flagService; | ||
|
|
||
| private TagListParser tagListParser; | ||
|
|
||
| @Autowired | ||
| public FlagsLineProcessor(@Qualifier("flagService") FlagService flagService, | ||
| @Qualifier("initializer.flagTagListParser") TagListParser tagListParser) { | ||
| this.flagService = flagService; | ||
| this.tagListParser = tagListParser; | ||
| } | ||
|
|
||
| @Override | ||
| public Flag fill(Flag flag, CsvLine line) throws IllegalArgumentException { | ||
| flag.setName(line.get(HEADER_NAME, true)); | ||
| flag.setDescription(line.get(HEADER_DESC)); | ||
|
|
||
| // Required fields | ||
| flag.setCriteria(line.get(HEADER_CRITERIA, true)); | ||
| flag.setEvaluator(line.get(HEADER_EVALUATOR, true)); | ||
| flag.setMessage(line.get(HEADER_MESSAGE, true)); | ||
|
|
||
| // Optional priority | ||
| String priorityId = line.getString(HEADER_PRIORITY, ""); | ||
| if (StringUtils.isNotBlank(priorityId)) { | ||
| Priority priority = fetchPriority(priorityId); | ||
| if (priority == null) { | ||
| throw new IllegalArgumentException( | ||
| "The priority referenced by '" + priorityId + "' does not point to any known priority."); | ||
| } | ||
| flag.setPriority(priority); | ||
| } else { | ||
| flag.setPriority(null); | ||
| } | ||
|
|
||
| // Optional enabled flag (defaults to true if not specified) | ||
| String enabledStr = line.getString(HEADER_ENABLED, ""); | ||
| if (StringUtils.isNotBlank(enabledStr)) { | ||
| flag.setEnabled(Boolean.parseBoolean(enabledStr.trim())); | ||
| } else { | ||
| flag.setEnabled(true); // Default to enabled | ||
| } | ||
|
|
||
| // Optional tags | ||
| String tagsStr = line.getString(HEADER_TAGS, ""); | ||
| if (StringUtils.isNotBlank(tagsStr)) { | ||
| Set<Tag> tags = new HashSet<Tag>(tagListParser.parseList(tagsStr)); | ||
| flag.setTags(tags); | ||
| } else if (flag.getTags() != null) { | ||
| // Clear tags if not specified (only if tags were previously set) | ||
| flag.getTags().clear(); | ||
| } | ||
|
|
||
| return flag; | ||
| } | ||
|
|
||
| /** | ||
| * Fetches a Priority by UUID or name. | ||
| */ | ||
| private Priority fetchPriority(String id) { | ||
| if (StringUtils.isBlank(id)) { | ||
| return null; | ||
| } | ||
|
|
||
| // Try UUID first | ||
| Priority priority = flagService.getPriorityByUuid(id); | ||
| if (priority != null) { | ||
| return priority; | ||
| } | ||
|
|
||
| // Try name | ||
| priority = flagService.getPriorityByName(id); | ||
| if (priority != null) { | ||
| return priority; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
api/src/main/java/org/openmrs/module/initializer/api/patientflags/FlagsLoader.java
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.openmrs.module.initializer.api.patientflags; | ||
|
|
||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.patientflags.Flag; | ||
| import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Loads Flags from CSV files. | ||
| */ | ||
| @Component("initializer.flagFlagsLoader") | ||
| @OpenmrsProfile(modules = { "patientflags:3.* - 9.*" }) | ||
| public class FlagsLoader extends BaseCsvLoader<Flag, FlagsCsvParser> { | ||
|
|
||
| @Autowired | ||
| public void setParser(FlagsCsvParser parser) { | ||
| this.parser = parser; | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
api/src/main/java/org/openmrs/module/initializer/api/patientflags/PrioritiesCsvParser.java
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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package org.openmrs.module.initializer.api.patientflags; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.annotation.OpenmrsProfile; | ||
| import org.openmrs.module.patientflags.Priority; | ||
| import org.openmrs.module.patientflags.api.FlagService; | ||
| import org.openmrs.module.initializer.Domain; | ||
| import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
| import org.openmrs.module.initializer.api.CsvLine; | ||
| import org.openmrs.module.initializer.api.CsvParser; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Parses CSV files for Priority entities. | ||
| */ | ||
| @Component("initializer.flagPrioritiesCsvParser") | ||
| @OpenmrsProfile(modules = { "patientflags:3.* - 9.*" }) | ||
| public class PrioritiesCsvParser extends CsvParser<Priority, BaseLineProcessor<Priority>> { | ||
|
|
||
| private final FlagService flagService; | ||
|
|
||
| @Autowired | ||
| public PrioritiesCsvParser(@Qualifier("flagService") FlagService flagService, | ||
| @Qualifier("initializer.flagPriorityLineProcessor") PriorityLineProcessor processor) { | ||
| super(processor); | ||
| this.flagService = flagService; | ||
| } | ||
|
|
||
| @Override | ||
| public Domain getDomain() { | ||
| return Domain.FLAG_PRIORITIES; | ||
| } | ||
|
|
||
| @Override | ||
| public Priority bootstrap(CsvLine line) throws IllegalArgumentException { | ||
| String uuid = line.getUuid(); | ||
| Priority priority = flagService.getPriorityByUuid(uuid); | ||
|
|
||
| if (priority == null && StringUtils.isEmpty(uuid)) { | ||
| String name = line.getName(); | ||
| if (StringUtils.isNotBlank(name)) { | ||
| priority = flagService.getPriorityByName(name); | ||
| } | ||
| } | ||
|
|
||
| if (priority == null) { | ||
| priority = new Priority(); | ||
| if (StringUtils.isNotBlank(uuid)) { | ||
| priority.setUuid(uuid); | ||
| } | ||
| } | ||
|
|
||
| return priority; | ||
| } | ||
|
|
||
| @Override | ||
| public Priority save(Priority instance) { | ||
| flagService.savePriority(instance); | ||
| return instance; | ||
| } | ||
| } |
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.
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 seems not to match the declaration in the POM.xml?
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.
Yeah I thought there was no API change (so it would be compatible) but then I changed the API. Changed to
3.0.9 (*compatible*)