diff --git a/api/pom.xml b/api/pom.xml index 6c2993840..ad9b20b6f 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -78,6 +78,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 000000000..4ff7e023c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirFlagService.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; + +import javax.annotation.Nonnull; + +import org.hl7.fhir.r4.model.Flag; + +public interface FhirFlagService extends FhirService { + + @Override + Flag get(@Nonnull String uuid); +} 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 000000000..1067bb748 --- /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 000000000..a5e191501 --- /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 000000000..353de0f94 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirFlagServiceImpl.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.impl; + +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; + +} 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 000000000..77ebe4191 --- /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 000000000..cd66cff4e --- /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 000000000..4f842bf8f --- /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 e0c6f7a6a..9a469dc6c 100644 --- a/pom.xml +++ b/pom.xml @@ -509,6 +509,11 @@ 1.1.1 test + + org.openmrs.module + patientflags-api + ${patinetflagversion} + @@ -529,6 +534,10 @@ junit junit + + org.openmrs.module + patientflags-api + org.hamcrest hamcrest-core @@ -948,6 +957,7 @@ 2.4.1 5.7.9 1.0.3 + 3.0.8-SNAPSHOT