Skip to content

Commit 9b8e9ff

Browse files
authored
O3-5658: Add support for Procedure Types domain in the Initializer module (#323)
1 parent ca0ef6f commit 9b8e9ff

17 files changed

Lines changed: 552 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ This is the list of currently supported domains in their loading order:
129129
1. [Privileges (CSV files)](readme/priv.md)
130130
1. [Encounter Types (CSV files)](readme/et.md)
131131
1. [Encounter Roles (CSV files)](readme/encounterroles.md)
132+
1. [Procedure Types (CSV files)](readme/proceduretypes.md)
132133
1. [Roles (CSV files)](readme/roles.md)
133134
1. [Global Properties (XML files)](readme/globalproperties.md)
134135
1. [Attribute Types (CSV files)](readme/atttypes.md)
@@ -232,6 +233,7 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo
232233
* Fix to ensure concept lookups correctly handle concepts with % characters
233234
* Fix for performance to only process displays preloaders if they are present within csvs
234235
* Add support for row-level checksums in CSV domains to enable only re-loading those rows that have changed
236+
* Added support for 'proceduretypes' domain (requires emrapi 3.4+ on OpenMRS Core 2.8+)
235237

236238
#### Version 2.11.0
237239
* Added support for patient flags (flags, flagpriorities, flagtags) domains

api-2.3/src/test/java/org/openmrs/module/initializer/api/loaders/LoadersOrderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ protected boolean matchesSafely(List<Loader> loaders, Description mismatchDescri
7777
exclude.add(Domain.FLAGS.getName());
7878
exclude.add(Domain.FLAG_PRIORITIES.getName());
7979
exclude.add(Domain.FLAG_TAGS.getName());
80+
exclude.add(Domain.PROCEDURE_TYPES.getName());
8081

8182
boolean result = true;
8283
Set<String> loaderDomains = loaders.stream().map(Loader::getDomainName).collect(Collectors.toSet());

api-2.8/pom.xml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.openmrs.module</groupId>
7+
<artifactId>initializer</artifactId>
8+
<version>2.12.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>initializer-api-2.8</artifactId>
13+
<packaging>jar</packaging>
14+
<name>Initializer API 2.8</name>
15+
<description>API 2.8 project for Initializer</description>
16+
17+
<properties>
18+
<openmrsPlatformVersion>${openmrsVersion2.8}</openmrsPlatformVersion>
19+
<emrapiVersion>3.4.0</emrapiVersion>
20+
</properties>
21+
22+
<repositories>
23+
<repository>
24+
<id>openmrs-repo-snapshots</id>
25+
<name>OpenMRS Nexus Snapshots</name>
26+
<url>https://mavenrepo.openmrs.org/snapshots</url>
27+
<releases>
28+
<enabled>false</enabled>
29+
</releases>
30+
<snapshots>
31+
<enabled>true</enabled>
32+
</snapshots>
33+
</repository>
34+
</repositories>
35+
36+
<dependencies>
37+
38+
<dependency>
39+
<groupId>org.openmrs.test</groupId>
40+
<artifactId>openmrs-test</artifactId>
41+
<type>pom</type>
42+
<version>${openmrsPlatformVersion}</version>
43+
<scope>test</scope>
44+
<exclusions>
45+
<exclusion>
46+
<groupId>org.powermock</groupId>
47+
<artifactId>powermock-api-mockito2</artifactId>
48+
</exclusion>
49+
</exclusions>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>${project.parent.groupId}</groupId>
54+
<artifactId>${project.parent.artifactId}-api</artifactId>
55+
<version>${project.parent.version}</version>
56+
<scope>provided</scope>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>${project.parent.groupId}</groupId>
61+
<artifactId>${project.parent.artifactId}-api</artifactId>
62+
<version>${project.parent.version}</version>
63+
<scope>test</scope>
64+
<type>test-jar</type>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>${project.parent.groupId}</groupId>
69+
<artifactId>${project.parent.artifactId}-api-2.2</artifactId>
70+
<version>${project.parent.version}</version>
71+
<scope>provided</scope>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>${project.parent.groupId}</groupId>
76+
<artifactId>${project.parent.artifactId}-api-2.2</artifactId>
77+
<version>${project.parent.version}</version>
78+
<scope>test</scope>
79+
<type>test-jar</type>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.openmrs.module</groupId>
84+
<artifactId>emrapi-api</artifactId>
85+
<version>${emrapiVersion}</version>
86+
<scope>provided</scope>
87+
</dependency>
88+
89+
</dependencies>
90+
91+
<build>
92+
<plugins>
93+
<!-- Inherited from parent pom; not used by api-2.8 and each breaks the Spring test context on Core 2.8. -->
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-surefire-plugin</artifactId>
97+
<configuration>
98+
<classpathDependencyExcludes>
99+
<classpathDependencyExclude>org.openmrs.module:providermanagement-api</classpathDependencyExclude>
100+
<classpathDependencyExclude>org.openmrs.module:htmlformentry-api</classpathDependencyExclude>
101+
<classpathDependencyExclude>org.openmrs.module:fhir2-api</classpathDependencyExclude>
102+
<classpathDependencyExclude>org.openmrs.module:fhir2-api-2.1</classpathDependencyExclude>
103+
<classpathDependencyExclude>org.openmrs.module:fhir2-api-2.2</classpathDependencyExclude>
104+
<classpathDependencyExclude>org.openmrs.module:tasks-api</classpathDependencyExclude>
105+
<classpathDependencyExclude>org.openmrs.module:reporting-api</classpathDependencyExclude>
106+
<classpathDependencyExclude>org.openmrs.module:reporting-api-2.0</classpathDependencyExclude>
107+
</classpathDependencyExcludes>
108+
</configuration>
109+
</plugin>
110+
</plugins>
111+
</build>
112+
113+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.openmrs.module.initializer.api.procedure;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.openmrs.annotation.OpenmrsProfile;
5+
import org.openmrs.module.emrapi.procedure.ProcedureType;
6+
import org.openmrs.module.initializer.api.BaseLineProcessor;
7+
import org.openmrs.module.initializer.api.CsvLine;
8+
import org.springframework.stereotype.Component;
9+
10+
@OpenmrsProfile(modules = { "emrapi:3.4.* - 9.*" })
11+
@Component
12+
public class ProcedureTypeLineProcessor extends BaseLineProcessor<ProcedureType> {
13+
14+
@Override
15+
public ProcedureType fill(ProcedureType instance, CsvLine line) throws IllegalArgumentException {
16+
String name = line.getName(true);
17+
if (StringUtils.isBlank(name)) {
18+
throw new IllegalArgumentException("'Name' is required for procedure types.");
19+
}
20+
instance.setName(name);
21+
instance.setDescription(line.get(HEADER_DESC));
22+
return instance;
23+
}
24+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.openmrs.module.initializer.api.procedure;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.apache.commons.lang3.StringUtils;
7+
import org.openmrs.annotation.OpenmrsProfile;
8+
import org.openmrs.module.emrapi.procedure.ProcedureService;
9+
import org.openmrs.module.emrapi.procedure.ProcedureType;
10+
import org.openmrs.module.initializer.Domain;
11+
import org.openmrs.module.initializer.api.BaseLineProcessor;
12+
import org.openmrs.module.initializer.api.CsvLine;
13+
import org.openmrs.module.initializer.api.CsvParser;
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.beans.factory.annotation.Qualifier;
16+
import org.springframework.stereotype.Component;
17+
18+
@OpenmrsProfile(modules = { "emrapi:3.4.* - 9.*" })
19+
@Component
20+
public class ProcedureTypesCsvParser extends CsvParser<ProcedureType, BaseLineProcessor<ProcedureType>> {
21+
22+
private final ProcedureService procedureService;
23+
24+
@Autowired
25+
public ProcedureTypesCsvParser(@Qualifier("procedureService") ProcedureService procedureService,
26+
ProcedureTypeLineProcessor lineProcessor) {
27+
super(lineProcessor);
28+
this.procedureService = procedureService;
29+
}
30+
31+
@Override
32+
public Domain getDomain() {
33+
return Domain.PROCEDURE_TYPES;
34+
}
35+
36+
@Override
37+
public ProcedureType bootstrap(CsvLine line) throws IllegalArgumentException {
38+
String uuid = line.getUuid();
39+
String name = line.getName();
40+
41+
ProcedureType type = null;
42+
if (StringUtils.isNotBlank(uuid)) {
43+
type = procedureService.getProcedureTypeByUuid(uuid);
44+
} else if (StringUtils.isNotBlank(name)) {
45+
List<ProcedureType> exactMatches = new ArrayList<ProcedureType>();
46+
List<ProcedureType> raw = procedureService.getProcedureTypesByName(name);
47+
if (raw != null) {
48+
for (ProcedureType candidate : raw) {
49+
if (name.equals(candidate.getName())) {
50+
exactMatches.add(candidate);
51+
}
52+
}
53+
}
54+
if (exactMatches.size() > 1) {
55+
throw new IllegalArgumentException(
56+
exactMatches.size() + " procedure types match name '" + name + "'; provide a Uuid to disambiguate.");
57+
}
58+
if (!exactMatches.isEmpty()) {
59+
type = exactMatches.get(0);
60+
}
61+
}
62+
63+
if (type != null) {
64+
return type;
65+
}
66+
67+
type = new ProcedureType();
68+
if (StringUtils.isNotBlank(uuid)) {
69+
type.setUuid(uuid);
70+
}
71+
return type;
72+
}
73+
74+
@Override
75+
public ProcedureType save(ProcedureType instance) {
76+
return procedureService.saveProcedureType(instance);
77+
}
78+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.openmrs.module.initializer.api.procedure;
2+
3+
import org.openmrs.annotation.OpenmrsProfile;
4+
import org.openmrs.module.emrapi.procedure.ProcedureType;
5+
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.stereotype.Component;
8+
9+
@OpenmrsProfile(modules = { "emrapi:3.4.* - 9.*" })
10+
@Component
11+
public class ProcedureTypesLoader extends BaseCsvLoader<ProcedureType, ProcedureTypesCsvParser> {
12+
13+
@Autowired
14+
public void setParser(ProcedureTypesCsvParser parser) {
15+
this.parser = parser;
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.openmrs.module.initializer;
2+
3+
import java.io.File;
4+
5+
import org.openmrs.module.Module;
6+
import org.openmrs.module.ModuleFactory;
7+
8+
public abstract class DomainBaseModuleContextSensitive_2_8_Test extends DomainBaseModuleContextSensitiveTest {
9+
10+
@Override
11+
public void initModules() {
12+
Module mod = new Module("", "emrapi", "", "", "", "3.4.0", "");
13+
mod.setFile(new File(""));
14+
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
15+
}
16+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.openmrs.module.initializer.api.lineprocessor;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNull;
5+
6+
import org.junit.Test;
7+
import org.openmrs.module.emrapi.procedure.ProcedureType;
8+
import org.openmrs.module.initializer.api.CsvLine;
9+
import org.openmrs.module.initializer.api.procedure.ProcedureTypeLineProcessor;
10+
11+
public class ProcedureTypeLineProcessorTest {
12+
13+
private final ProcedureTypeLineProcessor processor = new ProcedureTypeLineProcessor();
14+
15+
@Test
16+
public void shouldPopulateNameAndDescription() {
17+
String[] headers = { "Uuid", "Name", "Description" };
18+
String[] line = { "9d9aa7c1-2e0e-4b1e-8b57-7e6f1a0b1234", "Appendectomy", "Surgical removal of the appendix" };
19+
20+
ProcedureType type = processor.fill(new ProcedureType(), new CsvLine(headers, line));
21+
22+
assertEquals("Appendectomy", type.getName());
23+
assertEquals("Surgical removal of the appendix", type.getDescription());
24+
}
25+
26+
@Test
27+
public void shouldAllowMissingDescription() {
28+
String[] headers = { "Uuid", "Name", "Description" };
29+
String[] line = { "9d9aa7c1-2e0e-4b1e-8b57-7e6f1a0b1234", "Cholecystectomy", null };
30+
31+
ProcedureType type = processor.fill(new ProcedureType(), new CsvLine(headers, line));
32+
33+
assertEquals("Cholecystectomy", type.getName());
34+
assertNull(type.getDescription());
35+
}
36+
37+
@Test(expected = IllegalArgumentException.class)
38+
public void shouldThrowWhenNameIsNull() {
39+
String[] headers = { "Uuid", "Name", "Description" };
40+
String[] line = { "9d9aa7c1-2e0e-4b1e-8b57-7e6f1a0b1234", null, "Description without a name" };
41+
42+
processor.fill(new ProcedureType(), new CsvLine(headers, line));
43+
}
44+
45+
@Test(expected = IllegalArgumentException.class)
46+
public void shouldThrowWhenNameIsBlank() {
47+
String[] headers = { "Uuid", "Name", "Description" };
48+
String[] line = { "9d9aa7c1-2e0e-4b1e-8b57-7e6f1a0b1234", "", "Description without a name" };
49+
50+
processor.fill(new ProcedureType(), new CsvLine(headers, line));
51+
}
52+
}

0 commit comments

Comments
 (0)