Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new FhirContactPoints domain #253

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ configuration/
├── encounterroles/
├── fhirconceptsources/
├── fhirpatientidentifiersystems/
├── fhircontactpointmaps/
├── globalproperties/
├── htmlforms/
├── idgen/
Expand Down Expand Up @@ -149,6 +150,7 @@ This is the list of currently supported domains in their loading order:
1. [Cohort Attribute Types (CSV files)](readme/cohort.md#domain-cohortattributetypes)
1. [FHIR Concept Sources (CSV files)](readme/fhir.md#domain-fhirconceptsources)
1. [FHIR Patient Identifier Systems (CSV Files)](readme/fhir.md#domain-fhirpatientidentifiersystems)
2. [FHIR Contact Point Map (CSV Files)](readme/fhir.md#domain-fhircontactpointmap)
1. [AMPATH Forms (JSON files)](readme/ampathforms.md)
1. [AMPATH Forms Translations (JSON files)](readme/ampathformstranslations.md)
1. [HTML Forms (XML files)](readme/htmlforms.md)
Expand Down Expand Up @@ -201,6 +203,7 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo
* Fix for OCL Loader to ensure it throws an Exception if the OCL import fails.
* Fix for Validator to not encounter failure upon repeated execution on the same JVM process.
* Fix for null config directory path in `DeleteDomainChecksumsChangeset`.
* Added support for 'fhircontactpointmap' domain.

#### Version 2.6.0
* Added support for 'cohorttypes' and 'cohortattributetypes' domains.
Expand Down
136 changes: 136 additions & 0 deletions api-2.6/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update this now that 2.7.0 is released. I guess this should be 2.8.0-SNAPSHOT.

</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>
<fhir2Version>1.11.0</fhir2Version>
<datafilterVersion>2.2.0</datafilterVersion>
</properties>

<dependencies>
<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<version>${openmrsPlatformVersion}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
</exclusion>
</exclusions>
</dependency>

<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.5</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api-2.5</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>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api-2.5</artifactId>
<version>${fhir2Version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api-2.6</artifactId>
<version>${fhir2Version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>datafilter-api</artifactId>
<version>${datafilterVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>queue-api</artifactId>
<version>${queueVersion}</version>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/**
* 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;
import org.springframework.stereotype.Component;

@Component
@OpenmrsProfile(modules = { "fhir2:1.11.0" }, openmrsPlatformVersion = "2.6.3")
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;
}

return personService.getPersonAttributeTypeByUuid(attributeType);
}

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* 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 org.springframework.stereotype.Component;

import static org.openmrs.module.initializer.api.fhir.cpm.FhirContactPointMapCsvParser.ATTRIBUTE_TYPE_DOMAIN_HEADER;

@Component
@OpenmrsProfile(modules = { "fhir2:1.11.0" }, openmrsPlatformVersion = "2.6.3")
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;
}
}
Loading