Skip to content

Commit 2ded69e

Browse files
committed
add fhir contact point map to initializer
1 parent db6d291 commit 2ded69e

File tree

12 files changed

+453
-4
lines changed

12 files changed

+453
-4
lines changed

api-2.5/pom.xml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
6+
<parent>
7+
<groupId>org.openmrs.module</groupId>
8+
<artifactId>initializer</artifactId>
9+
<version>2.7.0-SNAPSHOT</version>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>initializer-api-2.5</artifactId>
14+
<packaging>jar</packaging>
15+
<name>Initializer API 2.5</name>
16+
<description>API 2.5 project for Initializer</description>
17+
18+
<properties>
19+
<openmrsPlatformVersion>${openmrsVersion2.5}</openmrsPlatformVersion>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>${project.parent.groupId}</groupId>
25+
<artifactId>${project.parent.artifactId}-api</artifactId>
26+
<version>${project.parent.version}</version>
27+
<scope>provided</scope>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>${project.parent.groupId}</groupId>
32+
<artifactId>${project.parent.artifactId}-api</artifactId>
33+
<version>${project.parent.version}</version>
34+
<scope>test</scope>
35+
<type>test-jar</type>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>${project.parent.groupId}</groupId>
40+
<artifactId>${project.parent.artifactId}-api-2.4</artifactId>
41+
<version>${project.parent.version}</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>${project.parent.groupId}</groupId>
47+
<artifactId>${project.parent.artifactId}-api-2.3</artifactId>
48+
<version>${project.parent.version}</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>${project.parent.groupId}</groupId>
54+
<artifactId>${project.parent.artifactId}-api-2.3</artifactId>
55+
<version>${project.parent.version}</version>
56+
<scope>test</scope>
57+
<type>test-jar</type>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>${project.parent.groupId}</groupId>
62+
<artifactId>${project.parent.artifactId}-api-2.2</artifactId>
63+
<version>${project.parent.version}</version>
64+
<scope>provided</scope>
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>test</scope>
72+
<type>test-jar</type>
73+
</dependency>
74+
</dependencies>
75+
76+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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.getFhirContactPointMapByUuid(line.getUuid())
53+
.orElse(null);
54+
}
55+
56+
if (contactPointMap != null) {
57+
return contactPointMap;
58+
}
59+
60+
String attributeTypeDomain = line.get(ATTRIBUTE_TYPE_DOMAIN_HEADER, true);
61+
String attributeType = line.get(ATTRIBUTE_TYPE, true);
62+
63+
if (attributeTypeDomain.equals(PERSON)) {
64+
PersonAttributeType personAttributeType = getPersonAttributeType(attributeType);
65+
66+
if (personAttributeType == null) {
67+
throw new IllegalArgumentException("PersonAttributeType " + attributeType
68+
+ " does not exist. Please ensure your Initializer configuration contains this attribute type.");
69+
}
70+
71+
contactPointMap = fhirContactPointMapService.getFhirContactPointMapForPersonAttributeType(personAttributeType)
72+
.orElse(null);
73+
} else {
74+
BaseAttributeType<?> baseAttributeType = getBaseAttributeType(attributeTypeDomain, attributeType);
75+
76+
if (baseAttributeType == null) {
77+
throw new IllegalArgumentException(
78+
"Could not find attribute type " + attributeType + " for attribute domain " + attributeTypeDomain);
79+
}
80+
81+
contactPointMap = fhirContactPointMapService.getFhirContactPointMapForAttributeType(baseAttributeType)
82+
.orElse(null);
83+
}
84+
85+
if (contactPointMap != null) {
86+
return contactPointMap;
87+
}
88+
89+
return new FhirContactPointMap();
90+
}
91+
92+
93+
@Override
94+
public FhirContactPointMap save(FhirContactPointMap instance) {
95+
return fhirContactPointMapService.saveFhirContactPointMap(instance);
96+
}
97+
98+
@Override
99+
public Domain getDomain() {
100+
return Domain.FHIR_CONTACT_POINT_MAP;
101+
}
102+
103+
protected PersonAttributeType getPersonAttributeType(String attributeType) {
104+
PersonAttributeType personAttributeType = personService.getPersonAttributeTypeByName(attributeType);
105+
106+
if (personAttributeType != null) {
107+
return personAttributeType;
108+
}
109+
110+
personAttributeType = personService.getPersonAttributeTypeByUuid(attributeType);
111+
112+
return personAttributeType;
113+
}
114+
115+
protected BaseAttributeType<?> getBaseAttributeType(String attributeDomain, String attributeType) {
116+
BaseAttributeType<?> baseAttributeType = null;
117+
118+
switch (attributeDomain) {
119+
case LOCATION:
120+
baseAttributeType = locationService.getLocationAttributeTypeByName(attributeType);
121+
122+
if (baseAttributeType != null) {
123+
return baseAttributeType;
124+
}
125+
126+
return locationService.getLocationAttributeTypeByUuid(attributeType);
127+
break;
128+
case PROVIDER:
129+
baseAttributeType = providerService.getProviderAttributeTypeByName(attributeType);
130+
131+
if (baseAttributeType != null) {
132+
return baseAttributeType;
133+
}
134+
135+
return providerService.getProviderAttributeTypeByUuid(attributeType);
136+
break;
137+
}
138+
return baseAttributeType;
139+
}
140+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.openmrs.module.initializer.api.fhir.cpm;
2+
3+
import org.openmrs.annotation.OpenmrsProfile;
4+
import org.openmrs.module.fhir2.model.FhirContactPointMap;
5+
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
8+
@OpenmrsProfile(modules = { "fhir2:1.11.* - 9.*" }, openmrsPlatformVersion = "2.5.13 - 2.5.*, 2.6.2 - 2.6.*, 2.7.* - 9.*")
9+
public class FhirContactPointMapLoader extends BaseCsvLoader<FhirContactPointMap, FhirContactPointMapCsvParser> {
10+
11+
@Autowired
12+
public void setParser(FhirContactPointMapCsvParser parser) {
13+
this.parser = parser;
14+
}
15+
16+
}
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+
}
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,

api/src/main/java/org/openmrs/module/initializer/Domain.java

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public enum Domain {
4646
COHORT_ATTRIBUTE_TYPES,
4747
FHIR_CONCEPT_SOURCES,
4848
FHIR_PATIENT_IDENTIFIER_SYSTEMS,
49+
FHIR_CONTACT_POINT_MAP,
4950
AMPATH_FORMS,
5051
AMPATH_FORMS_TRANSLATIONS,
5152
HTML_FORMS;

0 commit comments

Comments
 (0)