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 Nov 14, 2023
1 parent db6d291 commit 825acb5
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -60,6 +60,7 @@ configuration/
├── encounterroles/
├── fhirconceptsources/
├── fhirpatientidentifiersystems/
├── fhirContactPointMap/
├── globalproperties/
├── htmlforms/
├── idgen/
Expand Down
46 changes: 46 additions & 0 deletions api-2.6/pom.xml
@@ -0,0 +1,46 @@
<?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">

<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>initializer</artifactId>
<version>2.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>initializer-api-2.6</artifactId>
<packaging>jar</packaging>
<name>Initializer API 2.6</name>
<description>API 2.6 project for Initializer</description>

<properties>
<openmrsPlatformVersion>${openmrsVersion2.6}</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>
</dependencies>

</project>
@@ -0,0 +1,147 @@
/**
* 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.
* <p>
* 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.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.6.3 - 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.getFhirContactPointMapByUuid(line.getUuid())
.orElse(null);
}

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);
case PROVIDER:
baseAttributeType = providerService.getProviderAttributeTypeByName(attributeType);

if (baseAttributeType != null) {
return baseAttributeType;
}

return providerService.getProviderAttributeTypeByUuid(attributeType);
}
return baseAttributeType;
}
}
@@ -0,0 +1,59 @@
/**
* 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.
* <p>
* 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.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.6.3 - 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;
}
}
@@ -0,0 +1,25 @@
/**
* 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.
* <p>
* 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.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.6.3 - 2.6.*, 2.7.* - 9.*")
public class FhirContactPointMapLoader extends BaseCsvLoader<FhirContactPointMap, FhirContactPointMapCsvParser> {

@Autowired
public void setParser(FhirContactPointMapCsvParser parser) {
this.parser = parser;
}

}
@@ -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.
* <p>
* 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_6_Test extends DomainBaseModuleContextSensitiveTest {

@Override
public void updateSearchIndex() {
// to prevent Data Filter's 'Illegal Record Access'
}
}

0 comments on commit 825acb5

Please sign in to comment.