Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

TFS#513262 - Fixed moduleApplicationContext #24

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
package org.openmrs.module.fhir2extension;

public final class FhirConstants {

private FhirConstants() {
}

public static final String QUESTIONNAIRE = "Questionnaire";

public static final String FHIR_QUESTIONNAIRE_TYPE = "FHIR Questionnaire";

public static final String FORM_SYSTEM_URI = "http://fhir.openmrs.org/core/StructureDefinition/omrs-form";

private FhirConstants() {
}
public static final String QUESTIONNAIRE = "Questionnaire";
public static final String FHIR_QUESTIONNAIRE_TYPE = "FHIR Questionnaire";
public static final String FORM_SYSTEM_URI = "http://fhir.openmrs.org/core/StructureDefinition/omrs-form";
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,30 @@
import org.openmrs.module.fhir2.api.translators.PatientTranslator;
import org.openmrs.module.fhir2.api.translators.impl.PatientTranslatorImpl;


@Primary
@Component
public class PatientTranslatorExtensionImpl extends PatientTranslatorImpl implements PatientTranslator {

@Autowired
LocationService locationService;

@Override
public org.openmrs.Patient toOpenmrsType(@Nonnull Patient fhirPatient) {
notNull(fhirPatient, "The Patient object should not be null");

if (Context.getUserContext().getLocation() == null) {
String l = extractLocationUuidFromPatient(fhirPatient);

Integer locationId = getLocationIdFromUuid(l);
if (locationId != null) {
Context.getUserContext().setLocationId(locationId);
}
}

return toOpenmrsType(new org.openmrs.Patient(), fhirPatient);
}

private String extractLocationUuidFromPatient(Patient patient) {
@Autowired
LocationService locationService;
@Override
public org.openmrs.Patient toOpenmrsType(@Nonnull Patient fhirPatient) {
notNull(fhirPatient, "The Patient object should not be null");
if (Context.getUserContext().getLocation() == null) {
String l = extractLocationUuidFromPatient(fhirPatient);
Integer locationId = getLocationIdFromUuid(l);
if (locationId != null) {
Context.getUserContext().setLocationId(locationId);
}
}
return toOpenmrsType(new org.openmrs.Patient(), fhirPatient);
}
private String extractLocationUuidFromPatient(Patient patient) {
if (patient.hasIdentifier()) {
return patient.getIdentifier().stream().flatMap(identifier -> identifier.getExtension().stream())
.filter(
Expand All @@ -83,13 +82,13 @@ private String extractLocationUuidFromPatient(Patient patient) {
}
return null;
}

private Integer getLocationIdFromUuid(String uuid) {
org.openmrs.Location location = locationService.getLocationByUuid(uuid);

if (location != null) {
return location.getId();
}
return null;
}
private Integer getLocationIdFromUuid(String uuid) {
org.openmrs.Location location = locationService.getLocationByUuid(uuid);
if (location != null) {
return location.getId();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
package org.openmrs.module.fhir2extension.api.translators;/*
/*
* with Copyright 2024 ICRC
*
* BSD 3-Clause License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
* with Copyright 2024 ICRC
*
* BSD 3-Clause License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.hl7.fhir.r4.model.CodeableConcept;
import org.openmrs.module.fhir2.api.translators.OpenmrsFhirTranslator;

public interface FormTranslator<T> extends OpenmrsFhirTranslator<T, CodeableConcept> {

/**
* @param form the OpenMRS form to translate
* @return a list consisting of an encoded version of the OpenMRS form
*/
@Override
CodeableConcept toFhirResource(T form);

/**
* @param form a list consisting of an encoded version of the OpenMRS form
* @return the OpenMRS encounter type or visit type
*/
@Override
T toOpenmrsType(CodeableConcept form);
/**
* @param form the OpenMRS form to translate
* @return a list consisting of an encoded version of the OpenMRS form
*/
@Override
CodeableConcept toFhirResource(T form);
/**
* @param form a list consisting of an encoded version of the OpenMRS form
* @return the OpenMRS encounter type or visit type
*/
@Override
T toOpenmrsType(CodeableConcept form);
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package org.openmrs.module.fhir2extension.api.translators.impl;/*
/*
* with Copyright 2024 ICRC
*
* BSD 3-Clause License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
* with Copyright 2024 ICRC
*
* BSD 3-Clause License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
Expand All @@ -42,25 +42,25 @@

@Component
public class FormTranslatorImpl implements FormTranslator<Form> {

public static final String FORM_SYSTEM_URI = "http://fhir.openmrs.org/core/StructureDefinition/omrs-form";

@Autowired
private FormService formService;

@Override
public CodeableConcept toFhirResource(Form form) {
if (form == null) {
return null;
}

CodeableConcept code = new CodeableConcept();
code.addCoding().setSystem(FORM_SYSTEM_URI).setCode(form.getUuid()).setDisplay(getMetadataTranslation(form));

return code;
}

@Override
public static final String FORM_SYSTEM_URI = "http://fhir.openmrs.org/core/StructureDefinition/omrs-form";
@Autowired
private FormService formService;
@Override
public CodeableConcept toFhirResource(Form form) {
if (form == null) {
return null;
}
CodeableConcept code = new CodeableConcept();
code.addCoding().setSystem(FORM_SYSTEM_URI).setCode(form.getUuid()).setDisplay(getMetadataTranslation(form));
return code;
}
@Override
public Form toOpenmrsType(CodeableConcept form) {
if (form == null || !form.hasCoding()) {
return null;
Expand Down
67 changes: 31 additions & 36 deletions api/src/main/resources/moduleApplicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,38 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="org.openmrs.module.fhir2extension" />

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

<context:annotation-config />

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath:fhir.properties</value>
</list>
</property>
</bean>

<bean name="restfulClientFactoryR4" class="ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory">
<property name="fhirContext" ref="fhirR4"/>
</bean>
<bean name="fhirR4" class="ca.uhn.fhir.context.FhirContext" factory-method="forR4">
<property name="restfulClientFactory" ref="restfulClientFactoryR4"/>
</bean>
<!-- base ucum-essence file packaged with fhir-ucum-->
<bean id="baseUcumService" class="org.fhir.ucum.UcumEssenceService">
<constructor-arg name="stream" value="classpath:ucum-essence.xml" />
</bean>
<!-- fhir2 module defined ucum-essence file containing additional (custom) UCUM definitions-->
<bean id="fhirUcumService" class="org.fhir.ucum.UcumEssenceService">
<constructor-arg name="stream" value="classpath:ucum-fhir-essence.xml" />
</bean>

</beans>
<context:annotation-config />

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath:fhir.properties</value>
</list>
</property>
</bean>

<bean name="restfulClientFactoryR4" class="ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory">
<property name="fhirContext" ref="fhirR4"/>
</bean>

<bean name="fhirR4" class="ca.uhn.fhir.context.FhirContext" factory-method="forR4">
<property name="restfulClientFactory" ref="restfulClientFactoryR4"/>
</bean>

<!-- Base UCUM-essence file packaged with fhir-ucum -->
<bean id="baseUcumService" class="org.fhir.ucum.UcumEssenceService">
<constructor-arg name="stream" value="classpath:ucum-essence.xml" />
</bean>

<!-- FHIR2 module-defined UCUM-essence file containing additional (custom) UCUM definitions -->
<bean id="fhirUcumService" class="org.fhir.ucum.UcumEssenceService">
<constructor-arg name="stream" value="classpath:ucum-fhir-essence.xml" />
</bean>

</beans>