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

FM2-640: Add support for Flag resource #543

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>patientflags-api</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Flag> {

@Override
Flag get(@Nonnull String uuid);
}
Original file line number Diff line number Diff line change
@@ -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<PatientFlag> {

@Authorized(PrivilegeConstants.GET_PATIENTS)
PatientFlag getPatientFlagForPatientId(Integer id);
}
Original file line number Diff line number Diff line change
@@ -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<PatientFlag> implements FhirFlagDao {

@Override
public PatientFlag getPatientFlagForPatientId(Integer id) {
return (PatientFlag) getSessionFactory().getCurrentSession().createCriteria(PatientFlag.class)
.add(eq("patient_flag_id", id)).uniqueResult();
}
}
Original file line number Diff line number Diff line change
@@ -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<Flag, PatientFlag> implements FhirFlagService {

@Autowired
private FhirFlagDao dao;

@Autowired
private PatientFlagTranslator translator;

}
Original file line number Diff line number Diff line change
@@ -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<PatientFlag, Flag> {

/**
* 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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<? extends IBaseResource> 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;
}

}
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>patientflags-api</artifactId>
<version>${patinetflagversion}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -501,6 +506,10 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>patientflags-api</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
Expand Down Expand Up @@ -897,6 +906,7 @@
<openmrsPlatformToolsVersion>2.4.1</openmrsPlatformToolsVersion>
<hapifhirVersion>5.7.9</hapifhirVersion>
<ucumVersion>1.0.3</ucumVersion>
<patinetflagversion>3.0.8-SNAPSHOT</patinetflagversion>
</properties>

<profiles>
Expand Down