Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ This is the list of currently supported domains in their loading order:
1. [AMPATH Forms (JSON files)](readme/ampathforms.md)
1. [AMPATH Forms Translations (JSON files)](readme/ampathformstranslations.md)
1. [HTML Forms (XML files)](readme/htmlforms.md)
1. [Concept Reference Ranges (CSV files)](readme/conceptreferenceranges.md)

## Try it out
Build the master branch and install the built OMOD to your OpenMRS instance:
Expand Down Expand Up @@ -206,6 +207,7 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo
* Ampath forms translation files will now generate checksums.
* Enhancement to ensure that when an Ampath forms file is loaded, a new resource with the existing Ampath forms translations is created.
* Added support for 'billing' (billableservices, paymentmodes, cashpoints) domains.
* Added support for 'conceptreferencerange' domain.

#### Version 2.7.0
* Added support for 'queues' domain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum Domain {
OCL,
CONCEPTS,
CONCEPT_SETS,
CONCEPT_REFERENCE_RANGE,
BILLABLE_SERVICES,
PAYMENT_MODES,
CASH_POINTS,
Expand Down
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);
}
}
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;
}
}
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) {
}
}
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());
}
}
}
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

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

Yes. I made this change while I was trying to test. I will revert it.

b5a7b296-e500-4a2c-ab2e-eb012ed9ae1e,,60,70,80,120,130,150, $fn.getCurrentHour() > 2
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<openmrsVersion2.3>2.3.6</openmrsVersion2.3>
<openmrsVersion2.4>2.4.5</openmrsVersion2.4>
<openmrsVersion2.5>2.5.5</openmrsVersion2.5>
<openmrsVersion2.7>2.7.0-SNAPSHOT</openmrsVersion2.7>

<openmrsPlatformVersion>${openmrsVersion2.1}</openmrsPlatformVersion>

Expand Down
49 changes: 49 additions & 0 deletions readme/conceptreferenceranges.md
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.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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).