Skip to content

Commit

Permalink
OZ-684: Implement FHIR Odoo HAPI plain server
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliouzbett committed Sep 6, 2024
1 parent 158d54a commit 0bdaf17
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fhir-odoo-mapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<dependencies>
<dependency>
<groupId>com.ozonehis.fhir</groupId>
<groupId>org.openmrs.fhir</groupId>
<artifactId>fhir-structures-backport-r4</artifactId>
<version>${fhir.structures.backport-r4.version}</version>
</dependency>
Expand Down
20 changes: 20 additions & 0 deletions fhir-odoo/src/main/java/com/ozonehis/fhir/FhirOdooConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright © 2024, Ozone HIS <[email protected]>
*
* 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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright © 2024, Ozone HIS <[email protected]>
*
* 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<IResourceProvider> theProviders) {
super.setResourceProviders(theProviders);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright © 2024, Ozone HIS <[email protected]>
*
* 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<FhirOdooRestfulServlet> fhirOdooRestfulServletRegistrationBean() {
var servletRegistrationBean = new ServletRegistrationBean<>(fhirOdooRestfulServlet, "/odoo/R4/*");
servletRegistrationBean.setName(FHIR_ODOO_SERVLET_NAME);
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright © 2024, Ozone HIS <[email protected]>
*
* 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 {}
10 changes: 10 additions & 0 deletions fhir-odoo/src/main/resources/fhir-odoo.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright © 2024, Ozone HIS <[email protected]>
#
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright © 2024, Ozone HIS <[email protected]>
*
* 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<FhirOdooRestfulServlet> 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());
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
<modules>
<module>fhir-odoo</module>
<module>fhir-odoo-mapper</module>
<module>development</module>
</modules>

<properties>
<java.version>17</java.version>
<hapi.fhir.version>7.2.2</hapi.fhir.version>
<spring-boot.version>3.3.2</spring-boot.version>
<fhir-structures-backport-r4.version>1.0.0-SNAPSHOT</fhir-structures-backport-r4.version>
<lombok.version>1.18.30</lombok.version>
<spotless.version>2.43.0</spotless.version>
<palantirJavaFormat.version>2.49.0</palantirJavaFormat.version>
Expand Down

0 comments on commit 0bdaf17

Please sign in to comment.