From 0bdaf17fd211740ed4a66ad56d882bfa153328a1 Mon Sep 17 00:00:00 2001 From: "Kipchumba C. Bett" Date: Wed, 4 Sep 2024 10:24:14 +0300 Subject: [PATCH] OZ-684: Implement FHIR Odoo HAPI plain server --- .../java/com/ozonehis/fhir/Application.java | 0 .../main/resources/application.properties | 0 .../com/ozonehis/fhir/ApplicationTest.java | 0 fhir-odoo-mapper/pom.xml | 2 +- .../com/ozonehis/fhir/FhirOdooConfig.java | 20 ++++++++++ .../ozonehis/fhir/FhirOdooRestfulServlet.java | 34 ++++++++++++++++ .../fhir/FhirOdooRestfulServletConfig.java | 30 ++++++++++++++ .../fhir/annotations/FhirOdooProvider.java | 22 +++++++++++ .../src/main/resources/fhir-odoo.properties | 10 +++++ .../FhirOdooRestfulServletConfigTest.java | 39 +++++++++++++++++++ pom.xml | 2 +- 11 files changed, 157 insertions(+), 2 deletions(-) rename development/{src => app}/main/java/com/ozonehis/fhir/Application.java (100%) rename development/{src => app}/main/resources/application.properties (100%) rename development/{src => app}/test/java/com/ozonehis/fhir/ApplicationTest.java (100%) create mode 100644 fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooConfig.java create mode 100644 fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServlet.java create mode 100644 fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServletConfig.java create mode 100644 fhir-odoo/src/main/java/com/ozonehis/fhir/annotations/FhirOdooProvider.java create mode 100644 fhir-odoo/src/main/resources/fhir-odoo.properties create mode 100644 fhir-odoo/src/test/java/com/ozonehis/fhir/FhirOdooRestfulServletConfigTest.java diff --git a/development/src/main/java/com/ozonehis/fhir/Application.java b/development/app/main/java/com/ozonehis/fhir/Application.java similarity index 100% rename from development/src/main/java/com/ozonehis/fhir/Application.java rename to development/app/main/java/com/ozonehis/fhir/Application.java diff --git a/development/src/main/resources/application.properties b/development/app/main/resources/application.properties similarity index 100% rename from development/src/main/resources/application.properties rename to development/app/main/resources/application.properties diff --git a/development/src/test/java/com/ozonehis/fhir/ApplicationTest.java b/development/app/test/java/com/ozonehis/fhir/ApplicationTest.java similarity index 100% rename from development/src/test/java/com/ozonehis/fhir/ApplicationTest.java rename to development/app/test/java/com/ozonehis/fhir/ApplicationTest.java diff --git a/fhir-odoo-mapper/pom.xml b/fhir-odoo-mapper/pom.xml index ce90505..9112f0e 100644 --- a/fhir-odoo-mapper/pom.xml +++ b/fhir-odoo-mapper/pom.xml @@ -29,7 +29,7 @@ - com.ozonehis.fhir + org.openmrs.fhir fhir-structures-backport-r4 ${fhir.structures.backport-r4.version} diff --git a/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooConfig.java b/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooConfig.java new file mode 100644 index 0000000..9fd5566 --- /dev/null +++ b/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooConfig.java @@ -0,0 +1,20 @@ +/* + * Copyright © 2024, Ozone HIS + * + * 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/. + */ +package com.ozonehis.fhir; + +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +public class FhirOdooConfig { + + @Value("${fhir.odoo.server-url}") + private String OdooServerUrl; +} diff --git a/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServlet.java b/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServlet.java new file mode 100644 index 0000000..d3a5fb6 --- /dev/null +++ b/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServlet.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2024, Ozone HIS + * + * 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/. + */ +package com.ozonehis.fhir; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.RestfulServer; +import com.ozonehis.fhir.annotations.FhirOdooProvider; +import java.util.Collection; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class FhirOdooRestfulServlet extends RestfulServer { + + @Override + protected void initialize() { + setFhirContext(FhirContext.forR4()); + setDefaultResponseEncoding(EncodingEnum.JSON); + } + + @Override + @Autowired + @FhirOdooProvider + public void setResourceProviders(Collection theProviders) { + super.setResourceProviders(theProviders); + } +} diff --git a/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServletConfig.java b/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServletConfig.java new file mode 100644 index 0000000..0cce758 --- /dev/null +++ b/fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooRestfulServletConfig.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2024, Ozone HIS + * + * 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/. + */ +package com.ozonehis.fhir; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class FhirOdooRestfulServletConfig { + + private final String FHIR_ODOO_SERVLET_NAME = "FhirOdooRestfulServlet"; + + @Autowired + private FhirOdooRestfulServlet fhirOdooRestfulServlet; + + @Bean + public ServletRegistrationBean fhirOdooRestfulServletRegistrationBean() { + var servletRegistrationBean = new ServletRegistrationBean<>(fhirOdooRestfulServlet, "/odoo/R4/*"); + servletRegistrationBean.setName(FHIR_ODOO_SERVLET_NAME); + servletRegistrationBean.setLoadOnStartup(1); + return servletRegistrationBean; + } +} diff --git a/fhir-odoo/src/main/java/com/ozonehis/fhir/annotations/FhirOdooProvider.java b/fhir-odoo/src/main/java/com/ozonehis/fhir/annotations/FhirOdooProvider.java new file mode 100644 index 0000000..ecc1767 --- /dev/null +++ b/fhir-odoo/src/main/java/com/ozonehis/fhir/annotations/FhirOdooProvider.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2024, Ozone HIS + * + * 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/. + */ +package com.ozonehis.fhir.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +@Component +@Qualifier public @interface FhirOdooProvider {} diff --git a/fhir-odoo/src/main/resources/fhir-odoo.properties b/fhir-odoo/src/main/resources/fhir-odoo.properties new file mode 100644 index 0000000..cf27975 --- /dev/null +++ b/fhir-odoo/src/main/resources/fhir-odoo.properties @@ -0,0 +1,10 @@ +# +# Copyright © 2024, Ozone HIS +# +# 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/. +# + +# The URL of the Odoo server +fhir-odoo.server-url=http://localhost:8069 diff --git a/fhir-odoo/src/test/java/com/ozonehis/fhir/FhirOdooRestfulServletConfigTest.java b/fhir-odoo/src/test/java/com/ozonehis/fhir/FhirOdooRestfulServletConfigTest.java new file mode 100644 index 0000000..7aa17a0 --- /dev/null +++ b/fhir-odoo/src/test/java/com/ozonehis/fhir/FhirOdooRestfulServletConfigTest.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2024, Ozone HIS + * + * 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/. + */ +package com.ozonehis.fhir; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; + +@SpringBootTest(classes = FhirOdooRestfulServletConfig.class) +class FhirOdooRestfulServletConfigTest { + + @MockBean + FhirOdooRestfulServlet fhirOdooRestfulServlet; + + @Autowired + ServletRegistrationBean fhirOdooRestfulServletRegistrationBean; + + @Test + @DisplayName("Should register FhirOdooRestfulServlet with URL mapping /odoo/R4/*") + void shouldReturnFhirOdooRestfulServletRegistrationBeanWithCorrectMappings() { + // Assert + assertNotNull(fhirOdooRestfulServletRegistrationBean); + assertNotNull(fhirOdooRestfulServletRegistrationBean.getServlet()); + assertTrue(fhirOdooRestfulServletRegistrationBean.getUrlMappings().contains("/odoo/R4/*")); + assertEquals("FhirOdooRestfulServlet", fhirOdooRestfulServletRegistrationBean.getServletName()); + } +} diff --git a/pom.xml b/pom.xml index 52ce14f..fb8b7a6 100644 --- a/pom.xml +++ b/pom.xml @@ -33,13 +33,13 @@ fhir-odoo fhir-odoo-mapper + development 17 7.2.2 3.3.2 - 1.0.0-SNAPSHOT 1.18.30 2.43.0 2.49.0