Skip to content

Commit b75bff6

Browse files
authored
changes from code review #1
changes from code review
2 parents 5017206 + 89ce377 commit b75bff6

File tree

12 files changed

+296
-171
lines changed

12 files changed

+296
-171
lines changed

api-2.5/pom.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.openmrs.module</groupId>
8+
<artifactId>initializer</artifactId>
9+
<version>2.6.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>initializer-api-2.5</artifactId>
13+
<packaging>jar</packaging>
14+
<name>Initializer API 2.5</name>
15+
<description>API 2.5 project for Initializer</description>
16+
17+
<properties>
18+
<openmrsPlatformVersion>${openmrsVersion2.5}</openmrsPlatformVersion>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>${project.parent.groupId}</groupId>
24+
<artifactId>${project.parent.artifactId}-api</artifactId>
25+
<version>${project.parent.version}</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>${project.parent.groupId}</groupId>
31+
<artifactId>${project.parent.artifactId}-api</artifactId>
32+
<version>${project.parent.version}</version>
33+
<scope>test</scope>
34+
<type>test-jar</type>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>${project.parent.groupId}</groupId>
39+
<artifactId>${project.parent.artifactId}-api-2.4</artifactId>
40+
<version>${project.parent.version}</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>${project.parent.groupId}</groupId>
46+
<artifactId>${project.parent.artifactId}-api-2.3</artifactId>
47+
<version>${project.parent.version}</version>
48+
<scope>provided</scope>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>${project.parent.groupId}</groupId>
53+
<artifactId>${project.parent.artifactId}-api-2.3</artifactId>
54+
<version>${project.parent.version}</version>
55+
<scope>test</scope>
56+
<type>test-jar</type>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>${project.parent.groupId}</groupId>
61+
<artifactId>${project.parent.artifactId}-api-2.2</artifactId>
62+
<version>${project.parent.version}</version>
63+
<scope>provided</scope>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>${project.parent.groupId}</groupId>
68+
<artifactId>${project.parent.artifactId}-api-2.2</artifactId>
69+
<version>${project.parent.version}</version>
70+
<scope>test</scope>
71+
<type>test-jar</type>
72+
</dependency>
73+
</dependencies>
74+
75+
</project>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package org.openmrs.module.initializer.api.fhir.cpm;
2+
3+
import org.openmrs.PersonAttributeType;
4+
import org.openmrs.annotation.OpenmrsProfile;
5+
import org.openmrs.api.LocationService;
6+
import org.openmrs.api.PersonService;
7+
import org.openmrs.api.ProviderService;
8+
import org.openmrs.attribute.BaseAttributeType;
9+
import org.openmrs.module.fhir2.api.FhirContactPointMapService;
10+
import org.openmrs.module.initializer.Domain;
11+
import org.openmrs.module.fhir2.model.FhirContactPointMap;
12+
import org.openmrs.module.initializer.api.BaseLineProcessor;
13+
import org.openmrs.module.initializer.api.CsvLine;
14+
import org.openmrs.module.initializer.api.CsvParser;
15+
import org.springframework.beans.factory.annotation.Autowired;
16+
17+
@OpenmrsProfile(modules = { "fhir2:1.11.* - 9.*" }, openmrsPlatformVersion = "2.5.13 - 2.5.*, 2.6.2 - 2.6.*, 2.7.* - 9.*")
18+
public class FhirContactPointMapCsvParser extends CsvParser<FhirContactPointMap, BaseLineProcessor<FhirContactPointMap>> {
19+
20+
public static final String ATTRIBUTE_TYPE_DOMAIN_HEADER = "Entity name";
21+
22+
public static final String ATTRIBUTE_TYPE = "Attribute type";
23+
24+
private static final String LOCATION = "location";
25+
26+
private static final String PERSON = "person";
27+
28+
private static final String PROVIDER = "provider";
29+
30+
private final LocationService locationService;
31+
32+
private final PersonService personService;
33+
34+
private final ProviderService providerService;
35+
36+
private final FhirContactPointMapService fhirContactPointMapService;
37+
38+
@Autowired
39+
protected FhirContactPointMapCsvParser(FhirContactPointMapService fhirContactPointMapService,BaseLineProcessor<FhirContactPointMap> lineProcessor,
40+
LocationService locationService, PersonService personService, ProviderService providerService) {
41+
super(lineProcessor);
42+
this.fhirContactPointMapService = fhirContactPointMapService;
43+
this.locationService = locationService;
44+
this.personService = personService;
45+
this.providerService = providerService;
46+
}
47+
48+
@Override
49+
public FhirContactPointMap bootstrap(CsvLine line) throws IllegalArgumentException {
50+
FhirContactPointMap contactPointMap = null;
51+
if (line.getUuid() != null) {
52+
contactPointMap = fhirContactPointMapService.getFhirConactPointMapByUuid(line.getUuid());
53+
}
54+
55+
if (contactPointMap != null) {
56+
return contactPointMap;
57+
}
58+
59+
String attributeTypeDomain = line.get(ATTRIBUTE_TYPE_DOMAIN_HEADER, true);
60+
String attributeType = line.get(ATTRIBUTE_TYPE, true);
61+
62+
if (attributeTypeDomain.equals(PERSON)) {
63+
PersonAttributeType personAttributeType = getPersonAttributeType(attributeType);
64+
65+
if (personAttributeType == null) {
66+
throw new IllegalArgumentException("PersonAttributeType " + attributeType
67+
+ " does not exist. Please ensure your Initializer configuration contains this attribute type.");
68+
}
69+
70+
contactPointMap = fhirContactPointMapService.getFhirContactPointMapForPersonAttributeType(personAttributeType)
71+
.orElse(null);
72+
} else {
73+
BaseAttributeType<?> baseAttributeType = getBaseAttributeType(attributeTypeDomain, attributeType);
74+
75+
if (baseAttributeType == null) {
76+
throw new IllegalArgumentException(
77+
"Could not find attribute type " + attributeType + " for attribute domain " + attributeTypeDomain);
78+
}
79+
80+
contactPointMap = fhirContactPointMapService.getFhirContactPointMapForAttributeType(baseAttributeType)
81+
.orElse(null);
82+
}
83+
84+
if (contactPointMap != null) {
85+
return contactPointMap;
86+
}
87+
88+
return new FhirContactPointMap();
89+
}
90+
91+
92+
@Override
93+
public FhirContactPointMap save(FhirContactPointMap instance) {
94+
return fhirContactPointMapService.saveFhirContactPointMap(instance);
95+
}
96+
97+
@Override
98+
public Domain getDomain() {
99+
return Domain.FHIR_CONTACT_POINT_MAP;
100+
}
101+
102+
protected PersonAttributeType getPersonAttributeType(String attributeType) {
103+
PersonAttributeType personAttributeType = personService.getPersonAttributeTypeByName(attributeType);
104+
105+
if (personAttributeType != null) {
106+
return personAttributeType;
107+
}
108+
109+
personAttributeType = personService.getPersonAttributeTypeByUuid(attributeType);
110+
111+
return personAttributeType;
112+
}
113+
114+
protected BaseAttributeType<?> getBaseAttributeType(String attributeDomain, String attributeType) {
115+
BaseAttributeType<?> baseAttributeType = null;
116+
117+
switch (attributeDomain) {
118+
case LOCATION:
119+
baseAttributeType = locationService.getLocationAttributeTypeByName(attributeType);
120+
121+
if (baseAttributeType != null) {
122+
return baseAttributeType;
123+
}
124+
125+
return locationService.getLocationAttributeTypeByUuid(attributeType);
126+
break;
127+
case PROVIDER:
128+
baseAttributeType = providerService.getProviderAttributeTypeByName(attributeType);
129+
130+
if (baseAttributeType != null) {
131+
return baseAttributeType;
132+
}
133+
134+
return providerService.getProviderAttributeTypeByUuid(attributeType);
135+
break;
136+
}
137+
}
138+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.openmrs.module.initializer.api.fhir.cpm;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.hl7.fhir.r4.model.ContactPoint;
5+
import org.openmrs.annotation.OpenmrsProfile;
6+
import org.openmrs.module.fhir2.model.FhirContactPointMap;
7+
import org.openmrs.module.initializer.api.BaseLineProcessor;
8+
import org.openmrs.module.initializer.api.CsvLine;
9+
10+
import static org.openmrs.module.initializer.api.fhir.cpm.FhirContactPointMapCsvParser.ATTRIBUTE_TYPE_DOMAIN_HEADER;
11+
12+
@OpenmrsProfile(modules = { "fhir2:1.11.* - 9.*" }, openmrsPlatformVersion = "2.5.13 - 2.5.*, 2.6.2 - 2.6.*, 2.7.* - 9.*")
13+
public class FhirContactPointMapLineProcessor extends BaseLineProcessor<FhirContactPointMap> {
14+
15+
private static final String SYSTEM_HEADER = "system";
16+
private static final String USE_HEADER = "use";
17+
private static final String RANK_HEADER = "rank";
18+
@Override
19+
public FhirContactPointMap fill(FhirContactPointMap instance, CsvLine line) throws IllegalArgumentException {
20+
String uuid = line.getUuid();
21+
22+
if (StringUtils.isNotBlank(uuid)) {
23+
instance.setUuid(line.getUuid());
24+
}
25+
26+
line.get(ATTRIBUTE_TYPE_DOMAIN_HEADER, true);
27+
28+
String system = line.get(SYSTEM_HEADER, false);
29+
String use = line.get(USE_HEADER, false);
30+
String rank = line.get(RANK_HEADER, false);
31+
32+
if (system != null) {
33+
instance.setSystem(ContactPoint.ContactPointSystem.valueOf(system));
34+
}
35+
36+
if (use != null) {
37+
instance.setUse(ContactPoint.ContactPointUse.valueOf(use));
38+
}
39+
40+
if (rank != null) {
41+
int rankInt = Integer.parseInt(rank);
42+
if (rankInt < 1) {
43+
throw new IllegalArgumentException("Rank must be a positive integer, i.e., 1+");
44+
}
45+
instance.setRank(rankInt);
46+
}
47+
48+
return instance;
49+
}
50+
}

api/src/main/java/org/openmrs/module/initializer/api/fhir/cpm/FhirContactPointMapLoader.java renamed to api-2.5/src/main/java/org/openmrs/module/initializer/api/fhir/cpm/FhirContactPointMapLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader;
66
import org.springframework.beans.factory.annotation.Autowired;
77

8-
@OpenmrsProfile(modules = { "fhir2:1.6.* - 9.*" })
8+
@OpenmrsProfile(modules = { "fhir2:1.11.* - 9.*" }, openmrsPlatformVersion = "2.5.13 - 2.5.*, 2.6.2 - 2.6.*, 2.7.* - 9.*")
99
public class FhirContactPointMapLoader extends BaseCsvLoader<FhirContactPointMap, FhirContactPointMapCsvParser> {
1010

1111
@Autowired
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.initializer;
11+
12+
public abstract class DomainBaseModuleContextSensitive_2_5_Test extends DomainBaseModuleContextSensitiveTest {
13+
14+
@Override
15+
public void updateSearchIndex() {
16+
// to prevent Data Filter's 'Illegal Record Access'
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Uuid,Void/Retire,Entity name,Attribute Type,System,Use,Rank,_order:1000
2+
fa48acc4-ef1f-46d6-b0af-150b00ddee9d,,person,717ec942-3c4a-11ea-b024-ffc81a23382e,phone,work,1,
3+
,,person,PAT_RENAME_NEW_NAME,phone,home,,
4+
bcf23315-a236-42aa-be95-b9e0931e22b0,,provider,Provider Speciality,email,home,2,
5+
800e48ba-666c-445c-b871-68e54eec6de8,,location,e7aacc6e-d151-4d9e-a808-6ed9ff761212,phone,temp,3,

0 commit comments

Comments
 (0)