-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fhir contact point map to initializer
- Loading branch information
Showing
12 changed files
with
449 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.openmrs.module</groupId> | ||
<artifactId>initializer</artifactId> | ||
<version>2.6.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>initializer-api-2.5</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Initializer API 2.5</name> | ||
<description>API 2.5 project for Initializer</description> | ||
|
||
<properties> | ||
<openmrsPlatformVersion>${openmrsVersion2.5}</openmrsPlatformVersion> | ||
</properties> | ||
|
||
<dependencies> | ||
<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.4</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-api-2.3</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-api-2.3</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> | ||
</dependencies> | ||
|
||
</project> |
138 changes: 138 additions & 0 deletions
138
...c/main/java/org/openmrs/module/initializer/api/fhir/cpm/FhirContactPointMapCsvParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package org.openmrs.module.initializer.api.fhir.cpm; | ||
|
||
import org.openmrs.PersonAttributeType; | ||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.api.LocationService; | ||
import org.openmrs.api.PersonService; | ||
import org.openmrs.api.ProviderService; | ||
import org.openmrs.attribute.BaseAttributeType; | ||
import org.openmrs.module.fhir2.api.FhirContactPointMapService; | ||
import org.openmrs.module.initializer.Domain; | ||
import org.openmrs.module.fhir2.model.FhirContactPointMap; | ||
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.Autowired; | ||
|
||
@OpenmrsProfile(modules = { "fhir2:1.11.* - 9.*" }, openmrsPlatformVersion = "2.5.13 - 2.5.*, 2.6.2 - 2.6.*, 2.7.* - 9.*") | ||
public class FhirContactPointMapCsvParser extends CsvParser<FhirContactPointMap, BaseLineProcessor<FhirContactPointMap>> { | ||
|
||
public static final String ATTRIBUTE_TYPE_DOMAIN_HEADER = "Entity name"; | ||
|
||
public static final String ATTRIBUTE_TYPE = "Attribute type"; | ||
|
||
private static final String LOCATION = "location"; | ||
|
||
private static final String PERSON = "person"; | ||
|
||
private static final String PROVIDER = "provider"; | ||
|
||
private final LocationService locationService; | ||
|
||
private final PersonService personService; | ||
|
||
private final ProviderService providerService; | ||
|
||
private final FhirContactPointMapService fhirContactPointMapService; | ||
|
||
@Autowired | ||
protected FhirContactPointMapCsvParser(FhirContactPointMapService fhirContactPointMapService,BaseLineProcessor<FhirContactPointMap> lineProcessor, | ||
LocationService locationService, PersonService personService, ProviderService providerService) { | ||
super(lineProcessor); | ||
this.fhirContactPointMapService = fhirContactPointMapService; | ||
this.locationService = locationService; | ||
this.personService = personService; | ||
this.providerService = providerService; | ||
} | ||
|
||
@Override | ||
public FhirContactPointMap bootstrap(CsvLine line) throws IllegalArgumentException { | ||
FhirContactPointMap contactPointMap = null; | ||
if (line.getUuid() != null) { | ||
contactPointMap = fhirContactPointMapService.getFhirConactPointMapByUuid(line.getUuid()); | ||
} | ||
|
||
if (contactPointMap != null) { | ||
return contactPointMap; | ||
} | ||
|
||
String attributeTypeDomain = line.get(ATTRIBUTE_TYPE_DOMAIN_HEADER, true); | ||
String attributeType = line.get(ATTRIBUTE_TYPE, true); | ||
|
||
if (attributeTypeDomain.equals(PERSON)) { | ||
PersonAttributeType personAttributeType = getPersonAttributeType(attributeType); | ||
|
||
if (personAttributeType == null) { | ||
throw new IllegalArgumentException("PersonAttributeType " + attributeType | ||
+ " does not exist. Please ensure your Initializer configuration contains this attribute type."); | ||
} | ||
|
||
contactPointMap = fhirContactPointMapService.getFhirContactPointMapForPersonAttributeType(personAttributeType) | ||
.orElse(null); | ||
} else { | ||
BaseAttributeType<?> baseAttributeType = getBaseAttributeType(attributeTypeDomain, attributeType); | ||
|
||
if (baseAttributeType == null) { | ||
throw new IllegalArgumentException( | ||
"Could not find attribute type " + attributeType + " for attribute domain " + attributeTypeDomain); | ||
} | ||
|
||
contactPointMap = fhirContactPointMapService.getFhirContactPointMapForAttributeType(baseAttributeType) | ||
.orElse(null); | ||
} | ||
|
||
if (contactPointMap != null) { | ||
return contactPointMap; | ||
} | ||
|
||
return new FhirContactPointMap(); | ||
} | ||
|
||
|
||
@Override | ||
public FhirContactPointMap save(FhirContactPointMap instance) { | ||
return fhirContactPointMapService.saveFhirContactPointMap(instance); | ||
} | ||
|
||
@Override | ||
public Domain getDomain() { | ||
return Domain.FHIR_CONTACT_POINT_MAP; | ||
} | ||
|
||
protected PersonAttributeType getPersonAttributeType(String attributeType) { | ||
PersonAttributeType personAttributeType = personService.getPersonAttributeTypeByName(attributeType); | ||
|
||
if (personAttributeType != null) { | ||
return personAttributeType; | ||
} | ||
|
||
personAttributeType = personService.getPersonAttributeTypeByUuid(attributeType); | ||
|
||
return personAttributeType; | ||
} | ||
|
||
protected BaseAttributeType<?> getBaseAttributeType(String attributeDomain, String attributeType) { | ||
BaseAttributeType<?> baseAttributeType = null; | ||
|
||
switch (attributeDomain) { | ||
case LOCATION: | ||
baseAttributeType = locationService.getLocationAttributeTypeByName(attributeType); | ||
|
||
if (baseAttributeType != null) { | ||
return baseAttributeType; | ||
} | ||
|
||
return locationService.getLocationAttributeTypeByUuid(attributeType); | ||
break; | ||
case PROVIDER: | ||
baseAttributeType = providerService.getProviderAttributeTypeByName(attributeType); | ||
|
||
if (baseAttributeType != null) { | ||
return baseAttributeType; | ||
} | ||
|
||
return providerService.getProviderAttributeTypeByUuid(attributeType); | ||
break; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...in/java/org/openmrs/module/initializer/api/fhir/cpm/FhirContactPointMapLineProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.openmrs.module.initializer.api.fhir.cpm; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.hl7.fhir.r4.model.ContactPoint; | ||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.module.fhir2.model.FhirContactPointMap; | ||
import org.openmrs.module.initializer.api.BaseLineProcessor; | ||
import org.openmrs.module.initializer.api.CsvLine; | ||
|
||
import static org.openmrs.module.initializer.api.fhir.cpm.FhirContactPointMapCsvParser.ATTRIBUTE_TYPE_DOMAIN_HEADER; | ||
|
||
@OpenmrsProfile(modules = { "fhir2:1.11.* - 9.*" }, openmrsPlatformVersion = "2.5.13 - 2.5.*, 2.6.2 - 2.6.*, 2.7.* - 9.*") | ||
public class FhirContactPointMapLineProcessor extends BaseLineProcessor<FhirContactPointMap> { | ||
|
||
private static final String SYSTEM_HEADER = "system"; | ||
private static final String USE_HEADER = "use"; | ||
private static final String RANK_HEADER = "rank"; | ||
@Override | ||
public FhirContactPointMap fill(FhirContactPointMap instance, CsvLine line) throws IllegalArgumentException { | ||
String uuid = line.getUuid(); | ||
|
||
if (StringUtils.isNotBlank(uuid)) { | ||
instance.setUuid(line.getUuid()); | ||
} | ||
|
||
line.get(ATTRIBUTE_TYPE_DOMAIN_HEADER, true); | ||
|
||
String system = line.get(SYSTEM_HEADER, false); | ||
String use = line.get(USE_HEADER, false); | ||
String rank = line.get(RANK_HEADER, false); | ||
|
||
if (system != null) { | ||
instance.setSystem(ContactPoint.ContactPointSystem.valueOf(system)); | ||
} | ||
|
||
if (use != null) { | ||
instance.setUse(ContactPoint.ContactPointUse.valueOf(use)); | ||
} | ||
|
||
if (rank != null) { | ||
int rankInt = Integer.parseInt(rank); | ||
if (rankInt < 1) { | ||
throw new IllegalArgumentException("Rank must be a positive integer, i.e., 1+"); | ||
} | ||
instance.setRank(rankInt); | ||
} | ||
|
||
return instance; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../src/main/java/org/openmrs/module/initializer/api/fhir/cpm/FhirContactPointMapLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.openmrs.module.initializer.api.fhir.cpm; | ||
|
||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.module.fhir2.model.FhirContactPointMap; | ||
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@OpenmrsProfile(modules = { "fhir2:1.11.* - 9.*" }, openmrsPlatformVersion = "2.5.13 - 2.5.*, 2.6.2 - 2.6.*, 2.7.* - 9.*") | ||
public class FhirContactPointMapLoader extends BaseCsvLoader<FhirContactPointMap, FhirContactPointMapCsvParser> { | ||
|
||
@Autowired | ||
public void setParser(FhirContactPointMapCsvParser parser) { | ||
this.parser = parser; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...c/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitive_2_5_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.initializer; | ||
|
||
public abstract class DomainBaseModuleContextSensitive_2_5_Test extends DomainBaseModuleContextSensitiveTest { | ||
|
||
@Override | ||
public void updateSearchIndex() { | ||
// to prevent Data Filter's 'Illegal Record Access' | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...5/src/test/resources/testAppDataDir/configuration/fhircontactpointmap/contactPointMap.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Uuid,Void/Retire,Entity name,Attribute Type,System,Use,Rank,_order:1000 | ||
fa48acc4-ef1f-46d6-b0af-150b00ddee9d,,person,717ec942-3c4a-11ea-b024-ffc81a23382e,phone,work,1, | ||
,,person,PAT_RENAME_NEW_NAME,phone,home,, | ||
bcf23315-a236-42aa-be95-b9e0931e22b0,,provider,Provider Speciality,email,home,2, | ||
800e48ba-666c-445c-b871-68e54eec6de8,,location,e7aacc6e-d151-4d9e-a808-6ed9ff761212,phone,temp,3, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.