Skip to content

Commit

Permalink
Loading Concept Reference Range Configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Dec 13, 2024
1 parent 26222b4 commit 7e979fa
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected boolean matchesSafely(List<Loader> loaders, Description mismatchDescri
exclude.add(Domain.PAYMENT_MODES.getName());
exclude.add(Domain.BILLABLE_SERVICES.getName());
exclude.add(Domain.CASH_POINTS.getName());
exclude.add(Domain.CONCEPT_REFERENCE_RANGE.getName());

boolean result = true;
Set<String> loaderDomains = loaders.stream().map(Loader::getDomainName).collect(Collectors.toSet());
Expand Down
83 changes: 83 additions & 0 deletions api-2.7/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>initializer</artifactId>
<groupId>org.openmrs.module</groupId>
<version>2.8.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>initializer-api-2.7</artifactId>
<packaging>jar</packaging>
<name>Initializer API 2.7</name>
<description>API 2.7 project for Initializer</description>

<properties>
<openmrsPlatformVersion>${openmrsVersion2.7}</openmrsPlatformVersion>
</properties>

<dependencies>

<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<version>${openmrsPlatformVersion}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api-2.2</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api-2.2</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api-2.5</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api-2.6</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.openmrs.module.initializer.api.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.Qualifier;
import org.springframework.stereotype.Component;
import org.openmrs.ConceptReferenceRange;

@Component
public class ConceptReferenceRangeLineProcessor extends BaseLineProcessor<ConceptReferenceRange> {

private final String HEADER_CONCEPT_NUMERIC_UUID = "Concept Numeric UUID";

private final String HEADER_ABSOLUTE_LOW = "Absolute Low";

private final String HEADER_ABSOLUTE_HIGH = "Absolute High";

private final String HEADER_CRITICAL_LOW = "Critical Low";

private final String HEADER_CRITICAL_HIGH = "Critical High";

private final String HEADER_NORMAL_LOW = "Normal Low";

private final String HEADER_NORMAL_HIGH = "Normal High";

private final String HEADER_CRITERIA = "Criteria";

private final ConceptService conceptService;

public ConceptReferenceRangeLineProcessor(@Qualifier("conceptService") ConceptService conceptService) {
this.conceptService = conceptService;
}

public ConceptReferenceRange fill(ConceptReferenceRange conceptReferenceRange, CsvLine line)
throws IllegalArgumentException {
conceptReferenceRange
.setConceptNumeric(conceptService.getConceptNumericByUuid(line.get(HEADER_CONCEPT_NUMERIC_UUID)));
conceptReferenceRange.setHiAbsolute(line.getDouble(HEADER_ABSOLUTE_HIGH));
conceptReferenceRange.setLowAbsolute(line.getDouble(HEADER_ABSOLUTE_LOW));
conceptReferenceRange.setHiCritical(line.getDouble(HEADER_CRITICAL_HIGH));
conceptReferenceRange.setLowCritical(line.getDouble(HEADER_CRITICAL_LOW));
conceptReferenceRange.setHiNormal(line.getDouble(HEADER_NORMAL_HIGH));
conceptReferenceRange.setLowNormal(line.getDouble(HEADER_NORMAL_LOW));
conceptReferenceRange.setCriteria(line.getString(HEADER_CRITERIA));

return conceptReferenceRange;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.openmrs.module.initializer.api.conceptreferencerange;

import org.openmrs.ConceptReferenceRange;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;

@OpenmrsProfile(openmrsPlatformVersion = "2.7.x")
@Component
public class ConceptReferenceRangeLoader extends BaseCsvLoader<ConceptReferenceRange, ConceptReferenceRangeParser> {

@Autowired
public void setParser(ConceptReferenceRangeParser parser) {
this.parser = parser;
}

@Override
protected void preload(File file) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.openmrs.module.initializer.api.conceptreferencerange;

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.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class ConceptReferenceRangeParser extends CsvParser<ConceptReferenceRange, BaseLineProcessor<ConceptReferenceRange>> {

private ConceptService conceptService;

public ConceptReferenceRangeParser(@Qualifier("conceptService") ConceptService conceptService,
ConceptReferenceRangeLineProcessor lineProcessor) {
super(lineProcessor);
this.conceptService = conceptService;
}

@Override
public ConceptReferenceRange bootstrap(CsvLine line) throws IllegalArgumentException {
String uuid = line.getUuid();
ConceptReferenceRange conceptReferenceRange = conceptService.getConceptReferenceRangeByUuid(uuid);

if (conceptReferenceRange == null) {
conceptReferenceRange = new ConceptReferenceRange();
conceptReferenceRange.setUuid(uuid);
}

return conceptReferenceRange;
}

@Override
public ConceptReferenceRange save(ConceptReferenceRange instance) {
return conceptService.saveConceptReferenceRange(instance);
}

@Override
public Domain getDomain() {
return Domain.CONCEPT_REFERENCE_RANGE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.openmrs.module.initializer;

import org.openmrs.module.Module;
import org.openmrs.module.ModuleFactory;

import java.io.File;

public abstract class DomainBaseModuleContextSensitive_2_7_Test extends DomainBaseModuleContextSensitiveTest {

@Override
public void initModules() {
{
Module mod = new Module("", "addresshierarchy", "", "", "", "2.17.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "exti18n", "", "", "", "1.0.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "fhir2", "", "", "", "1.6.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "openconceptlab", "", "", "", "1.2.9", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "htmlformentry", "", "", "", "4.0.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "idgen", "", "", "", "4.6.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "metadatasharing", "", "", "", "1.2.2", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "metadatamapping", "", "", "", "1.3.4", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "appointments", "", "", "", "1.2", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "datafilter", "", "", "", "1.0.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "bahmni.ie.apps", "", "", "", "1.0.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "providermanagement", "", "", "", "1.0.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "cohort", "", "", "", "3.5.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
{
Module mod = new Module("", "emrapi", "", "", "", "2.0.0", "");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.openmrs.module.initializer.api.loaders;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.ConceptReferenceRange;
import org.openmrs.api.ConceptService;
import org.openmrs.module.initializer.DomainBaseModuleContextSensitive_2_7_Test;
import org.openmrs.module.initializer.api.conceptreferencerange.ConceptReferenceRangeLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class ConceptReferenceRangeLoaderIntegrationTest extends DomainBaseModuleContextSensitive_2_7_Test {

@Autowired
@Qualifier("conceptService")
private ConceptService conceptService;

@Autowired
private ConceptReferenceRangeLoader loader;

public void setup() {
executeDataSet("testdata/test-concepts.xml");
executeDataSet("testdata/test-concepts-numeric.xml");
}

@Test
public void load_shouldLoadConceptReferenceRangesAccordingToCsvFiles() {
loader.load();

{
ConceptReferenceRange conceptReferenceRange = conceptService
.getConceptReferenceRangeByUuid("bc059100-4ace-4af5-afbf-2da7f3a34acf");
Assert.assertNotNull(conceptReferenceRange);
Assert.assertNotNull(conceptReferenceRange.getConceptNumeric());
Assert.assertEquals("a09ab2c5-878e-4905-b25d-5784167d0216", conceptReferenceRange.getConceptNumeric().getUuid());
Assert.assertEquals(-100.5, conceptReferenceRange.getLowAbsolute(), 0.01);
Assert.assertEquals(-85.7, conceptReferenceRange.getLowCritical(), 0.01);
Assert.assertEquals(-50.3, conceptReferenceRange.getLowNormal(), 0.01);
Assert.assertEquals(45.1, conceptReferenceRange.getHiNormal(), 0.01);
Assert.assertEquals(78.0, conceptReferenceRange.getHiCritical(), 0.01);
Assert.assertEquals(98.8, conceptReferenceRange.getHiAbsolute(), 0.01);
Assert.assertEquals("$patient.getAge() > 3", conceptReferenceRange.getCriteria());
}

{
ConceptReferenceRange conceptReferenceRange = conceptService
.getConceptReferenceRangeByUuid("930e1fb4-490d-45fe-a137-0cd941c76124");
Assert.assertNotNull(conceptReferenceRange);
Assert.assertNotNull(conceptReferenceRange.getConceptNumeric());
Assert.assertEquals("a09ab2c5-878e-4905-b25d-5784167d0216", conceptReferenceRange.getConceptNumeric().getUuid());
Assert.assertEquals(-100.5, conceptReferenceRange.getLowAbsolute(), 0.01);
Assert.assertEquals(-85.7, conceptReferenceRange.getLowCritical(), 0.01);
Assert.assertEquals(-50.3, conceptReferenceRange.getLowNormal(), 0.01);
Assert.assertEquals(45.1, conceptReferenceRange.getHiNormal(), 0.01);
Assert.assertEquals(78.0, conceptReferenceRange.getHiCritical(), 0.01);
Assert.assertEquals(98.8, conceptReferenceRange.getHiAbsolute(), 0.01);
Assert.assertEquals("$patient.getAge() < 10", conceptReferenceRange.getCriteria());
}

{
ConceptReferenceRange conceptReferenceRange = conceptService
.getConceptReferenceRangeByUuid("b5a7b296-e500-4a2c-ab2e-eb012ed9ae1e");
Assert.assertNotNull(conceptReferenceRange);
Assert.assertNotNull(conceptReferenceRange.getConceptNumeric());
Assert.assertEquals("a09ab2c5-878e-4905-b25d-5784167d0216", conceptReferenceRange.getConceptNumeric().getUuid());
Assert.assertEquals(60.0, conceptReferenceRange.getLowAbsolute(), 0.01);
Assert.assertEquals(70.0, conceptReferenceRange.getLowCritical(), 0.01);
Assert.assertEquals(80.0, conceptReferenceRange.getLowNormal(), 0.01);
Assert.assertEquals(120.0, conceptReferenceRange.getHiNormal(), 0.01);
Assert.assertEquals(130.0, conceptReferenceRange.getHiCritical(), 0.01);
Assert.assertEquals(150.0, conceptReferenceRange.getHiAbsolute(), 0.01);
Assert.assertEquals("$fn.getCurrentHour() > 2", conceptReferenceRange.getCriteria());
}
}

}
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,a09ab2c5-878e-4905-b25d-5784167d0216,-100.5,-85.7,-50.3,45.1,78,98.8, $patient.getAge() > 3
930e1fb4-490d-45fe-a137-0cd941c76124,a09ab2c5-878e-4905-b25d-5784167d0216,-100.5,-85.7,-50.3,45.1,78,98.8, $patient.getAge() < 10
b5a7b296-e500-4a2c-ab2e-eb012ed9ae1e,a09ab2c5-878e-4905-b25d-5784167d0216,60,70,80,120,130,150, $fn.getCurrentHour() > 2
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
Loading

0 comments on commit 7e979fa

Please sign in to comment.