diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 953cfaf704..e6585c8ce5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,11 +29,11 @@ jobs: - name: Build with Maven id: build_with_maven run: | - mvn verify --batch-mode -P integration-test --file pom.xml + mvn clean verify --batch-mode -P integration-test --file pom.xml - uses: actions/upload-artifact@v4 with: name: build_artifact - path: ${{ github.workspace }}/omod/target + path: ${{ github.workspace }}/omod/target/*.omod - name: Send data to Codecov uses: codecov/codecov-action@v4 with: diff --git a/api/src/main/java/org/openmrs/module/fhir2/FhirActivator.java b/api/src/main/java/org/openmrs/module/fhir2/FhirActivator.java index eb4a057ece..03cb45e72a 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/FhirActivator.java +++ b/api/src/main/java/org/openmrs/module/fhir2/FhirActivator.java @@ -27,6 +27,7 @@ import ca.uhn.fhir.rest.server.IResourceProvider; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.openmrs.api.context.Context; import org.openmrs.module.BaseModuleActivator; import org.openmrs.module.Module; import org.openmrs.module.ModuleException; @@ -36,6 +37,7 @@ import org.openmrs.module.fhir2.api.spi.ModuleLifecycleListener; import org.openmrs.module.fhir2.api.spi.ServiceClassLoader; import org.openmrs.module.fhir2.api.translators.FhirTranslator; +import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder; import org.openmrs.module.fhir2.model.GroupMember; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -53,6 +55,8 @@ public class FhirActivator extends BaseModuleActivator implements ApplicationCon @Getter private static ConfigurableApplicationContext applicationContext; + private static FhirGlobalPropertyHolder globalPropertyHolder = null; + private final Map>> services = new HashMap<>(); private final List lifecycleListeners = new ArrayList<>(); @@ -76,12 +80,24 @@ public void started() { @Override public void willRefreshContext() { + if (globalPropertyHolder != null) { + Context.getAdministrationService().removeGlobalPropertyListener(globalPropertyHolder); + } + lifecycleListeners.forEach(ModuleLifecycleListener::willRefresh); unloadModules(); } @Override public void contextRefreshed() { + if (globalPropertyHolder == null) { + globalPropertyHolder = new FhirGlobalPropertyHolder(); + } + + FhirGlobalPropertyHolder.reset(); + + Context.getAdministrationService().addGlobalPropertyListener(globalPropertyHolder); + if (!started) { return; } @@ -96,12 +112,17 @@ public void contextRefreshed() { public void willStop() { lifecycleListeners.forEach(ModuleLifecycleListener::willStop); unloadModules(); + + if (globalPropertyHolder != null) { + Context.getAdministrationService().removeGlobalPropertyListener(globalPropertyHolder); + } } @Override public void stopped() { lifecycleListeners.forEach(ModuleLifecycleListener::stopped); + globalPropertyHolder = null; started = false; log.info("Shutdown FHIR"); } @@ -117,7 +138,7 @@ public void removeModuleLifecycleLister(@Nonnull ModuleLifecycleListener lifecyc } @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + public void setApplicationContext(@Nonnull ApplicationContext applicationContext) throws BeansException { if (applicationContext instanceof ConfigurableApplicationContext) { FhirActivator.applicationContext = (ConfigurableApplicationContext) applicationContext; } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirGlobalPropertyService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirGlobalPropertyService.java index 8966153cd4..c09f3e5bb7 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/FhirGlobalPropertyService.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirGlobalPropertyService.java @@ -17,7 +17,7 @@ public interface FhirGlobalPropertyService { String getGlobalProperty(String property) throws APIException; - Integer getGlobalProperty(String property, Integer defaultValue); + int getGlobalPropertyAsInteger(String property, int defaultValue); String getGlobalProperty(String property, String defaultValue); diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirGlobalPropertyDao.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirGlobalPropertyDao.java deleted file mode 100644 index 03837df24c..0000000000 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirGlobalPropertyDao.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.fhir2.api.dao; - -import java.util.Map; - -import org.openmrs.GlobalProperty; -import org.openmrs.annotation.Authorized; -import org.openmrs.api.APIException; -import org.openmrs.util.PrivilegeConstants; - -public interface FhirGlobalPropertyDao { - - @Authorized(PrivilegeConstants.GET_GLOBAL_PROPERTIES) - String getGlobalProperty(String property) throws APIException; - - @Authorized(PrivilegeConstants.GET_GLOBAL_PROPERTIES) - GlobalProperty getGlobalPropertyObject(String property); - - @Authorized(PrivilegeConstants.GET_GLOBAL_PROPERTIES) - Map getGlobalProperties(String... properties); -} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImpl.java deleted file mode 100644 index 2084f7c771..0000000000 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.fhir2.api.dao.impl; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import lombok.AccessLevel; -import lombok.Setter; -import org.hibernate.SessionFactory; -import org.hibernate.criterion.Restrictions; -import org.openmrs.GlobalProperty; -import org.openmrs.api.APIException; -import org.openmrs.module.fhir2.api.dao.FhirGlobalPropertyDao; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -@Component -@Setter(AccessLevel.PACKAGE) -public class FhirGlobalPropertyDaoImpl implements FhirGlobalPropertyDao { - - @Autowired - @Qualifier("sessionFactory") - private SessionFactory sessionFactory; - - @Override - public String getGlobalProperty(String property) throws APIException { - GlobalProperty globalProperty = (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.class, - property); - return globalProperty == null ? null : globalProperty.getPropertyValue(); - } - - @Override - public GlobalProperty getGlobalPropertyObject(String property) { - return (GlobalProperty) sessionFactory.getCurrentSession().createCriteria(GlobalProperty.class) - .add(Restrictions.eq("property", property)).uniqueResult(); - } - - @Override - @SuppressWarnings("unchecked") - public Map getGlobalProperties(String... properties) { - Map globalPropertiesMap = new HashMap<>(); - - Collection globalProperties = (sessionFactory.getCurrentSession() - .createCriteria(GlobalProperty.class).add(Restrictions.in("property", properties)).list()); - - for (GlobalProperty property : globalProperties) { - globalPropertiesMap.put(property.getProperty(), property.getPropertyValue()); - } - - return globalPropertiesMap; - } -} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImpl.java index a6f9204fc1..215da03982 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImpl.java @@ -15,45 +15,30 @@ import lombok.Setter; import org.openmrs.api.APIException; import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; -import org.openmrs.module.fhir2.api.dao.FhirGlobalPropertyDao; -import org.springframework.beans.factory.annotation.Autowired; +import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; @Component -@Transactional @Setter(AccessLevel.PACKAGE) public class FhirGlobalPropertyServiceImpl implements FhirGlobalPropertyService { - @Autowired - private FhirGlobalPropertyDao dao; - @Override - @Transactional(readOnly = true) public String getGlobalProperty(String property) throws APIException { - return dao.getGlobalProperty(property); + return FhirGlobalPropertyHolder.getGlobalProperty(property); } @Override - @Transactional(readOnly = true) - public Integer getGlobalProperty(String property, Integer defaultValue) { - try { - return Integer.valueOf(getGlobalProperty(property, String.valueOf(defaultValue))); - } - catch (NumberFormatException e) { - return defaultValue; - } + public int getGlobalPropertyAsInteger(String property, int defaultValue) { + return FhirGlobalPropertyHolder.getGlobalPropertyAsInteger(property, defaultValue); } @Override - @Transactional(readOnly = true) public String getGlobalProperty(String property, String defaultValue) { - return this.getGlobalProperty(property) == null ? defaultValue : this.getGlobalProperty(property); + return FhirGlobalPropertyHolder.getGlobalProperty(property, defaultValue); } @Override - @Transactional(readOnly = true) public Map getGlobalProperties(String... properties) { - return dao.getGlobalProperties(properties); + return FhirGlobalPropertyHolder.getGlobalProperties(properties); } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProvider.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProvider.java index 4d7667b1b7..a8e1079a0f 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProvider.java @@ -93,7 +93,7 @@ public List getResources(int fromIndex, int toIndex) { @Override public Integer preferredPageSize() { if (pageSize == null) { - pageSize = globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10); + pageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10); } return pageSize; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/TwoSearchQueryBundleProvider.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/TwoSearchQueryBundleProvider.java index f40a8767d8..7317bd895a 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/search/TwoSearchQueryBundleProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/TwoSearchQueryBundleProvider.java @@ -122,7 +122,7 @@ public List getResources(int fromIndex, int toIndex) { @Override public Integer preferredPageSize() { if (pageSize == null) { - pageSize = globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10); + pageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10); } return pageSize; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImpl.java index d15622d4b1..ddb0f7715a 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImpl.java @@ -39,7 +39,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class AllergyIntoleranceTranslatorImpl extends BaseReferenceHandlingTranslator implements AllergyIntoleranceTranslator { +public class AllergyIntoleranceTranslatorImpl implements AllergyIntoleranceTranslator { @Autowired private PractitionerReferenceTranslator practitionerReferenceTranslator; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DiagnosticReportTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DiagnosticReportTranslatorImpl.java index ce9f36ad09..4b76219c60 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DiagnosticReportTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DiagnosticReportTranslatorImpl.java @@ -60,8 +60,13 @@ public DiagnosticReport toFhirResource(@Nonnull FhirDiagnosticReport fhirDiagnos diagnosticReport.setId(fhirDiagnosticReport.getUuid()); if (fhirDiagnosticReport.getStatus() != null) { - diagnosticReport - .setStatus(DiagnosticReport.DiagnosticReportStatus.valueOf(fhirDiagnosticReport.getStatus().toString())); + try { + diagnosticReport.setStatus( + DiagnosticReport.DiagnosticReportStatus.valueOf(fhirDiagnosticReport.getStatus().toString())); + } + catch (IllegalArgumentException e) { + diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN); + } } else { diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterLocationTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterLocationTranslatorImpl.java index bec37bee6a..2eecdc8610 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterLocationTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterLocationTranslatorImpl.java @@ -10,6 +10,8 @@ package org.openmrs.module.fhir2.api.translators.impl; import static org.apache.commons.lang3.Validate.notNull; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createLocationReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import javax.annotation.Nonnull; @@ -24,7 +26,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class EncounterLocationTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterLocationTranslator { +public class EncounterLocationTranslatorImpl implements EncounterLocationTranslator { @Autowired private FhirLocationDao locationDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterParticipantTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterParticipantTranslatorImpl.java index dbc272a9cc..63c818424e 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterParticipantTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterParticipantTranslatorImpl.java @@ -10,6 +10,8 @@ package org.openmrs.module.fhir2.api.translators.impl; import static org.apache.commons.lang3.Validate.notNull; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createPractitionerReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import javax.annotation.Nonnull; @@ -27,7 +29,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class EncounterParticipantTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterParticipantTranslator { +public class EncounterParticipantTranslatorImpl implements EncounterParticipantTranslator { private static final String DEFAULT_ENCOUNTER_ROLE_UUID_PROPERTY = "fhir2.encounterParticipantComponentUuid"; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImpl.java index 4b95798586..74d202ddbb 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createEncounterReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class EncounterReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterReferenceTranslator { +public class EncounterReferenceTranslatorImpl implements EncounterReferenceTranslator { @Autowired private FhirEncounterDao encounterDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImpl.java index f030283dc6..dd856ce19c 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImpl.java @@ -64,7 +64,8 @@ public PatientProgram toOpenmrsType(@Nonnull EpisodeOfCare episodeOfCare) { @Override public PatientProgram toOpenmrsType(@Nonnull PatientProgram patientProgram, @Nonnull EpisodeOfCare episodeOfCare) { - throw new UnsupportedOperationException("Translation from FHIR resource EpisodeOfCare to OpenMRS object PatientProgram is not supported."); + throw new UnsupportedOperationException( + "Translation from FHIR resource EpisodeOfCare to OpenMRS object PatientProgram is not supported."); } private List getType(PatientProgram patientProgram) { diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationReferenceTranslatorImpl.java index 5f00db8470..94dbeba68b 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createLocationReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class LocationReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements LocationReferenceTranslator { +public class LocationReferenceTranslatorImpl implements LocationReferenceTranslator { @Autowired private FhirLocationDao locationDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImpl.java index bc208aa89e..83611d17cc 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImpl.java @@ -16,6 +16,7 @@ import javax.annotation.Nonnull; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -34,6 +35,7 @@ import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; import org.openmrs.module.fhir2.api.dao.FhirLocationDao; import org.openmrs.module.fhir2.api.translators.LocationAddressTranslator; +import org.openmrs.module.fhir2.api.translators.LocationReferenceTranslator; import org.openmrs.module.fhir2.api.translators.LocationTagTranslator; import org.openmrs.module.fhir2.api.translators.LocationTranslator; import org.openmrs.module.fhir2.api.translators.LocationTypeTranslator; @@ -43,7 +45,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class LocationTranslatorImpl extends BaseReferenceHandlingTranslator implements LocationTranslator { +public class LocationTranslatorImpl implements LocationTranslator { @Autowired private LocationAddressTranslator locationAddressTranslator; @@ -51,6 +53,9 @@ public class LocationTranslatorImpl extends BaseReferenceHandlingTranslator impl @Autowired private LocationTagTranslator locationTagTranslator; + @Autowired + private LocationReferenceTranslator locationReferenceTranslator; + @Autowired private TelecomTranslator telecomTranslator; @@ -73,29 +78,37 @@ public Location toFhirResource(@Nonnull org.openmrs.Location openmrsLocation) { } Location fhirLocation = new Location(); - Location.LocationPositionComponent position = new Location.LocationPositionComponent(); fhirLocation.setId(openmrsLocation.getUuid()); fhirLocation.setName(getMetadataTranslation(openmrsLocation)); fhirLocation.setDescription(openmrsLocation.getDescription()); fhirLocation.setAddress(locationAddressTranslator.toFhirResource(openmrsLocation)); - double latitude = NumberUtils.toDouble(openmrsLocation.getLatitude(), -1.0d); - if (latitude >= 0.0d) { - position.setLatitude(latitude); + Location.LocationPositionComponent position = null; + if (openmrsLocation.getLatitude() != null && !openmrsLocation.getLatitude().isEmpty()) { + double latitude = NumberUtils.toDouble(openmrsLocation.getLatitude(), -1.0d); + if (latitude >= 0.0d) { + position = new Location.LocationPositionComponent(); + position.setLatitude(latitude); + } } - double longitude = NumberUtils.toDouble(openmrsLocation.getLongitude(), -1.0d); - if (longitude >= 0.0d) { - position.setLongitude(longitude); + if (openmrsLocation.getLongitude() != null && !openmrsLocation.getLongitude().isEmpty()) { + double longitude = NumberUtils.toDouble(openmrsLocation.getLongitude(), -1.0d); + if (longitude >= 0.0d) { + if (position == null) { + position = new Location.LocationPositionComponent(); + } + position.setLongitude(longitude); + } } - fhirLocation.setPosition(position); + if (position != null) { + fhirLocation.setPosition(position); + } if (!openmrsLocation.getRetired()) { fhirLocation.setStatus(Location.LocationStatus.ACTIVE); - } - - if (openmrsLocation.getRetired()) { + } else { fhirLocation.setStatus(Location.LocationStatus.INACTIVE); } @@ -103,16 +116,15 @@ public Location toFhirResource(@Nonnull org.openmrs.Location openmrsLocation) { fhirLocation.setType(locationTypeTranslator.toFhirResource(openmrsLocation)); - fhirLocation.setType(locationTypeTranslator.toFhirResource(openmrsLocation)); - if (openmrsLocation.getTags() != null) { for (LocationTag tag : openmrsLocation.getTags()) { fhirLocation.getMeta().addTag(FhirConstants.OPENMRS_FHIR_EXT_LOCATION_TAG, tag.getName(), tag.getDescription()); } } + if (openmrsLocation.getParentLocation() != null) { - fhirLocation.setPartOf(createLocationReference(openmrsLocation.getParentLocation())); + fhirLocation.setPartOf(locationReferenceTranslator.toFhirResource(openmrsLocation.getParentLocation())); } fhirLocation.getMeta().setLastUpdated(getLastUpdated(openmrsLocation)); @@ -122,9 +134,14 @@ public Location toFhirResource(@Nonnull org.openmrs.Location openmrsLocation) { } protected List getLocationContactDetails(@Nonnull org.openmrs.Location location) { - return fhirLocationDao - .getActiveAttributesByLocationAndAttributeTypeUuid(location, - propertyService.getGlobalProperty(FhirConstants.LOCATION_CONTACT_POINT_ATTRIBUTE_TYPE)) + String locationContactPointAttributeType = propertyService + .getGlobalProperty(FhirConstants.LOCATION_CONTACT_POINT_ATTRIBUTE_TYPE); + + if (locationContactPointAttributeType == null || locationContactPointAttributeType.isEmpty()) { + return Collections.emptyList(); + } + + return fhirLocationDao.getActiveAttributesByLocationAndAttributeTypeUuid(location, locationContactPointAttributeType) .stream().map(telecomTranslator::toFhirResource).collect(Collectors.toList()); } @@ -199,6 +216,6 @@ public org.openmrs.Location getOpenmrsParentLocation(Reference location) { throw new IllegalArgumentException("Reference must be to a Location not a " + location.getType()); } - return getReferenceId(location).map(uuid -> fhirLocationDao.get(uuid)).orElse(null); + return locationReferenceTranslator.toOpenmrsType(location); } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImpl.java index 734114c475..e170a1ee11 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImpl.java @@ -78,8 +78,12 @@ public List toFhirResource(@Nonnull Location location) { @Override public Location toOpenmrsType(@Nonnull Location location, @Nonnull List types) { - LocationAttributeType typeAttributeType = locationDao.getLocationAttributeTypeByUuid( - globalPropertyService.getGlobalProperty(FhirConstants.LOCATION_TYPE_ATTRIBUTE_TYPE)); + LocationAttributeType typeAttributeType = null; + + String locationAttributeType = globalPropertyService.getGlobalProperty(FhirConstants.LOCATION_TYPE_ATTRIBUTE_TYPE); + if (locationAttributeType != null && !locationAttributeType.isEmpty()) { + typeAttributeType = locationDao.getLocationAttributeTypeByUuid(locationAttributeType); + } if (typeAttributeType != null) { Optional typeConcept = types.stream().filter(Objects::nonNull).filter(CodeableConcept::hasCoding) diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImpl.java index b9e286f87f..68db489916 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createMedicationReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class MedicationReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements MedicationReferenceTranslator { +public class MedicationReferenceTranslatorImpl implements MedicationReferenceTranslator { @Autowired private FhirMedicationDao medicationDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImpl.java index ed685ae876..929b63d863 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createDrugOrderReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class MedicationRequestReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements MedicationRequestReferenceTranslator { +public class MedicationRequestReferenceTranslatorImpl implements MedicationRequestReferenceTranslator { @Autowired private FhirMedicationRequestDao medicationRequestDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java index 29db918872..b3834e38c8 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImpl.java @@ -38,6 +38,7 @@ import org.openmrs.module.fhir2.api.translators.MedicationReferenceTranslator; import org.openmrs.module.fhir2.api.translators.MedicationRequestDispenseRequestComponentTranslator; import org.openmrs.module.fhir2.api.translators.MedicationRequestPriorityTranslator; +import org.openmrs.module.fhir2.api.translators.MedicationRequestReferenceTranslator; import org.openmrs.module.fhir2.api.translators.MedicationRequestStatusTranslator; import org.openmrs.module.fhir2.api.translators.MedicationRequestTranslator; import org.openmrs.module.fhir2.api.translators.OrderIdentifierTranslator; @@ -48,7 +49,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class MedicationRequestTranslatorImpl extends BaseReferenceHandlingTranslator implements MedicationRequestTranslator { +public class MedicationRequestTranslatorImpl implements MedicationRequestTranslator { @Autowired private MedicationRequestStatusTranslator statusTranslator; @@ -59,6 +60,9 @@ public class MedicationRequestTranslatorImpl extends BaseReferenceHandlingTransl @Autowired private MedicationRequestPriorityTranslator medicationRequestPriorityTranslator; + @Autowired + private MedicationRequestReferenceTranslator medicationRequestReferenceTranslator; + @Autowired private MedicationReferenceTranslator medicationReferenceTranslator; @@ -115,11 +119,13 @@ public MedicationRequest toFhirResource(@Nonnull DrugOrder drugOrder) { if (drugOrder.getPreviousOrder() != null && (drugOrder.getAction() == Order.Action.DISCONTINUE || drugOrder.getAction() == Order.Action.REVISE)) { - medicationRequest.setPriorPrescription(createOrderReference(drugOrder.getPreviousOrder()) - .setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder()))); + medicationRequest.setPriorPrescription( + medicationRequestReferenceTranslator.toFhirResource((DrugOrder) drugOrder.getPreviousOrder()) + .setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder()))); } else if (drugOrder.getPreviousOrder() != null && drugOrder.getAction() == Order.Action.RENEW) { - medicationRequest.setBasedOn(Collections.singletonList(createOrderReference(drugOrder.getPreviousOrder()) - .setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder())))); + medicationRequest.setBasedOn(Collections.singletonList( + medicationRequestReferenceTranslator.toFhirResource((DrugOrder) drugOrder.getPreviousOrder()) + .setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder())))); } if (drugOrder.getFulfillerStatus() != null) { diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationBasedOnReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationBasedOnReferenceTranslatorImpl.java index d6642559c5..00f97b8860 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationBasedOnReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationBasedOnReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createOrderReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -25,7 +29,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class ObservationBasedOnReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements ObservationBasedOnReferenceTranslator { +public class ObservationBasedOnReferenceTranslatorImpl implements ObservationBasedOnReferenceTranslator { @Autowired private FhirServiceRequestDao serviceRequestDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImpl.java index 7ae756dcdb..ba29ba7ed2 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createObservationReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class ObservationReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements ObservationReferenceTranslator { +public class ObservationReferenceTranslatorImpl implements ObservationReferenceTranslator { @Autowired private FhirObservationDao observationDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationTranslatorImpl.java index 864d760832..c838476226 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationTranslatorImpl.java @@ -12,6 +12,7 @@ import static org.apache.commons.lang3.Validate.notNull; import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getLastUpdated; import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getVersionId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createLocationReferenceByUuid; import javax.annotation.Nonnull; @@ -48,7 +49,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class ObservationTranslatorImpl extends BaseReferenceHandlingTranslator implements ObservationTranslator { +public class ObservationTranslatorImpl implements ObservationTranslator { @Autowired private ObservationStatusTranslator observationStatusTranslator; @@ -165,7 +166,7 @@ public Obs toOpenmrsType(Obs existingObs, Observation observation, Supplier observationValueTranslator.toOpenmrsType(existingObs, observation.getValue()); - if (observation.getInterpretation().size() > 0) { + if (!observation.getInterpretation().isEmpty()) { interpretationTranslator.toOpenmrsType(existingObs, observation.getInterpretation().get(0)); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientIdentifierTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientIdentifierTranslatorImpl.java index b4b87b7246..c88f09e12f 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientIdentifierTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientIdentifierTranslatorImpl.java @@ -20,19 +20,24 @@ import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Type; +import org.openmrs.Location; import org.openmrs.PatientIdentifier; import org.openmrs.PatientIdentifierType; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.api.FhirPatientIdentifierSystemService; import org.openmrs.module.fhir2.api.FhirPatientService; import org.openmrs.module.fhir2.api.dao.FhirLocationDao; +import org.openmrs.module.fhir2.api.translators.LocationReferenceTranslator; import org.openmrs.module.fhir2.api.translators.PatientIdentifierTranslator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component @Setter(AccessLevel.PACKAGE) -public class PatientIdentifierTranslatorImpl extends BaseReferenceHandlingTranslator implements PatientIdentifierTranslator { +public class PatientIdentifierTranslatorImpl implements PatientIdentifierTranslator { + + @Autowired + private LocationReferenceTranslator locationReferenceTranslator; @Autowired private FhirPatientIdentifierSystemService patientIdentifierSystemService; @@ -70,7 +75,7 @@ public Identifier toFhirResource(@Nonnull PatientIdentifier identifier) { if (identifier.getLocation() != null) { patientIdentifier.addExtension().setUrl(FhirConstants.OPENMRS_FHIR_EXT_PATIENT_IDENTIFIER_LOCATION) - .setValue(createLocationReference(identifier.getLocation())); + .setValue(locationReferenceTranslator.toFhirResource(identifier.getLocation())); } return patientIdentifier; @@ -111,8 +116,10 @@ public PatientIdentifier toOpenmrsType(@Nonnull PatientIdentifier patientIdentif .getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_PATIENT_IDENTIFIER_LOCATION).getValue(); if (identifierLocationType instanceof Reference) { - getReferenceId((Reference) identifierLocationType).map(uuid -> locationDao.get(uuid)) - .ifPresent(patientIdentifier::setLocation); + Location location = locationReferenceTranslator.toOpenmrsType((Reference) identifierLocationType); + if (location != null) { + patientIdentifier.setLocation(location); + } } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImpl.java index deb5ab2af4..335a55cce4 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createPatientReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class PatientReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements PatientReferenceTranslator { +public class PatientReferenceTranslatorImpl implements PatientReferenceTranslator { @Autowired private FhirPatientDao patientDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImpl.java index aeeb7f8137..621bf270d0 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImpl.java @@ -15,6 +15,7 @@ import javax.annotation.Nonnull; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -119,10 +120,15 @@ public Patient toFhirResource(@Nonnull org.openmrs.Patient openmrsPatient) { } public List getPatientContactDetails(@Nonnull org.openmrs.Patient patient) { - return fhirPersonDao - .getActiveAttributesByPersonAndAttributeTypeUuid(patient, - globalPropertyService.getGlobalProperty(FhirConstants.PERSON_CONTACT_POINT_ATTRIBUTE_TYPE)) - .stream().map(telecomTranslator::toFhirResource).collect(Collectors.toList()); + String personContactAttributeType = globalPropertyService + .getGlobalProperty(FhirConstants.PERSON_CONTACT_POINT_ATTRIBUTE_TYPE); + + if (personContactAttributeType == null || personContactAttributeType.isEmpty()) { + return Collections.emptyList(); + } + + return fhirPersonDao.getActiveAttributesByPersonAndAttributeTypeUuid(patient, personContactAttributeType).stream() + .map(telecomTranslator::toFhirResource).collect(Collectors.toList()); } @Override diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImpl.java index 1c6919c461..9f657bdb91 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createPractitionerReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class PractitionerReferenceTranslatorProviderImpl extends BaseReferenceHandlingTranslator implements PractitionerReferenceTranslator { +public class PractitionerReferenceTranslatorProviderImpl implements PractitionerReferenceTranslator { @Autowired private FhirPractitionerDao practitionerDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImpl.java index 93ba2719b2..9670c29700 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createPractitionerReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class PractitionerReferenceTranslatorUserImpl extends BaseReferenceHandlingTranslator implements PractitionerReferenceTranslator { +public class PractitionerReferenceTranslatorUserImpl implements PractitionerReferenceTranslator { @Autowired private FhirUserDao userDao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerTranslatorProviderImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerTranslatorProviderImpl.java index cbcbcbf89b..6c57b55121 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerTranslatorProviderImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerTranslatorProviderImpl.java @@ -14,6 +14,7 @@ import javax.annotation.Nonnull; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -148,10 +149,16 @@ public Practitioner toFhirResource(@Nonnull Provider provider) { } public List getProviderContactDetails(@Nonnull Provider provider) { + String providerContactPointAttributeType = globalPropertyService + .getGlobalProperty(FhirConstants.PROVIDER_CONTACT_POINT_ATTRIBUTE_TYPE); + + if (providerContactPointAttributeType == null || providerContactPointAttributeType.isEmpty()) { + return Collections.emptyList(); + } + return fhirPractitionerDao - .getActiveAttributesByPractitionerAndAttributeTypeUuid(provider, - globalPropertyService.getGlobalProperty(FhirConstants.PROVIDER_CONTACT_POINT_ATTRIBUTE_TYPE)) - .stream().map(telecomTranslator::toFhirResource).collect(Collectors.toList()); + .getActiveAttributesByPractitionerAndAttributeTypeUuid(provider, providerContactPointAttributeType).stream() + .map(telecomTranslator::toFhirResource).collect(Collectors.toList()); } @Override diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/BaseReferenceHandlingTranslator.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ReferenceHandlingTranslator.java similarity index 80% rename from api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/BaseReferenceHandlingTranslator.java rename to api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ReferenceHandlingTranslator.java index d50e967ae7..a18b2deb50 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/BaseReferenceHandlingTranslator.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ReferenceHandlingTranslator.java @@ -41,22 +41,22 @@ @Setter(AccessLevel.PACKAGE) @Slf4j -public abstract class BaseReferenceHandlingTranslator { +public final class ReferenceHandlingTranslator { - protected Reference createEncounterReference(@Nonnull Encounter encounter) { + public static Reference createEncounterReference(@Nonnull Encounter encounter) { return createEncounterReference((OpenmrsObject) encounter); } - protected Reference createEncounterReference(@Nonnull Visit visit) { + public static Reference createEncounterReference(@Nonnull Visit visit) { return createEncounterReference((OpenmrsObject) visit); } - private Reference createEncounterReference(@Nonnull OpenmrsObject encounter) { + private static Reference createEncounterReference(@Nonnull OpenmrsObject encounter) { return new Reference().setReference(FhirConstants.ENCOUNTER + "/" + encounter.getUuid()) .setType(FhirConstants.ENCOUNTER); } - protected Reference createValueSetReference(@Nonnull Concept concept) { + public static Reference createValueSetReference(@Nonnull Concept concept) { if (concept == null || !concept.getSet()) { return null; } @@ -64,26 +64,26 @@ protected Reference createValueSetReference(@Nonnull Concept concept) { .setType(FhirConstants.VALUESET); } - protected Reference createMedicationReference(@Nonnull Drug drug) { + public static Reference createMedicationReference(@Nonnull Drug drug) { return new Reference().setReference(FhirConstants.MEDICATION + "/" + drug.getUuid()) .setType(FhirConstants.MEDICATION).setDisplay(drug.getDisplayName()); } - protected Reference createObservationReference(@Nonnull Obs obs) { + public static Reference createObservationReference(@Nonnull Obs obs) { return new Reference().setReference(FhirConstants.OBSERVATION + "/" + obs.getUuid()) .setType(FhirConstants.OBSERVATION); } - protected Reference createLocationReferenceByUuid(@Nonnull String uuid) { + public static Reference createLocationReferenceByUuid(@Nonnull String uuid) { return new Reference().setReference(FhirConstants.LOCATION + "/" + uuid).setType(FhirConstants.LOCATION); } - protected Reference createLocationReference(@Nonnull Location location) { + public static Reference createLocationReference(@Nonnull Location location) { return new Reference().setReference(FhirConstants.LOCATION + "/" + location.getUuid()) .setType(FhirConstants.LOCATION).setDisplay(getMetadataTranslation(location)); } - protected Reference createPatientReference(@Nonnull Patient patient) { + public static Reference createPatientReference(@Nonnull Patient patient) { Reference reference = new Reference().setReference(FhirConstants.PATIENT + "/" + patient.getUuid()) .setType(FhirConstants.PATIENT); @@ -108,7 +108,7 @@ protected Reference createPatientReference(@Nonnull Patient patient) { return reference; } - protected Reference createPractitionerReference(@Nonnull User user) { + public static Reference createPractitionerReference(@Nonnull User user) { Reference reference = new Reference().setReference(FhirConstants.PRACTITIONER + "/" + user.getUuid()) .setType(FhirConstants.PRACTITIONER); @@ -121,7 +121,7 @@ protected Reference createPractitionerReference(@Nonnull User user) { return reference; } - protected Reference createPractitionerReference(@Nonnull Provider provider) { + public static Reference createPractitionerReference(@Nonnull Provider provider) { Reference reference = new Reference().setReference(FhirConstants.PRACTITIONER + "/" + provider.getUuid()) .setType(FhirConstants.PRACTITIONER); @@ -144,7 +144,7 @@ protected Reference createPractitionerReference(@Nonnull Provider provider) { return reference; } - protected Reference createOrderReference(@Nonnull Order order) { + public static Reference createOrderReference(@Nonnull Order order) { if (order == null) { return null; } @@ -160,7 +160,7 @@ protected Reference createOrderReference(@Nonnull Order order) { } } - protected Reference createDrugOrderReference(@Nonnull DrugOrder drugOrder) { + public static Reference createDrugOrderReference(@Nonnull DrugOrder drugOrder) { if (drugOrder == null) { return null; } @@ -168,11 +168,11 @@ protected Reference createDrugOrderReference(@Nonnull DrugOrder drugOrder) { .setType(FhirConstants.MEDICATION_REQUEST); } - protected Optional getReferenceType(Reference reference) { + public static Optional getReferenceType(Reference reference) { return FhirUtils.getReferenceType(reference); } - protected Optional getReferenceId(Reference reference) { + public static Optional getReferenceId(Reference reference) { return FhirUtils.referenceToId(reference.getReference()); } } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImpl.java index 75b56e2c40..bfca486132 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImpl.java @@ -12,6 +12,7 @@ import static org.apache.commons.lang3.Validate.notNull; import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getLastUpdated; import static org.openmrs.module.fhir2.api.translators.impl.FhirTranslatorUtils.getVersionId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createOrderReference; import javax.annotation.Nonnull; @@ -47,7 +48,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class ServiceRequestTranslatorImpl extends BaseReferenceHandlingTranslator implements ServiceRequestTranslator { +public class ServiceRequestTranslatorImpl implements ServiceRequestTranslator { private static final int START_INDEX = 0; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetReferenceTranslatorImpl.java index dc649ba242..acb4a10a49 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetReferenceTranslatorImpl.java @@ -9,6 +9,8 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createValueSetReference; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -20,7 +22,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class ValueSetReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements ValueSetReferenceTranslator { +public class ValueSetReferenceTranslatorImpl implements ValueSetReferenceTranslator { @Override public Reference toFhirResource(@Nonnull Concept concept) { diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImpl.java index b5de0c28df..875353d4db 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImpl.java @@ -9,6 +9,10 @@ */ package org.openmrs.module.fhir2.api.translators.impl; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createEncounterReference; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType; + import javax.annotation.Nonnull; import lombok.AccessLevel; @@ -23,7 +27,7 @@ @Component @Setter(AccessLevel.PACKAGE) -public class VisitReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterReferenceTranslator { +public class VisitReferenceTranslatorImpl implements EncounterReferenceTranslator { @Autowired private FhirVisitDao dao; diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/util/FhirGlobalPropertyHolder.java b/api/src/main/java/org/openmrs/module/fhir2/api/util/FhirGlobalPropertyHolder.java new file mode 100644 index 0000000000..54b628bed2 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/util/FhirGlobalPropertyHolder.java @@ -0,0 +1,136 @@ +/* + * 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.fhir2.api.util; + +import static org.openmrs.module.fhir2.FhirConstants.FHIR2_MODULE_ID; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import org.openmrs.GlobalProperty; +import org.openmrs.api.APIException; +import org.openmrs.api.GlobalPropertyListener; +import org.openmrs.api.context.Context; +import org.openmrs.util.PrivilegeConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FhirGlobalPropertyHolder implements GlobalPropertyListener { + + private static final Logger log = LoggerFactory.getLogger(FhirGlobalPropertyHolder.class); + + private static final Map globalPropertyCache = new ConcurrentHashMap<>(1 << 4 << 4); + + // the idea of missing keys is essentially to store "cache misses" so we avoid needing to do unnecessary lookups + private static final Set missingKeys = ConcurrentHashMap.newKeySet(); + + public static String getGlobalProperty(String globalProperty) { + if (missingKeys.contains(globalProperty)) { + return null; + } else { + if (!supportsProperty(globalProperty)) { + return null; + } + + return globalPropertyCache.computeIfAbsent(globalProperty, (gp) -> { + String gpValue = null; + + boolean hasUserContext = false; + try { + Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES); + hasUserContext = true; + } + catch (APIException ignored) {} + + try { + gpValue = Context.getAdministrationService().getGlobalProperty(gp); + } + catch (APIException ignored) { + + } + finally { + if (hasUserContext) { + Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES); + } + } + + if (gpValue == null || gpValue.isEmpty()) { + missingKeys.add(gp); + return null; + } + + return gpValue; + }); + } + } + + public static String getGlobalProperty(String globalProperty, String defaultValue) { + return Optional.ofNullable(getGlobalProperty(globalProperty)).orElse(defaultValue); + } + + public static int getGlobalPropertyAsInteger(String globalProperty, int defaultValue) { + String globalPropertyValue = getGlobalProperty(globalProperty); + + if (globalPropertyValue == null || globalPropertyValue.isEmpty()) { + return defaultValue; + } + + try { + return Integer.parseInt(globalPropertyValue); + } + catch (NumberFormatException e) { + log.error("Error converting global property {} with value '{}' to an integer", globalProperty, + globalPropertyValue, e); + return defaultValue; + } + } + + public static Map getGlobalProperties(String... globalProperties) { + Map result = new HashMap<>(globalProperties.length); + for (String globalProperty : globalProperties) { + String globalPropertyValue = getGlobalProperty(globalProperty); + if (globalPropertyValue != null && !globalPropertyValue.isEmpty()) { + result.put(globalProperty, globalPropertyValue); + } + } + + return result; + } + + public static void reset() { + globalPropertyCache.clear(); + missingKeys.clear(); + } + + @Override + public boolean supportsPropertyName(String globalProperty) { + return supportsProperty(globalProperty); + } + + @Override + public void globalPropertyChanged(GlobalProperty globalProperty) { + globalPropertyCache.put(globalProperty.getProperty(), globalProperty.getPropertyValue()); + missingKeys.remove(globalProperty.getProperty()); + } + + @Override + public void globalPropertyDeleted(String globalProperty) { + globalPropertyCache.remove(globalProperty); + missingKeys.add(globalProperty); + } + + private static boolean supportsProperty(String globalProperty) { + return globalProperty != null + && (globalProperty.startsWith(FHIR2_MODULE_ID) || globalProperty.startsWith("allergy")); + } +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/util/FhirUtils.java b/api/src/main/java/org/openmrs/module/fhir2/api/util/FhirUtils.java index df73cb9479..0b1c3e5417 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/util/FhirUtils.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/util/FhirUtils.java @@ -29,6 +29,9 @@ @Slf4j public class FhirUtils { + private FhirUtils() { + } + public enum OpenmrsEncounterType { ENCOUNTER, VISIT, @@ -145,7 +148,6 @@ public static Optional getOpenmrsEncounterType(Encounter e * @return localization for the given metadata, from message source, in the authenticated locale */ public static String getMetadataTranslation(OpenmrsMetadata metadata) { - String className = metadata.getClass().getSimpleName(); String uuid = metadata.getUuid(); @@ -159,7 +161,6 @@ public static String getMetadataTranslation(OpenmrsMetadata metadata) { } public static String getMetadataTranslation(Concept concept) { - String className = concept.getClass().getSimpleName(); String uuid = concept.getUuid(); @@ -184,11 +185,12 @@ private static String getLocalization(String shortClassName, String uuid) { String code = "ui.i18n." + shortClassName + ".name." + uuid; String localization = null; try { - localization = Context.getMessageSourceService().getMessage(code); + localization = Context.getMessageSourceService().getMessage(code, null, Context.getLocale()); } catch (Exception e) { log.info("Caught exception while attempting to localize code [{}]", code, e); } + if (localization == null || localization.equals(code)) { return null; } else { diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index 4f79a86287..4f372de8cd 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -30,10 +30,10 @@ - + - + diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImplTest.java deleted file mode 100644 index 5b525a2c1d..0000000000 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImplTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.fhir2.api.dao.impl; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; - -import java.util.Map; - -import org.hibernate.SessionFactory; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.GlobalProperty; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirGlobalPropertyDaoImplTest extends BaseModuleContextSensitiveTest { - - private static final String PERSON_ATTRIBUE_TYPE_PROPERTY_VALUE = "1289123-230-23n210-11nj2"; - - private static final String PERSON_ATTRIBUTE_TYPE_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImplTest_initial_data.xml"; - - private static final String PERSON_ATTRIBUTE_TYPE_PROPERTY = "fhir2.personAttributeTypeUuid"; - - private static final String PERSON_ATTRIBUTE_TYPE_PROPERTY_NOT_FOUND = "fhir2.non-found"; - - private static final String GLOBAL_PROPERTY_UUID = "cd9d0baa-a88b-4553-907a-b4ea7811ebf8"; - - private static final String GLOBAL_PROPERTY_MODERATE = "1499AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - - @Autowired - private SessionFactory sessionFactory; - - private FhirGlobalPropertyDaoImpl dao; - - @Before - public void setUp() throws Exception { - dao = new FhirGlobalPropertyDaoImpl(); - dao.setSessionFactory(sessionFactory); - executeDataSet(PERSON_ATTRIBUTE_TYPE_INITIAL_DATA_XML); - } - - @Test - public void shouldRetrieveGlobalPropertyValueByProperty() { - String globalProperty = dao.getGlobalProperty(PERSON_ATTRIBUTE_TYPE_PROPERTY); - assertThat(globalProperty, notNullValue()); - assertThat(globalProperty, equalTo(PERSON_ATTRIBUE_TYPE_PROPERTY_VALUE)); - } - - @Test - public void shouldReturnNullWhenGlobalPropertyNotFound() { - String globalProperty = dao.getGlobalProperty(PERSON_ATTRIBUTE_TYPE_PROPERTY_NOT_FOUND); - assertThat(globalProperty, nullValue()); - } - - @Test - public void shouldReturnGlobalPropertyObjectWhenPropertyMatched() { - GlobalProperty property = dao.getGlobalPropertyObject(PERSON_ATTRIBUTE_TYPE_PROPERTY); - assertThat(property, notNullValue()); - assertThat(property.getUuid(), notNullValue()); - assertThat(property.getUuid(), equalTo(GLOBAL_PROPERTY_UUID)); - } - - @Test - public void shouldReturnGlobalPropertyObjectWithTheCorrectValueWhenPropertyMatched() { - GlobalProperty property = dao.getGlobalPropertyObject(PERSON_ATTRIBUTE_TYPE_PROPERTY); - assertThat(property, notNullValue()); - assertThat(property.getPropertyValue(), notNullValue()); - assertThat(property.getPropertyValue(), equalTo(PERSON_ATTRIBUE_TYPE_PROPERTY_VALUE)); - } - - @Test - public void shouldReturnNullGlobalPropertyObjectWhenPropertyNotMatched() { - GlobalProperty property = dao.getGlobalPropertyObject(PERSON_ATTRIBUTE_TYPE_PROPERTY_NOT_FOUND); - assertThat(property, nullValue()); - } - - @Test - public void shouldReturnListOfGlobalPropertyValues() { - Map values = dao.getGlobalProperties(FhirConstants.GLOBAL_PROPERTY_MODERATE, - FhirConstants.GLOBAL_PROPERTY_SEVERE); - assertThat(values, notNullValue()); - assertThat(values.size(), greaterThanOrEqualTo(1)); - assertThat(values.get(FhirConstants.GLOBAL_PROPERTY_MODERATE), equalTo(GLOBAL_PROPERTY_MODERATE)); - } -} diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java index 38de5a701f..7f7edd451b 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java @@ -31,8 +31,8 @@ public class FhirClientServiceImplTest { @Before public void setup() { - FhirContext fhirR3 = FhirContext.forDstu3(); - FhirContext fhirR4 = FhirContext.forR4(); + FhirContext fhirR3 = FhirContext.forDstu3Cached(); + FhirContext fhirR4 = FhirContext.forR4Cached(); fhirClientService = new FhirClientServiceImpl(fhirR3, fhirR4); } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImplTest.java deleted file mode 100644 index 8e9fbf3b8e..0000000000 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImplTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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.fhir2.api.impl; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.Map; - -import org.hamcrest.CoreMatchers; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; -import org.openmrs.module.fhir2.api.dao.FhirGlobalPropertyDao; - -@RunWith(MockitoJUnitRunner.class) -public class FhirGlobalPropertyServiceImplTest { - - private static final String PERSON_ATTRIBUTE_TYPE_VALUE = "fhir2.personAttributeTypeUuid"; - - private static final String PERSON_ATTRIBUTE_TYPE_UUID = "12323h324-32423n30-32n23-23j23"; - - private static final String GLOBAL_PROPERTY_MODERATE = "1499AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - - private static final String DEFAULT_PAGE_SIZE = "default.page.size"; - - private static final String DEFAULT_PAGE_SIZE_STRING_VALUE = "10"; - - private static final Integer DEFAULT_PAGE_SIZE_INTEGER_VALUE = 10; - - @Mock - private FhirGlobalPropertyDao fhirGlobalPropertyDao; - - private FhirGlobalPropertyServiceImpl globalPropertyService; - - @Before - public void setUp() { - globalPropertyService = new FhirGlobalPropertyServiceImpl(); - globalPropertyService.setDao(fhirGlobalPropertyDao); - } - - @Test - public void shouldReturnStringGlobalPropertyWhenPropertyMatched() { - when(fhirGlobalPropertyDao.getGlobalProperty(PERSON_ATTRIBUTE_TYPE_VALUE)).thenReturn(PERSON_ATTRIBUTE_TYPE_UUID); - - String personAttributeTypeUuid = globalPropertyService.getGlobalProperty(PERSON_ATTRIBUTE_TYPE_VALUE); - - assertThat(personAttributeTypeUuid, notNullValue()); - assertThat(personAttributeTypeUuid, equalTo(PERSON_ATTRIBUTE_TYPE_UUID)); - } - - @Test - public void shouldReturnNullWhenGlobalPropertyNotFound() { - String personAttributeTypeUuid = globalPropertyService.getGlobalProperty(PERSON_ATTRIBUTE_TYPE_VALUE); - - assertThat(personAttributeTypeUuid, nullValue()); - } - - @Test - public void shouldReturnListOfGlobalPropertyValues() { - Map uuids = new HashMap<>(); - uuids.put(FhirConstants.GLOBAL_PROPERTY_MODERATE, GLOBAL_PROPERTY_MODERATE); - - when(fhirGlobalPropertyDao.getGlobalProperties(FhirConstants.GLOBAL_PROPERTY_MODERATE, - FhirConstants.GLOBAL_PROPERTY_SEVERE)).thenReturn(uuids); - - Map values = globalPropertyService.getGlobalProperties(FhirConstants.GLOBAL_PROPERTY_MODERATE, - FhirConstants.GLOBAL_PROPERTY_SEVERE); - - assertThat(values, CoreMatchers.notNullValue()); - assertThat(values.size(), greaterThanOrEqualTo(1)); - assertThat(values.get(FhirConstants.GLOBAL_PROPERTY_MODERATE), CoreMatchers.equalTo(GLOBAL_PROPERTY_MODERATE)); - } - - @Test - public void shouldReturnIntegerGlobalPropertyValueWhenPropertyMatched() { - FhirGlobalPropertyService globalPropertyService = mock(FhirGlobalPropertyService.class); - when(globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_INTEGER_VALUE)).thenReturn(100); - - int result = globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_INTEGER_VALUE); - assertThat(result, notNullValue()); - assertThat(result, is(100)); - } - - @Test - public void shouldReturnDefaultIntegerGlobalPropertyValueWhenPropertyNotMatched() { - int result = globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_INTEGER_VALUE); - assertThat(result, notNullValue()); - assertThat(result, is(DEFAULT_PAGE_SIZE_INTEGER_VALUE)); - } - - @Test - public void shouldReturnStringGlobalPropertyValueWhenPropertyMatched() { - FhirGlobalPropertyService globalPropertyService = mock(FhirGlobalPropertyService.class); - when(globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_STRING_VALUE)).thenReturn("100"); - - String result = globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_STRING_VALUE); - assertThat(result, notNullValue()); - assertThat(result, is("100")); - } - - @Test - public void shouldReturnDefaultStringGlobalPropertyValueWhenPropertyNotMatched() { - String result = globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_STRING_VALUE); - assertThat(result, notNullValue()); - assertThat(result, is(DEFAULT_PAGE_SIZE_STRING_VALUE)); - } - - @Test - public void shouldThrowNumberFormatException() { - when(globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_STRING_VALUE)) - .thenReturn("Invalid"); - Integer result = globalPropertyService.getGlobalProperty(DEFAULT_PAGE_SIZE, 0); - assertThat(result, notNullValue()); - assertThat(result, is(0)); - } -} diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirObservationServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirObservationServiceImplTest.java index 7772cc896a..991101d908 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirObservationServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirObservationServiceImplTest.java @@ -131,7 +131,7 @@ public void searchForObservations_shouldReturnObservationsByParameters() { SearchParameterMap theParams = new SearchParameterMap(); theParams.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obs)); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( @@ -182,7 +182,7 @@ public void getLastnObservations_shouldReturnRecentNObservations() { .addParameter(FhirConstants.MAX_SEARCH_HANDLER, max) .addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam()); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obs)); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( @@ -235,7 +235,7 @@ public void getLastn_shouldReturnFirstRecentObservationsWhenMaxIsMissing() { .addParameter(FhirConstants.MAX_SEARCH_HANDLER, max) .addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam()); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obs)); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( @@ -280,7 +280,7 @@ public void getLastnObservations_shouldReturnRecentNObservationsForAllPatientsWh .addParameter(FhirConstants.MAX_SEARCH_HANDLER, max) .addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam()); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obs)); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( @@ -332,7 +332,7 @@ public void getLastnEncountersObservations_shouldReturnRecentNEncountersObservat .addParameter(FhirConstants.MAX_SEARCH_HANDLER, max) .addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam()); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obs)); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( @@ -385,7 +385,7 @@ public void getLastnEncountersObservations_shouldReturnFirstRecentEncountersObse .addParameter(FhirConstants.MAX_SEARCH_HANDLER, max) .addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam()); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obs)); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( @@ -430,7 +430,7 @@ public void getLastnEncountersObservations_shouldReturnRecentNEncountersObservat .addParameter(FhirConstants.MAX_SEARCH_HANDLER, max) .addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam()); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(obs)); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java index d07e0bfa15..503d8469c1 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirPatientServiceImplTest.java @@ -275,7 +275,7 @@ public void searchForPatients_shouldSearchForPatientsByFamilyName() { SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam); - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); when(dao.getSearchResults(any())).thenReturn(patients); when(dao.getSearchResultsCount(any())).thenReturn(1); when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn( diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProviderTest.java index 4cad4bbf6f..3cef742263 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProviderTest.java @@ -63,7 +63,7 @@ public void setup() { @Test public void shouldReturnPreferredPageSize() { - when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10); + when(globalPropertyService.getGlobalPropertyAsInteger(anyString(), anyInt())).thenReturn(10); assertThat(searchQueryBundleProvider.preferredPageSize(), notNullValue()); assertThat(searchQueryBundleProvider.preferredPageSize(), equalTo(10)); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImplTest.java index 078abb84c6..17e2433329 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImplTest.java @@ -15,6 +15,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import java.util.Collections; import java.util.Date; @@ -279,8 +280,7 @@ public void toFhirResource_shouldTranslateOmrsPatientToFhirPatientReference() { AllergyIntolerance allergyIntolerance = allergyIntoleranceTranslator.toFhirResource(omrsAllergy); assertThat(allergyIntolerance.getPatient(), notNullValue()); assertThat(allergyIntolerance.getPatient().getType(), is(FhirTestConstants.PATIENT)); - assertThat(allergyIntoleranceTranslator.getReferenceId(allergyIntolerance.getPatient()).orElse(null), - equalTo(PATIENT_UUID)); + assertThat(getReferenceId(allergyIntolerance.getPatient()).orElse(null), equalTo(PATIENT_UUID)); } @Test @@ -298,8 +298,7 @@ public void toFhirResource_shouldTranslateOmrsAllergyCreatorToFhirPractitionerRe assertThat(allergyIntolerance.getRecorder(), notNullValue()); assertThat(allergyIntolerance.getRecorder().getType(), is(FhirTestConstants.PRACTITIONER)); - assertThat(allergyIntoleranceTranslator.getReferenceId(allergyIntolerance.getRecorder()).orElse(null), - equalTo(CREATOR_UUID)); + assertThat(getReferenceId(allergyIntolerance.getRecorder()).orElse(null), equalTo(CREATOR_UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImplTest.java index 232b11c4b3..025622a32a 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Reference; @@ -51,7 +52,7 @@ public void toFhirResource_shouldConvertEncounterToReference() { assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.ENCOUNTER)); - assertThat(encounterReferenceTranslator.getReferenceId(result).orElse(null), equalTo(ENCOUNTER_UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(ENCOUNTER_UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterTranslatorImplTest.java index 4a7a039d64..d12572fc2c 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterTranslatorImplTest.java @@ -103,7 +103,7 @@ public class EncounterTranslatorImplTest { @Mock private EncounterClassMap encounterClassMap; - + @Mock private EncounterService encounterService; @@ -246,7 +246,8 @@ public void toOpenMrsType_shouldTranslateParticipantToEncounterProvider() { Patient patient = new Patient(); patient.setUuid(PATIENT_UUID); when(patientReferenceTranslator.toOpenmrsType(patientRef)).thenReturn(patient); - when(participantTranslator.toOpenmrsType(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(new EncounterProvider()); + when(participantTranslator.toOpenmrsType(ArgumentMatchers.any(), ArgumentMatchers.any())) + .thenReturn(new EncounterProvider()); org.openmrs.Encounter result = encounterTranslator.toOpenmrsType(fhirEncounter); assertThat(result.getEncounterProviders(), not(empty())); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImplTest.java index 813dbb2306..349a6af2ab 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EpisodeOfCareTranslatorImplTest.java @@ -39,7 +39,7 @@ @RunWith(MockitoJUnitRunner.class) public class EpisodeOfCareTranslatorImplTest { - + private static final String PATIENT_UUID = "8549f706-7e85-4c1d-9424-217d50a2988b"; private static final String PATIENT_URI = FhirConstants.PATIENT + "/" + PATIENT_UUID; @@ -162,6 +162,6 @@ public void shouldTranslateVoidedPatientProgramToFinishesStatus() { @Test public void shouldThrowsUnsupportedExceptionForTranslationToOpenmrsType() { EpisodeOfCare episodeOfCare = new EpisodeOfCare(); - assertThrows(UnsupportedOperationException.class, () -> episodeOfCareTranslator.toOpenmrsType(episodeOfCare)); + assertThrows(UnsupportedOperationException.class, () -> episodeOfCareTranslator.toOpenmrsType(episodeOfCare)); } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImplTest.java index fda8120cf9..d96b675829 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTranslatorImplTest.java @@ -19,6 +19,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import java.math.BigDecimal; import java.util.ArrayList; @@ -46,6 +47,7 @@ import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; import org.openmrs.module.fhir2.api.dao.FhirLocationDao; import org.openmrs.module.fhir2.api.translators.LocationAddressTranslator; +import org.openmrs.module.fhir2.api.translators.LocationReferenceTranslator; import org.openmrs.module.fhir2.api.translators.LocationTagTranslator; import org.openmrs.module.fhir2.api.translators.LocationTypeTranslator; import org.openmrs.module.fhir2.api.translators.TelecomTranslator; @@ -90,6 +92,8 @@ public class LocationTranslatorImplTest { @Mock private LocationAddressTranslator locationAddressTranslator; + private LocationReferenceTranslator locationReferenceTranslator = new LocationReferenceTranslatorImpl(); + @Mock private LocationTagTranslator locationTagTranslator; @@ -112,13 +116,17 @@ public class LocationTranslatorImplTest { @Before public void setup() { omrsLocation = new Location(); + + ((LocationReferenceTranslatorImpl) locationReferenceTranslator).setLocationDao(fhirLocationDao); + locationTranslator = new LocationTranslatorImpl(); locationTranslator.setLocationAddressTranslator(locationAddressTranslator); + locationTranslator.setLocationReferenceTranslator(locationReferenceTranslator); locationTranslator.setTelecomTranslator(telecomTranslator); locationTranslator.setFhirLocationDao(fhirLocationDao); - locationTranslator.setPropertyService(propertyService); locationTranslator.setLocationTagTranslator(locationTagTranslator); locationTranslator.setLocationTypeTranslator(locationTypeTranslator); + locationTranslator.setPropertyService(propertyService); } @Test @@ -341,11 +349,13 @@ public void toFhirResource_shouldTranslateOpenmrsParentLocationToFhirReference() parentLocation.setUuid(PARENT_LOCATION_UUID); parentLocation.setName(PARENT_LOCATION_NAME); omrsLocation.setParentLocation(parentLocation); + Reference locationReference = locationTranslator.toFhirResource(omrsLocation).getPartOf(); + assertThat(locationReference, notNullValue()); assertThat(locationReference.getType(), is(FhirConstants.LOCATION)); assertThat(locationReference.getDisplay(), is(PARENT_LOCATION_NAME)); - assertThat(locationTranslator.getReferenceId(locationReference).orElse(null), equalTo(PARENT_LOCATION_UUID)); + assertThat(getReferenceId(locationReference).orElse(null), equalTo(PARENT_LOCATION_UUID)); } @Test @@ -388,14 +398,16 @@ public void getOpenmrsParentLocation_shouldReturnCorrectParentLocation() { Location parentLocation = new Location(); parentLocation.setUuid(PARENT_LOCATION_UUID); when(fhirLocationDao.get(PARENT_LOCATION_UUID)).thenReturn(parentLocation); + Location result = locationTranslator.getOpenmrsParentLocation(locationReference); + assertThat(result, notNullValue()); assertThat(result.getUuid(), is(PARENT_LOCATION_UUID)); } @Test public void getOpenmrsParentLocation_shouldReturnNullIfLocationHasNoIdentifier() { - Reference locationReference = new Reference().setReference(FhirConstants.LOCATION + "/" + PARENT_LOCATION_UUID) + Reference locationReference = new Reference().setReference(FhirConstants.LOCATION + "/") .setType(FhirConstants.LOCATION); Location result = locationTranslator.getOpenmrsParentLocation(locationReference); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImplTest.java index 6f929efacc..1abad082a5 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/LocationTypeTranslatorImplTest.java @@ -14,7 +14,6 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -153,13 +152,6 @@ public void toOpenmrsType_shouldTranslateFhirTypeCodeableConceptToExistingLocati typeAttribute.setValue(TYPE_CONCEPT_UUID); omrsLocation.addAttribute(typeAttribute); - when(locationDao.getLocationAttributeTypeByUuid(LOCATION_ATTRIBUTE_TYPE_UUID)).thenReturn(typeAttributeType); - when(globalPropertyService.getGlobalProperty(FhirConstants.LOCATION_TYPE_ATTRIBUTE_TYPE)) - .thenReturn(LOCATION_ATTRIBUTE_TYPE_UUID); - when(conceptTranslator.toOpenmrsType(eq(fhirTypeConcept))).thenReturn(typeConcept); - when(locationDao.getActiveAttributesByLocationAndAttributeTypeUuid(any(), any())) - .thenReturn(Collections.singletonList(typeAttribute)); - Location result = locationTypeTranslator.toOpenmrsType(omrsLocation, Collections.singletonList(fhirTypeConcept)); assertThat(result, notNullValue()); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImplTest.java index 2c5c7cda7a..092334a816 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationReferenceTranslatorImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hl7.fhir.r4.model.Reference; import org.junit.Before; @@ -50,7 +51,7 @@ public void toFhirResource_shouldConvertDrugToReference() { assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.MEDICATION)); - assertThat(medicationReferenceTranslator.getReferenceId(result).orElse(null), equalTo(MEDICATION_UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(MEDICATION_UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImplTest.java index 93e11fe436..f2d241460a 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestReferenceTranslatorImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Reference; @@ -49,7 +50,7 @@ public void toFhirResource_shouldConvertDrugOrderToReference() { Reference result = translator.toFhirResource(drugOrder); assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.MEDICATION_REQUEST)); - assertThat(translator.getReferenceId(result).orElse(null), equalTo(DRUG_ORDER_UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(DRUG_ORDER_UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java index f998a32b72..e775a4a8aa 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java @@ -119,6 +119,8 @@ public class MedicationRequestTranslatorImplTest { private MedicationRequestTranslatorImpl medicationRequestTranslator; + private MedicationRequestReferenceTranslatorImpl medicationRequestReferenceTranslator; + private MedicationQuantityCodingTranslatorImpl quantityCodingTranslator; private MedicationRequest medicationRequest; @@ -140,11 +142,14 @@ public void setup() { dispenseRequestComponentTranslator = new MedicationRequestDispenseRequestComponentTranslatorImpl(); dispenseRequestComponentTranslator.setQuantityCodingTranslator(quantityCodingTranslator); + medicationRequestReferenceTranslator = new MedicationRequestReferenceTranslatorImpl(); + medicationRequestTranslator = new MedicationRequestTranslatorImpl(); medicationRequestTranslator.setStatusTranslator(medicationRequestStatusTranslator); medicationRequestTranslator.setPractitionerReferenceTranslator(providerPractitionerReferenceTranslator); medicationRequestTranslator.setMedicationRequestPriorityTranslator(medicationRequestPriorityTranslator); medicationRequestTranslator.setMedicationReferenceTranslator(medicationReferenceTranslator); + medicationRequestTranslator.setMedicationRequestReferenceTranslator(medicationRequestReferenceTranslator); medicationRequestTranslator.setEncounterReferenceTranslator(encounterReferenceTranslator); medicationRequestTranslator.setPatientReferenceTranslator(patientReferenceTranslator); medicationRequestTranslator.setConceptTranslator(conceptTranslator); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImplTest.java index 7bbbd04e0f..67612162b8 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationReferenceTranslatorImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Reference; @@ -51,7 +52,7 @@ public void toFhirResource_shouldConvertObsToReference() { assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.OBSERVATION)); - assertThat(observationReferenceTranslator.getReferenceId(result).orElse(null), equalTo(UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImplTest.java index 9c6fcc394e..20188fc71d 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientReferenceTranslatorImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Reference; @@ -51,7 +52,7 @@ public void toFhirResource_shouldConvertEncounterToReference() { assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.PATIENT)); - assertThat(patientReferenceTranslator.getReferenceId(result).orElse(null), equalTo(PATIENT_UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(PATIENT_UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImplTest.java index 3b30dd4f35..b97484e3af 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorProviderImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.Practitioner; @@ -54,7 +55,7 @@ public void shouldConvertProviderToFhirPractitionerReference() { Reference result = referenceTranslatorProvider.toFhirResource(provider); assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.PRACTITIONER)); - assertThat(referenceTranslatorProvider.getReferenceId(result).orElse(null), equalTo(PRACTITIONER_UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(PRACTITIONER_UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImplTest.java index 522e5e9844..563a449a8d 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PractitionerReferenceTranslatorUserImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.Practitioner; @@ -54,7 +55,7 @@ public void shouldConvertUserToFhirPractitionerReference() { Reference result = practitionerReferenceTranslatorUser.toFhirResource(user); assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.PRACTITIONER)); - assertThat(practitionerReferenceTranslatorUser.getReferenceId(result).orElse(null), equalTo(USER_UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(USER_UUID)); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/BaseReferenceHandlingTranslatorTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ReferenceHandlingTranslatorTest.java similarity index 84% rename from api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/BaseReferenceHandlingTranslatorTest.java rename to api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ReferenceHandlingTranslatorTest.java index abc942a765..88dd486614 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/BaseReferenceHandlingTranslatorTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ReferenceHandlingTranslatorTest.java @@ -34,7 +34,7 @@ import org.openmrs.module.fhir2.FhirConstants; @RunWith(MockitoJUnitRunner.class) -public class BaseReferenceHandlingTranslatorTest { +public class ReferenceHandlingTranslatorTest { private static final String GIVEN_NAME = "Ricky"; @@ -93,12 +93,8 @@ public class BaseReferenceHandlingTranslatorTest { private org.openmrs.Encounter encounter; - private BaseReferenceHandlingTranslator referenceHandlingTranslator; - @Before public void setUp() { - referenceHandlingTranslator = new BaseReferenceHandlingTranslator() {}; - patient = new Patient(); patient.setUuid(PATIENT_UUID); @@ -138,61 +134,61 @@ public void setUp() { @Test public void shouldExtractIdFromReference() { - assertThat(referenceHandlingTranslator.getReferenceId(new Reference().setReference(PATIENT_URI)).orElse(null), + assertThat(ReferenceHandlingTranslator.getReferenceId(new Reference().setReference(PATIENT_URI)).orElse(null), equalTo(PATIENT_UUID)); } @Test public void shouldReturnNullIdForNullReference() { - assertThat(referenceHandlingTranslator.getReferenceId(new Reference()).orElse(null), nullValue()); + assertThat(ReferenceHandlingTranslator.getReferenceId(new Reference()).orElse(null), nullValue()); } @Test public void shouldNotExtractIdWhenIdMissingFromReference() { - assertThat(referenceHandlingTranslator.getReferenceId(new Reference().setReference(FhirConstants.PATIENT + "/")) + assertThat(ReferenceHandlingTranslator.getReferenceId(new Reference().setReference(FhirConstants.PATIENT + "/")) .orElse(null), nullValue()); } @Test public void shouldReturnNullIdWhenNoSlashFound() { - assertThat(referenceHandlingTranslator.getReferenceId(new Reference().setReference(PATIENT_UUID)).orElse(null), + assertThat(ReferenceHandlingTranslator.getReferenceId(new Reference().setReference(PATIENT_UUID)).orElse(null), nullValue()); } @Test public void shouldExtractReferenceTypeFromReference() { - assertThat(referenceHandlingTranslator.getReferenceType(new Reference().setReference(PATIENT_URI)).orElse(null), + assertThat(ReferenceHandlingTranslator.getReferenceType(new Reference().setReference(PATIENT_URI)).orElse(null), equalTo(FhirConstants.PATIENT)); } @Test public void shouldReturnNullTypeForNullReference() { - assertThat(referenceHandlingTranslator.getReferenceType(new Reference()).orElse(null), nullValue()); + assertThat(ReferenceHandlingTranslator.getReferenceType(new Reference()).orElse(null), nullValue()); } @Test public void shouldReturnNullTypeWhenTypeMissing() { assertThat( - referenceHandlingTranslator.getReferenceType(new Reference().setReference("/" + PATIENT_UUID)).orElse(null), + ReferenceHandlingTranslator.getReferenceType(new Reference().setReference("/" + PATIENT_UUID)).orElse(null), nullValue()); } @Test public void shouldReturnNullTypeWhenNoSlashFound() { - assertThat(referenceHandlingTranslator.getReferenceType(new Reference().setReference(PATIENT_UUID)).orElse(null), + assertThat(ReferenceHandlingTranslator.getReferenceType(new Reference().setReference(PATIENT_UUID)).orElse(null), nullValue()); } @Test public void shouldUseExplicitType() { - assertThat(referenceHandlingTranslator.getReferenceType(new Reference().setType(FhirConstants.PATIENT)).orElse(null), + assertThat(ReferenceHandlingTranslator.getReferenceType(new Reference().setType(FhirConstants.PATIENT)).orElse(null), equalTo(FhirConstants.PATIENT)); } @Test public void shouldReturnPatientReference() { - Reference reference = referenceHandlingTranslator.createPatientReference(patient); + Reference reference = ReferenceHandlingTranslator.createPatientReference(patient); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(PATIENT_URI)); @@ -201,7 +197,7 @@ public void shouldReturnPatientReference() { @Test public void shouldReturnPatientReferenceWithCorrectDisplayName() { - Reference reference = referenceHandlingTranslator.createPatientReference(patient); + Reference reference = ReferenceHandlingTranslator.createPatientReference(patient); assertThat(reference, notNullValue()); assertThat(reference.getDisplay(), equalTo(NAME_DISPLAY)); @@ -209,7 +205,7 @@ public void shouldReturnPatientReferenceWithCorrectDisplayName() { @Test public void shouldAddPractitionerReference() { - Reference reference = referenceHandlingTranslator.createPractitionerReference(provider); + Reference reference = ReferenceHandlingTranslator.createPractitionerReference(provider); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(PROVIDER_URI)); @@ -226,7 +222,7 @@ public void shouldReturnReferenceWithDisplayForProviderWithPerson() { person.addName(name); provider.setPerson(person); - Reference reference = referenceHandlingTranslator.createPractitionerReference(provider); + Reference reference = ReferenceHandlingTranslator.createPractitionerReference(provider); assertThat(reference, notNullValue()); assertThat(reference.getDisplay(), equalTo(PROVIDER_DISPLAY)); @@ -234,7 +230,7 @@ public void shouldReturnReferenceWithDisplayForProviderWithPerson() { @Test public void shouldReturnNullDisplayForPractitionerWithNullPerson() { - Reference reference = referenceHandlingTranslator.createPractitionerReference(provider); + Reference reference = ReferenceHandlingTranslator.createPractitionerReference(provider); assertThat(reference, notNullValue()); assertThat(reference.getDisplay(), nullValue()); @@ -242,7 +238,7 @@ public void shouldReturnNullDisplayForPractitionerWithNullPerson() { @Test public void shouldAddLocationReference() { - Reference reference = referenceHandlingTranslator.createLocationReference(location); + Reference reference = ReferenceHandlingTranslator.createLocationReference(location); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(LOCATION_URI)); @@ -254,7 +250,7 @@ public void shouldAddLocationReference() { public void shouldReturnNullDisplayWhenLocationNameIsNull() { location.setName(null); - Reference reference = referenceHandlingTranslator.createLocationReference(location); + Reference reference = ReferenceHandlingTranslator.createLocationReference(location); assertThat(reference, notNullValue()); assertThat(reference.getDisplay(), nullValue()); @@ -262,7 +258,7 @@ public void shouldReturnNullDisplayWhenLocationNameIsNull() { @Test public void shouldAddEncounterReference() { - Reference reference = referenceHandlingTranslator.createEncounterReference(encounter); + Reference reference = ReferenceHandlingTranslator.createEncounterReference(encounter); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(ENCOUNTER_URI)); @@ -271,7 +267,7 @@ public void shouldAddEncounterReference() { @Test public void shouldAddPractitionerGivenOpenMrsUserReference() { - Reference reference = referenceHandlingTranslator.createPractitionerReference(user); + Reference reference = ReferenceHandlingTranslator.createPractitionerReference(user); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(PRACTITIONER_REFERENCE)); @@ -284,7 +280,7 @@ public void shouldReturnReferenceWithNullDisplayIfUserPersonNameIsNull() { User user = new User(); user.setUuid(USER_UUID); - Reference reference = referenceHandlingTranslator.createPractitionerReference(user); + Reference reference = ReferenceHandlingTranslator.createPractitionerReference(user); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(PRACTITIONER_REFERENCE)); @@ -296,7 +292,7 @@ public void shouldAddOrderReferenceForTestOrder() { TestOrder order = new TestOrder(); order.setUuid(ORDER_UUID); - Reference reference = referenceHandlingTranslator.createOrderReference(order); + Reference reference = ReferenceHandlingTranslator.createOrderReference(order); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(TEST_ORDER_REFERENCE)); @@ -308,7 +304,7 @@ public void shouldAddOrderReferenceForTestOrderSubclass() { TestOrder order = new TestOrder() {}; order.setUuid(ORDER_UUID); - Reference reference = referenceHandlingTranslator.createOrderReference(order); + Reference reference = ReferenceHandlingTranslator.createOrderReference(order); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(TEST_ORDER_REFERENCE)); @@ -320,7 +316,7 @@ public void shouldAddOrderReferenceForDrugOrder() { DrugOrder order = new DrugOrder(); order.setUuid(ORDER_UUID); - Reference reference = referenceHandlingTranslator.createOrderReference(order); + Reference reference = ReferenceHandlingTranslator.createOrderReference(order); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(DRUG_ORDER_REFERENCE)); @@ -332,7 +328,7 @@ public void shouldAddOrderReferenceForDrugOrderSubclass() { DrugOrder order = new DrugOrder() {}; order.setUuid(ORDER_UUID); - Reference reference = referenceHandlingTranslator.createOrderReference(order); + Reference reference = ReferenceHandlingTranslator.createOrderReference(order); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(DRUG_ORDER_REFERENCE)); @@ -344,7 +340,7 @@ public void shouldReturnNullForRawOrder() { Order order = new Order(); order.setUuid(ORDER_UUID); - Reference reference = referenceHandlingTranslator.createOrderReference(order); + Reference reference = ReferenceHandlingTranslator.createOrderReference(order); assertThat(reference, nullValue()); } @@ -354,7 +350,7 @@ public void shouldReturnNullForUnknownOrderSubclass() { Order order = new Order() {}; order.setUuid(ORDER_UUID); - Reference reference = referenceHandlingTranslator.createOrderReference(order); + Reference reference = ReferenceHandlingTranslator.createOrderReference(order); assertThat(reference, nullValue()); } @@ -364,7 +360,7 @@ public void shouldReturnReferenceForDrugOrder() { DrugOrder order = new DrugOrder(); order.setUuid(ORDER_UUID); - Reference reference = referenceHandlingTranslator.createDrugOrderReference(order); + Reference reference = ReferenceHandlingTranslator.createDrugOrderReference(order); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(DRUG_ORDER_REFERENCE)); @@ -373,13 +369,13 @@ public void shouldReturnReferenceForDrugOrder() { @Test public void shouldReturnNullForNullDrugOrder() { - Reference reference = referenceHandlingTranslator.createDrugOrderReference(null); + Reference reference = ReferenceHandlingTranslator.createDrugOrderReference(null); assertThat(reference, nullValue()); } @Test public void shouldReturnLocationReferenceForUuid() { - Reference reference = referenceHandlingTranslator.createLocationReferenceByUuid(LOCATION_UUID); + Reference reference = ReferenceHandlingTranslator.createLocationReferenceByUuid(LOCATION_UUID); assertThat(reference, notNullValue()); assertThat(reference.getReference(), equalTo(LOCATION_URI)); assertThat(reference.getType(), equalTo(FhirConstants.LOCATION)); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java index feaa333e12..a4252bf78c 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java @@ -29,11 +29,11 @@ import org.openmrs.Concept; import org.openmrs.ConceptDescription; import org.openmrs.ConceptMap; +import org.openmrs.ConceptMapType; import org.openmrs.ConceptName; import org.openmrs.ConceptReferenceTerm; import org.openmrs.ConceptSet; import org.openmrs.ConceptSource; -import org.openmrs.ConceptMapType; import org.openmrs.module.fhir2.FhirTestConstants; import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.FhirConceptSourceService; @@ -76,7 +76,7 @@ public void shouldTranslateConceptSetToValueSet() { ConceptMap conceptMap = mock(ConceptMap.class); ConceptReferenceTerm conceptReferenceTerm = mock(ConceptReferenceTerm.class); ConceptSource conceptSource = mock(ConceptSource.class); - ConceptMapType conceptMapType=mock(ConceptMapType.class); + ConceptMapType conceptMapType = mock(ConceptMapType.class); when(conceptMap.getConceptReferenceTerm()).thenReturn(conceptReferenceTerm); when(conceptMap.getConceptMapType()).thenReturn(conceptMapType); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImplTest.java index 94c4a613da..3880320c5e 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/VisitReferenceTranslatorImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.when; +import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Reference; @@ -51,7 +52,7 @@ public void toFhirResource_shouldConvertVisitToReference() { assertThat(result, notNullValue()); assertThat(result.getType(), equalTo(FhirConstants.ENCOUNTER)); - assertThat(visitReferenceTranslator.getReferenceId(result).orElse(null), equalTo(VISIT_UUID)); + assertThat(getReferenceId(result).orElse(null), equalTo(VISIT_UUID)); } @Test diff --git a/docker/docker-compose-refqa.yml b/docker/docker-compose-refqa.yml index ee7b82e541..7b56355112 100644 --- a/docker/docker-compose-refqa.yml +++ b/docker/docker-compose-refqa.yml @@ -2,7 +2,7 @@ version: '2.1' services: openmrs-referenceapplication-mysql: - image: mysql:5.6 + image: mysql:8 command: "mysqld --character-set-server=utf8 --collation-server=utf8_general_ci" environment: - MYSQL_DATABASE=openmrs diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3IntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3IntegrationTest.java index 1de31ae2a3..0ee427f48a 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3IntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3IntegrationTest.java @@ -34,7 +34,7 @@ public abstract class BaseFhirR3IntegrationTest extends BaseFhirIntegrationTest { - private static final FhirContext FHIR_CONTEXT = FhirContext.forDstu3(); + private static final FhirContext FHIR_CONTEXT = FhirContext.forDstu3Cached(); @Override public String getServletName() { diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java index ddc10b467e..2a71d137cd 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java @@ -150,6 +150,8 @@ public void shouldCreateNewAllergyAsJson() throws Exception { assertThat(allergy.getPatient().getReferenceElement().getIdPart(), equalTo("da7f524f-27ce-4bb2-86d6-6d1d05312bd5")); assertThat(allergy.getRecorder().getReferenceElement().getIdPart(), equalTo("c98a1558-e131-11de-babe-001e378eb67e")); assertThat(allergy.getCategory().get(0).getCode(), equalTo("medication")); + assertThat(allergy.hasReaction(), is(true)); + assertThat(allergy.getReactionFirstRep().hasSeverity(), is(true)); assertThat(allergy.getReactionFirstRep().getSeverity().toCode(), equalTo("severe")); assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getCodingFirstRep().getCode(), equalTo("5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); @@ -200,6 +202,8 @@ public void shouldCreateNewAllergyAsXML() throws Exception { assertThat(allergy.getPatient().getReferenceElement().getIdPart(), equalTo("da7f524f-27ce-4bb2-86d6-6d1d05312bd5")); assertThat(allergy.getRecorder().getReferenceElement().getIdPart(), equalTo("c98a1558-e131-11de-babe-001e378eb67e")); assertThat(allergy.getCategory().get(0).getCode(), equalTo("medication")); + assertThat(allergy.hasReaction(), equalTo(true)); + assertThat(allergy.getReactionFirstRep().hasSeverity(), equalTo(true)); assertThat(allergy.getReactionFirstRep().getSeverity().toCode(), equalTo("severe")); assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getCodingFirstRep().getCode(), equalTo("5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/BaseFhirR4IntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/BaseFhirR4IntegrationTest.java index ce7dccad66..e0d406d41e 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/BaseFhirR4IntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/BaseFhirR4IntegrationTest.java @@ -35,7 +35,7 @@ public abstract class BaseFhirR4IntegrationTest extends BaseFhirIntegrationTest { - private static final FhirContext FHIR_CONTEXT = FhirContext.forR4(); + private static final FhirContext FHIR_CONTEXT = FhirContext.forR4Cached(); @Override public String getServletName() { diff --git a/omod/src/main/java/org/openmrs/module/fhir2/web/servlet/FhirRestServlet.java b/omod/src/main/java/org/openmrs/module/fhir2/web/servlet/FhirRestServlet.java index 6c4b3ea0ca..40a04282e5 100644 --- a/omod/src/main/java/org/openmrs/module/fhir2/web/servlet/FhirRestServlet.java +++ b/omod/src/main/java/org/openmrs/module/fhir2/web/servlet/FhirRestServlet.java @@ -30,7 +30,6 @@ import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor; import lombok.AccessLevel; import lombok.Setter; -import org.apache.commons.lang3.math.NumberUtils; import org.openmrs.GlobalProperty; import org.openmrs.api.AdministrationService; import org.openmrs.api.GlobalPropertyListener; @@ -152,7 +151,7 @@ protected void initialize() { registerInterceptor(new SupportMergePatchInterceptor()); String narrativesOverridePropertyFile = NarrativeUtils.getValidatedPropertiesFilePath( - globalPropertyService.getGlobalProperty(FhirConstants.NARRATIVES_OVERRIDE_PROPERTY_FILE, (String) null)); + globalPropertyService.getGlobalProperty(FhirConstants.NARRATIVES_OVERRIDE_PROPERTY_FILE, null)); List narrativePropertiesFiles; if (narrativesOverridePropertyFile != null) { @@ -206,10 +205,10 @@ public void setServerAddressStrategy(IServerAddressStrategy theServerAddressStra } private BasePagingProvider createPagingProvider() { - int defaultPageSize = NumberUtils - .toInt(globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE), 10); - int maximumPageSize = NumberUtils - .toInt(globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_MAXIMUM_PAGE_SIZE), 100); + int defaultPageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, + 10); + int maximumPageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_MAXIMUM_PAGE_SIZE, + 100); BasePagingProvider pagingProvider = new FifoMemoryPagingProvider(100); pagingProvider.setDefaultPageSize(defaultPageSize); @@ -226,6 +225,13 @@ protected void autoInject() { } } + @Override + public void willRefresh() { + if (fhirRestServletListener != null) { + administrationService.removeGlobalPropertyListener(fhirRestServletListener); + } + } + @Override public void refreshed() { if (started) { @@ -258,6 +264,13 @@ public void refreshed() { } } + @Override + public void stopped() { + if (fhirRestServletListener != null) { + administrationService.removeGlobalPropertyListener(fhirRestServletListener); + } + } + @Override public void destroy() { try { diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirResourceProviderWebTest.java index ca043ccadc..8dfae2129d 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirResourceProviderWebTest.java @@ -52,7 +52,6 @@ import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletConfig; import org.springframework.mock.web.MockServletContext; -import org.springframework.transaction.annotation.Transactional; public abstract class BaseFhirResourceProviderWebTest { @@ -118,15 +117,19 @@ public void setupFhirServlet() throws ServletException { servlet.setGlobalPropertyService(new FhirGlobalPropertyServiceImpl() { @Override - @Transactional(readOnly = true) - public String getGlobalProperty(String property) throws APIException { + public String getGlobalProperty(String property, String defaultValue) { + return defaultValue; + } + + @Override + public int getGlobalPropertyAsInteger(String property, int defaultValue) throws APIException { switch (property) { case FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE: - return "10"; + return 10; case FhirConstants.OPENMRS_FHIR_MAXIMUM_PAGE_SIZE: - return "100"; + return 100; } - return null; + return -1; } }); diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3ResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3ResourceProviderWebTest.java index 2ee6b3ca4e..2def6a30a1 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3ResourceProviderWebTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/BaseFhirR3ResourceProviderWebTest.java @@ -26,7 +26,7 @@ public abstract class BaseFhirR3ResourceProviderWebTest extends BaseFhirResourceProviderWebTest { - private static final FhirContext FHIR_CONTEXT = FhirContext.forDstu3(); + private static final FhirContext FHIR_CONTEXT = FhirContext.forDstu3Cached(); @Override public String getServletName() { diff --git a/pom.xml b/pom.xml index 695940c80e..0969882b1b 100644 --- a/pom.xml +++ b/pom.xml @@ -424,7 +424,7 @@ com.github.ben-manes.caffeine caffeine - 2.8.2 + 2.9.3 @@ -610,6 +610,15 @@ org.apache.maven.plugins maven-compiler-plugin 3.10.1 + + + + org.projectlombok + lombok + ${lombokVersion} + + + org.apache.maven.plugins @@ -892,7 +901,7 @@ 1.8 UTF-8 UTF-8 - 1.18.26 + 1.18.34 2.4.1 2.4.1 5.7.9 diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImplTest_initial_data.xml deleted file mode 100644 index d5eb88d6e8..0000000000 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImplTest_initial_data.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - -