Skip to content

Commit 825acb5

Browse files
committed
add fhir contact point map to initializer
1 parent db6d291 commit 825acb5

File tree

13 files changed

+458
-4
lines changed

13 files changed

+458
-4
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ configuration/
6060
├── encounterroles/
6161
├── fhirconceptsources/
6262
├── fhirpatientidentifiersystems/
63+
├── fhirContactPointMap/
6364
├── globalproperties/
6465
├── htmlforms/
6566
├── idgen/

Diff for: api-2.6/pom.xml

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

0 commit comments

Comments
 (0)