Skip to content

Commit

Permalink
add fhir contact point map to initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Oct 18, 2023
1 parent db6d291 commit 48ec7d4
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 4 deletions.
75 changes: 75 additions & 0 deletions api-2.5/pom.xml
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>
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;
}
}
}
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;
}
}
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;
}

}
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'
}
}
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,
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public enum Domain {
COHORT_ATTRIBUTE_TYPES,
FHIR_CONCEPT_SOURCES,
FHIR_PATIENT_IDENTIFIER_SYSTEMS,
FHIR_CONTACT_POINT_MAP,
AMPATH_FORMS,
AMPATH_FORMS_TRANSLATIONS,
HTML_FORMS;
Expand Down
Loading

0 comments on commit 48ec7d4

Please sign in to comment.