-
Notifications
You must be signed in to change notification settings - Fork 89
Trunk 6264 concept reference range initialization #280
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
dicksonmulli
wants to merge
15
commits into
mekomsolutions:main
Choose a base branch
from
dicksonmulli:TRUNK-6264-concept-reference-range-initialization
base: main
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
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b7d3639
Adding referencer range parser and loader classes
dicksonmulli 50220a7
Updating core version
dicksonmulli 6588fb2
Adding reference range csv
dicksonmulli cf86dc0
Adding integration test
dicksonmulli 7e89c2a
Adding README file for reference ranges
dicksonmulli 30f8777
Updating the readme
dicksonmulli bcef1a0
Removing unnecessary comment and updating csv
dicksonmulli 55e27f9
Upgrading core version
dicksonmulli 3911d33
Adding a sub module - initializer-api-2.7
dicksonmulli 2c9484e
Adding test data
dicksonmulli 1927770
Updating initializer-2.7
dicksonmulli 0c18db3
Fixing Mockito error
dicksonmulli 0f2f2b8
Reversing mockito version in validator
dicksonmulli 157258d
Code refactor
b56d18f
Merge branch 'main' into TRUNK-6264-concept-reference-range-initializ…
dicksonmulli 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
51 changes: 51 additions & 0 deletions
51
api/src/main/java/org/openmrs/module/initializer/api/c/ConceptReferenceRangeCsvParser.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,51 @@ | ||
| package org.openmrs.module.initializer.api.c; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.openmrs.ConceptReferenceRange; | ||
| import org.openmrs.api.ConceptService; | ||
| 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; | ||
|
|
||
| @Component | ||
| public class ConceptReferenceRangeCsvParser extends CsvParser<ConceptReferenceRange, BaseLineProcessor<ConceptReferenceRange>> { | ||
|
|
||
| private final ConceptService conceptService; | ||
|
|
||
| @Autowired | ||
| public ConceptReferenceRangeCsvParser(@Qualifier("conceptService") ConceptService conceptService, | ||
| ConceptReferenceRangeLineProcessor processor) { | ||
| super(processor); | ||
| this.conceptService = conceptService; | ||
| } | ||
|
|
||
| @Override | ||
| public Domain getDomain() { | ||
| return Domain.CONCEPT_REFERENCE_RANGE; | ||
| } | ||
|
|
||
| @Override | ||
| public ConceptReferenceRange bootstrap(CsvLine line) throws IllegalArgumentException { | ||
| String uuid = line.getUuid(); | ||
|
|
||
| ConceptReferenceRange referenceRange = conceptService.getConceptReferenceRangeByUuid(uuid); | ||
|
|
||
| if (referenceRange == null) { | ||
| referenceRange = new ConceptReferenceRange(); | ||
| if (!StringUtils.isEmpty(uuid)) { | ||
| referenceRange.setUuid(uuid); | ||
| } | ||
| } | ||
|
|
||
| return referenceRange; | ||
| } | ||
|
|
||
| @Override | ||
| public ConceptReferenceRange save(ConceptReferenceRange instance) { | ||
| return conceptService.saveConceptReferenceRange(instance); | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
...rc/main/java/org/openmrs/module/initializer/api/c/ConceptReferenceRangeLineProcessor.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,61 @@ | ||
| package org.openmrs.module.initializer.api.c; | ||
|
|
||
| import org.openmrs.ConceptNumeric; | ||
| import org.openmrs.ConceptReferenceRange; | ||
| import org.openmrs.api.ConceptService; | ||
| 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; | ||
|
|
||
| @Component("initializer.conceptReferenceRangeLineProcessor") | ||
| public class ConceptReferenceRangeLineProcessor extends BaseLineProcessor<ConceptReferenceRange> { | ||
|
|
||
| private final String HEADER_CONCEPT_NUMERIC_UUID = "Concept Numeric Uuid"; | ||
|
|
||
| private final String HEADER_AH = "Absolute high"; | ||
|
|
||
| private final String HEADER_CH = "Critical high"; | ||
|
|
||
| private final String HEADER_NH = "Normal high"; | ||
|
|
||
| private final String HEADER_AL = "Absolute low"; | ||
|
|
||
| private final String HEADER_CL = "Critical low"; | ||
|
|
||
| private final String HEADER_NL = "Normal low"; | ||
|
|
||
| private final String HEADER_CRITERIA = "Criteria"; | ||
|
|
||
| private ConceptService conceptService; | ||
|
|
||
| @Autowired | ||
| public ConceptReferenceRangeLineProcessor(@Qualifier("conceptService") ConceptService conceptService) { | ||
| this.conceptService = conceptService; | ||
| } | ||
|
|
||
| public ConceptReferenceRange fill(ConceptReferenceRange referenceRange, CsvLine line) throws IllegalArgumentException { | ||
| ConceptNumeric conceptNumeric = conceptService.getConceptNumericByUuid(line.get(HEADER_CONCEPT_NUMERIC_UUID)); | ||
|
|
||
| if (conceptNumeric == null) { // below overrides any other processors work, so this one should be called first | ||
| throw new IllegalArgumentException( | ||
| "No concept numeric found for '" + line.get(HEADER_CONCEPT_NUMERIC_UUID) + "'"); | ||
| } | ||
|
|
||
| if (referenceRange == null) { | ||
| referenceRange = new ConceptReferenceRange(); | ||
| } | ||
|
|
||
| referenceRange.setHiAbsolute(line.getDouble(HEADER_AH)); | ||
| referenceRange.setHiCritical(line.getDouble(HEADER_CH)); | ||
| referenceRange.setHiNormal(line.getDouble(HEADER_NH)); | ||
| referenceRange.setLowAbsolute(line.getDouble(HEADER_AL)); | ||
| referenceRange.setLowCritical(line.getDouble(HEADER_CL)); | ||
| referenceRange.setLowNormal(line.getDouble(HEADER_NL)); | ||
| referenceRange.setConceptNumeric(conceptNumeric); | ||
| referenceRange.setCriteria(line.getString(HEADER_CRITERIA)); | ||
|
|
||
| return referenceRange; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
api/src/main/java/org/openmrs/module/initializer/api/c/ConceptReferenceRangeLoader.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,21 @@ | ||
| package org.openmrs.module.initializer.api.c; | ||
|
|
||
| import org.openmrs.ConceptReferenceRange; | ||
| import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| @Component | ||
| public class ConceptReferenceRangeLoader extends BaseCsvLoader<ConceptReferenceRange, ConceptReferenceRangeCsvParser> { | ||
|
|
||
| @Autowired | ||
| public void setParser(ConceptReferenceRangeCsvParser parser) { | ||
| this.parser = parser; | ||
| } | ||
|
|
||
| @Override | ||
| protected void preload(File file) { | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
...rc/test/java/org/openmrs/module/initializer/api/ConceptReferenceRangeIntegrationTest.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,30 @@ | ||
| package org.openmrs.module.initializer.api; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openmrs.ConceptReferenceRange; | ||
| import org.openmrs.api.ConceptService; | ||
| import org.openmrs.module.initializer.DomainBaseModuleContextSensitiveTest; | ||
| import org.openmrs.module.initializer.api.c.ConceptReferenceRangeLoader; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| public class ConceptReferenceRangeIntegrationTest extends DomainBaseModuleContextSensitiveTest { | ||
|
|
||
| @Autowired | ||
| private ConceptService conceptService; | ||
|
|
||
| @Autowired | ||
| private ConceptReferenceRangeLoader conceptReferenceRangeLoader; | ||
|
|
||
| @Test | ||
| public void load_shouldLoadConceptReferenceRangeFromCsvFiles() { | ||
| conceptReferenceRangeLoader.load(); | ||
|
|
||
| { | ||
| ConceptReferenceRange referenceRange = conceptService | ||
| .getConceptReferenceRangeByUuid("239c1904-15ff-45e1-ac9d-d83afb637926"); | ||
| Assert.assertNotNull(referenceRange); | ||
| Assert.assertEquals(Double.valueOf("70"), referenceRange.getLowAbsolute()); | ||
| } | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
api/src/test/resources/testAppDataDir/configuration/concepts/concept_referenceranges.csv
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,4 @@ | ||
| Uuid,Concept Numeric Uuid,Absolute low,Critical low,Normal low,Normal high,Critical high,Absolute high,Criteria | ||
| bc059100-4ace-4af5-afbf-2da7f3a34acf,30247229-052c-400b-a823-cb66b1c506c7,-100.5,-85.7,-50.3,45.1,78,98.8, $patient.getAge() > 3 | ||
| 930e1fb4-490d-45fe-a137-0cd941c76124,,-100.5,-85.7,-50.3,45.1,78,98.8, $patient.getAge() < 10 | ||
| b5a7b296-e500-4a2c-ab2e-eb012ed9ae1e,,60,70,80,120,130,150, $fn.getCurrentHour() > 2 | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| ## Domain 'conceptreferenceranges' | ||
|
|
||
| The **conceptreferenceranges** subfolder contains CSV configuration files that help manage ConceptReferenceRange entity. | ||
|
|
||
| This is a possible example of how the configuration subfolder may look like: | ||
|
|
||
| ```bash | ||
| concepts/ | ||
| └── concepts_referenceranges.csv | ||
| ``` | ||
|
|
||
| Here is a sample CSV: | ||
|
|
||
| | Uuid | Concept Numeric Uuid | Absolute low | Critical low | Normal low | Normal high | Absolute high | Absolute high | Criteria | | ||
| |--------------------------------------|-|----------------------------------|-------------------------------------------------|---------------------------------|------------------------------------|-|-------------------------| - | | ||
| | bc059100-4ace-4af5-afbf-2da7f3a34acf | 3f8f0ab7-c240-4b68-8951-bb7020be01f6 | 60 | 70 | 80 | 120 | 130 | 150 | $patient.getAge() > 3 | | ||
|
|
||
|
|
||
| Summery of the set of available headers. | ||
|
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. Summery? |
||
|
|
||
| ###### Header `Uuid` | ||
| Uuid of the conceptReferenceRange entity. | ||
|
|
||
| ###### Header `Concept Numeric Uuid` *(mandatory)* | ||
| UUID of ConceptNumeric. | ||
|
|
||
| ###### Header `Absolute low` *(mandatory)* | ||
| Absolute low of referenceRange. | ||
|
|
||
| ###### Header `Critical low` *(mandatory)* | ||
| Critical low of referenceRange. | ||
|
|
||
| ###### Header `Normal low` *(mandatory)* | ||
| Normal low of referenceRange. | ||
|
|
||
| ###### Header `Normal high` | ||
| Normal high of referenceRange. | ||
|
|
||
| ###### Header `Critical high` | ||
| Critical high of referenceRange. | ||
|
|
||
| ###### Header `Absolute high` *(mandatory)* | ||
| Absolute high of referenceRange. | ||
|
|
||
| ###### Header `Criteria` *(mandatory)* | ||
| Criteria. | ||
|
|
||
| #### Further examples: | ||
| Please look at the test configuration folder for sample import files for all domains, see [here](../api/src/test/resources/testAppDataDir/configuration). | ||
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.
Did you intentionally leave out the concept numeric uuid for the two rows? https://github.com/mekomsolutions/openmrs-module-initializer/blob/7e89c2a0681fb90d26dcabf4bf41dc6228e83783/api/src/test/resources/testAppDataDir/configuration/concepts/concept_referenceranges.csv
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.
Yes. I made this change while I was trying to test. I will revert it.