From 94b48e5702307be6a35862f10b495480d77d13f8 Mon Sep 17 00:00:00 2001 From: ManojLL Date: Thu, 4 Jul 2024 22:38:42 +0530 Subject: [PATCH 1/3] FM2-640: add flag resource --- api/pom.xml | 4 + .../module/fhir2/api/FhirFlagService.java | 16 ++++ .../module/fhir2/api/dao/FhirFlagDao.java | 20 +++++ .../fhir2/api/dao/impl/FhirFlagDaoImpl.java | 29 +++++++ .../fhir2/api/impl/FhirFlagServiceImpl.java | 41 ++++++++++ .../translators/PatientFlagTranslator.java | 36 +++++++++ .../impl/PatientFlagTranslatorImpl.java | 77 +++++++++++++++++++ .../r4/FlagFhirResourceProvider.java | 51 ++++++++++++ pom.xml | 10 +++ 9 files changed, 284 insertions(+) create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirFlagDao.java create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirFlagDaoImpl.java create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/translators/PatientFlagTranslator.java create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientFlagTranslatorImpl.java create mode 100644 api/src/main/java/org/openmrs/module/fhir2/providers/r4/FlagFhirResourceProvider.java diff --git a/api/pom.xml b/api/pom.xml index 2827f35bbf..0c771d1dd3 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -74,6 +74,10 @@ ${project.parent.version} test + + org.openmrs.module + patientflags-api + diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java new file mode 100644 index 0000000000..bb264c1f88 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java @@ -0,0 +1,16 @@ +/* + * 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; + +import org.hl7.fhir.r4.model.Flag; + +public interface FhirFlagService extends FhirService { + +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirFlagDao.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirFlagDao.java new file mode 100644 index 0000000000..1067bb7482 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirFlagDao.java @@ -0,0 +1,20 @@ +/* + * 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 org.openmrs.annotation.Authorized; +import org.openmrs.module.patientflags.PatientFlag; +import org.openmrs.util.PrivilegeConstants; + +public interface FhirFlagDao extends FhirDao { + + @Authorized(PrivilegeConstants.GET_PATIENTS) + PatientFlag getPatientFlagForPatientId(Integer id); +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirFlagDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirFlagDaoImpl.java new file mode 100644 index 0000000000..a5e191501d --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirFlagDaoImpl.java @@ -0,0 +1,29 @@ +/* + * 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.hibernate.criterion.Restrictions.eq; + +import lombok.AccessLevel; +import lombok.Setter; +import org.openmrs.module.fhir2.api.dao.FhirFlagDao; +import org.openmrs.module.patientflags.PatientFlag; +import org.springframework.stereotype.Component; + +@Component +@Setter(AccessLevel.PACKAGE) +public class FhirFlagDaoImpl extends BaseFhirDao implements FhirFlagDao { + + @Override + public PatientFlag getPatientFlagForPatientId(Integer id) { + return (PatientFlag) getSessionFactory().getCurrentSession().createCriteria(PatientFlag.class) + .add(eq("patient_flag_id", id)).uniqueResult(); + } +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java new file mode 100644 index 0000000000..195b3fc631 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java @@ -0,0 +1,41 @@ +/* + * 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 javax.annotation.Nonnull; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import org.hl7.fhir.r4.model.Flag; +import org.openmrs.module.fhir2.api.FhirFlagService; +import org.openmrs.module.fhir2.api.dao.FhirFlagDao; +import org.openmrs.module.fhir2.api.translators.PatientFlagTranslator; +import org.openmrs.module.patientflags.PatientFlag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component +@Transactional +@Setter(AccessLevel.PACKAGE) +@Getter(AccessLevel.PROTECTED) +public class FhirFlagServiceImpl extends BaseFhirService implements FhirFlagService { + + @Autowired + private FhirFlagDao dao; + + @Autowired + private PatientFlagTranslator translator; + + public Flag getFlag(@Nonnull Integer id) { + return translator.toFhirResource(dao.getPatientFlagForPatientId(id)); + } +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/PatientFlagTranslator.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/PatientFlagTranslator.java new file mode 100644 index 0000000000..77ebe41914 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/PatientFlagTranslator.java @@ -0,0 +1,36 @@ +/* + * 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.translators; + +import javax.annotation.Nonnull; + +import org.hl7.fhir.r4.model.Flag; +import org.openmrs.module.patientflags.PatientFlag; + +public interface PatientFlagTranslator extends OpenmrsFhirTranslator { + + /** + * Maps an OpenMRS data element to a FHIR resource + * + * @param patientFlag the OpenMRS data element to translate + * @return the corresponding FHIR resource + */ + @Override + Flag toFhirResource(@Nonnull PatientFlag patientFlag); + + /** + * Maps a FHIR resource to an OpenMRS data element + * + * @param flag the FHIR resource to translate + * @return the corresponding OpenMRS data element + */ + @Override + PatientFlag toOpenmrsType(@Nonnull Flag flag); +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientFlagTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientFlagTranslatorImpl.java new file mode 100644 index 0000000000..cd66cff4e7 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientFlagTranslatorImpl.java @@ -0,0 +1,77 @@ +/* + * 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.translators.impl; + +import static org.apache.commons.lang3.Validate.notNull; + +import javax.annotation.Nonnull; + +import java.util.Collections; + +import lombok.AccessLevel; +import lombok.Setter; +import org.hl7.fhir.r4.model.Flag; +import org.hl7.fhir.r4.model.Identifier; +import org.hl7.fhir.r4.model.Period; +import org.openmrs.module.fhir2.api.translators.PatientFlagTranslator; +import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator; +import org.openmrs.module.patientflags.PatientFlag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@Setter(AccessLevel.PACKAGE) +public class PatientFlagTranslatorImpl implements PatientFlagTranslator { + + @Autowired + private PatientReferenceTranslator patientReferenceTranslator; + + @Override + public Flag toFhirResource(@Nonnull PatientFlag patientFlag) { + notNull(patientFlag, "The Openmrs Patient flag object should not be null"); + + Flag flag = new Flag(); + + flag.setId(patientFlag.getUuid()); + + // flag.setText(); + + Identifier identifier = new Identifier(); + identifier.setValue(String.valueOf(patientFlag.getPatientFlagId())); + flag.setIdentifier(Collections.singletonList(identifier)); + + if (patientFlag.getVoided()) { + flag.setStatus(Flag.FlagStatus.INACTIVE); + } else { + flag.setStatus(Flag.FlagStatus.ACTIVE); + } + + // flag.setCategory(); + + // flag.setCode(); + + flag.setSubject(patientReferenceTranslator.toFhirResource(patientFlag.getPatient())); + + Period period = new Period(); + period.setStart(patientFlag.getDateCreated()); + flag.setPeriod(period); + + // Reference reference = new Reference(); + // reference.set + // flag.setAuthor(reference); + + return flag; + } + + @Override + public PatientFlag toOpenmrsType(@Nonnull Flag flag) { + return null; + } +} diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/FlagFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/FlagFhirResourceProvider.java new file mode 100644 index 0000000000..4f842bf8f4 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/FlagFhirResourceProvider.java @@ -0,0 +1,51 @@ +/* + * 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.providers.r4; + +import static lombok.AccessLevel.PACKAGE; + +import javax.annotation.Nonnull; + +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import lombok.Setter; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Flag; +import org.hl7.fhir.r4.model.IdType; +import org.openmrs.module.fhir2.api.FhirFlagService; +import org.openmrs.module.fhir2.api.annotations.R4Provider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component("FlagFhirR4ResourceProvider") +@R4Provider +@Setter(PACKAGE) +public class FlagFhirResourceProvider implements IResourceProvider { + + @Autowired + private FhirFlagService flagService; + + @Override + public Class getResourceType() { + return Flag.class; + } + + @Read + public Flag getPatientById(@IdParam @Nonnull IdType id) { + Flag flag = flagService.get(id.getIdPart()); + if (flag == null) { + throw new ResourceNotFoundException("Could not find Flag with Id " + id.getIdPart()); + } + return flag; + } + +} diff --git a/pom.xml b/pom.xml index 109371d33a..ce6446965a 100644 --- a/pom.xml +++ b/pom.xml @@ -481,6 +481,11 @@ 1.1.1 test + + org.openmrs.module + patientflags-api + ${patinetflagversion} + @@ -501,6 +506,10 @@ junit junit + + org.openmrs.module + patientflags-api + org.hamcrest hamcrest-core @@ -897,6 +906,7 @@ 2.4.1 5.7.9 1.0.3 + 3.0.8-SNAPSHOT From 9e537e742e173fecfcc4fbce68d095f7d0abae7a Mon Sep 17 00:00:00 2001 From: ManojLL Date: Fri, 5 Jul 2024 12:23:11 +0530 Subject: [PATCH 2/3] FM2-640: add flag resource --- .../java/org/openmrs/module/fhir2/api/FhirFlagService.java | 5 ++++- .../openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java index bb264c1f88..245b2b977d 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java @@ -11,6 +11,9 @@ import org.hl7.fhir.r4.model.Flag; +import javax.annotation.Nonnull; + public interface FhirFlagService extends FhirService { - + @Override + Flag get(@Nonnull String uuid); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java index 195b3fc631..1df665e3ea 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java @@ -34,8 +34,5 @@ public class FhirFlagServiceImpl extends BaseFhirService impl @Autowired private PatientFlagTranslator translator; - - public Flag getFlag(@Nonnull Integer id) { - return translator.toFhirResource(dao.getPatientFlagForPatientId(id)); - } + } From 9b31ba07ccfc0e1aa04667dd809826f3c7f5f696 Mon Sep 17 00:00:00 2001 From: ManojLL Date: Fri, 5 Jul 2024 12:31:41 +0530 Subject: [PATCH 3/3] FM2-640: add flag resource --- .../org/openmrs/module/fhir2/api/FhirFlagService.java | 9 +++++---- .../module/fhir2/api/impl/FhirFlagServiceImpl.java | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java index 245b2b977d..4ff7e023c3 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.java @@ -9,11 +9,12 @@ */ package org.openmrs.module.fhir2.api; -import org.hl7.fhir.r4.model.Flag; - import javax.annotation.Nonnull; +import org.hl7.fhir.r4.model.Flag; + public interface FhirFlagService extends FhirService { - @Override - Flag get(@Nonnull String uuid); + + @Override + Flag get(@Nonnull String uuid); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java index 1df665e3ea..353de0f94c 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.java @@ -9,8 +9,6 @@ */ package org.openmrs.module.fhir2.api.impl; -import javax.annotation.Nonnull; - import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -34,5 +32,5 @@ public class FhirFlagServiceImpl extends BaseFhirService impl @Autowired private PatientFlagTranslator translator; - + }