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: added FHIR Flag resource #80

Merged
merged 33 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4ed742a
FM2-640: added FHIR FLag resource
ManojLL Jul 9, 2024
3e43860
FM2-640: fixed fhir module loading issue
ManojLL Jul 11, 2024
4db1284
FM2-640: added priority translator
ManojLL Jul 13, 2024
abf7082
FM2-640: remove unwanted imports
ManojLL Jul 13, 2024
44fc7f5
FM2-640: added flag translator
ManojLL Jul 15, 2024
426021e
FM2-640: added flag translator
ManojLL Jul 16, 2024
5ae17b0
FM2-640: added flag search for patient
ManojLL Jul 16, 2024
b3db661
FM2-640: added FHIR2 omod dependency
ManojLL Jul 17, 2024
13e0f84
FM2-640: added search flag using ref patient
ManojLL Jul 17, 2024
4042779
FM2-640: added search params for search patient flags
ManojLL Jul 18, 2024
7dcf60d
FM2-640: Improved the flag search by adding date and category
ManojLL Jul 19, 2024
87bec2d
FLAG 67: fixed flags rendering issue on patient page (#77)
ManojLL Jul 10, 2024
1791da9
(chore) O3-3551: Use latest Actions in GH Actions (#81)
Jul 10, 2024
d898a0e
FLAG-67: fixed flag rendering on platform lower versions (#82)
ManojLL Jul 14, 2024
8bb38c0
FLAG-75: refactor getFlagsForPatient method with stream API (#65)
ManojLL Jul 17, 2024
676e850
FLAG-78: added test for priority services (#84)
ManojLL Jul 20, 2024
5961c59
FLAG 78: added unit tests for patient flag (#78)
ManojLL Jul 20, 2024
83b44cb
FM2-640: added unit tests for fhir module
ManojLL Jul 20, 2024
8596b8a
FM2-640: added unit test for service
ManojLL Jul 22, 2024
74d14f7
FM2-640: added flag dao test
ManojLL Jul 22, 2024
2e8f8d7
FM2-640: updated pom file
ManojLL Jul 22, 2024
7d76bfc
Merge branch 'master' into FM2-640
ManojLL Jul 22, 2024
fadbbd2
FM2-640: fixed the test error
ManojLL Jul 22, 2024
003c8f4
FM2-640: add test for FHIR flag service
ManojLL Jul 23, 2024
3558739
FM2-640: added test for fhirFlagDao
ManojLL Jul 24, 2024
d885314
FM2-640: fixed Dao test executing issue
ManojLL Jul 24, 2024
1d36ae2
FM2-640: fixed Dao test executing issue
ManojLL Jul 24, 2024
95241ea
FM2-640: fixed Dao test executing issue
ManojLL Jul 25, 2024
17e90b8
FM2-640: added FhirFlagDao tests
ManojLL Jul 26, 2024
acc7041
FM2-640: added unit test for search queries
ManojLL Jul 26, 2024
df8718b
FM2-640: changed fhir2 module version 2.2 to 2.0
ManojLL Aug 1, 2024
60fe9a5
FM2-640: localized using FHIR FhirUtils #getMetadataTranslation()
ManojLL Aug 1, 2024
0e60f5d
FM2-640: Implement requested changes
ManojLL Aug 7, 2024
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
105 changes: 105 additions & 0 deletions fhir/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>patientflags</artifactId>
<version>3.0.8-SNAPSHOT</version>
</parent>

<artifactId>patientflags-fhir</artifactId>
<packaging>jar</packaging>
<name>Patient Flags Module FHIR</name>
<description>FHIR project for Patient Flags Module</description>

<dependencies>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>patientflags-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
</dependency>

<!-- include groovy, but mark as provided since it is included with openmrs-core v1.10+-->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.7.6</version>
<type>jar</type>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.txt</include>
<include>**/*.properties</include>
</includes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.txt</exclude>
<exclude>**/*.properties</exclude>
</excludes>
</testResource>
</testResources>
</build>

<properties>
<MODULE_ID>${project.parent.artifactId}</MODULE_ID>
<MODULE_NAME>${project.parent.name}</MODULE_NAME>
<MODULE_VERSION>${project.parent.version}</MODULE_VERSION>
<MODULE_PACKAGE>${project.parent.groupId}.${project.parent.artifactId}</MODULE_PACKAGE>
</properties>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed, I will remove this.


</project>
12 changes: 12 additions & 0 deletions fhir/src/main/java/org/openmrs/patinetflags/FhirFlagService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.openmrs.patinetflags;

import org.hl7.fhir.r4.model.Flag;
import org.openmrs.module.fhir2.api.FhirService;

import javax.annotation.Nonnull;

public interface FhirFlagService extends FhirService<Flag> {

@Override
Flag get(@Nonnull String uuid);
}
12 changes: 12 additions & 0 deletions fhir/src/main/java/org/openmrs/patinetflags/dao/FhirFlagDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.openmrs.patinetflags.dao;

import org.openmrs.module.fhir2.api.dao.FhirDao;
import org.openmrs.module.patientflags.PatientFlag;

import javax.annotation.Nonnull;

public interface FhirFlagDao extends FhirDao<PatientFlag> {

@Override
PatientFlag get(@Nonnull String uuid);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openmrs.patinetflags.dao.impl;

import lombok.Setter;
import lombok.AccessLevel;
import org.hibernate.criterion.Restrictions;
import org.openmrs.Patient;
import org.openmrs.module.fhir2.api.dao.impl.BaseFhirDao;
import org.openmrs.module.patientflags.PatientFlag;
import org.openmrs.patinetflags.dao.FhirFlagDao;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.List;

@Component
@Setter(AccessLevel.PACKAGE)
public class FhirFlagDaoImpl extends BaseFhirDao<PatientFlag> implements FhirFlagDao {

public List getFlagsByPatientId(@Nonnull Patient patient) {
return getSessionFactory().getCurrentSession().createCriteria(PatientFlag.class)
.add(Restrictions.eq("patient", patient)).list();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.openmrs.patinetflags.impl;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.hl7.fhir.r4.model.Flag;

import org.openmrs.module.fhir2.api.impl.BaseFhirService;
import org.openmrs.module.patientflags.PatientFlag;
import org.openmrs.patinetflags.FhirFlagService;
import org.openmrs.patinetflags.dao.FhirFlagDao;
import org.openmrs.patinetflags.translators.PatientFlagTranslator;
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,42 @@
package org.openmrs.patinetflags.providers;

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.IdType;
import org.hl7.fhir.r4.model.Flag;
import org.openmrs.module.fhir2.api.annotations.R4Provider;
import org.openmrs.patinetflags.FhirFlagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;

import static lombok.AccessLevel.PACKAGE;

@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 getFlagById(@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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openmrs.patinetflags.translators;

import org.hl7.fhir.r4.model.Flag;
import org.openmrs.module.fhir2.api.translators.OpenmrsFhirTranslator;
import org.openmrs.module.patientflags.PatientFlag;

import javax.annotation.Nonnull;

public interface PatientFlagTranslator extends OpenmrsFhirTranslator<PatientFlag, Flag> {
/**
* @param patientFlag
* @return
*/
@Override
Flag toFhirResource(@Nonnull PatientFlag patientFlag);

/**
* @param flag
* @return
*/
@Override
PatientFlag toOpenmrsType(@Nonnull Flag flag);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.openmrs.patinetflags.translators;

import org.hl7.fhir.r4.model.CodeableConcept;
import org.openmrs.module.fhir2.api.translators.ToFhirTranslator;
import org.openmrs.module.patientflags.Priority;

import javax.annotation.Nonnull;

public interface PriorityTranslator extends ToFhirTranslator<Priority, CodeableConcept> {

/**
* Maps an OpenMRS data element to a FHIR resource
*
* @param priority the OpenMRS data element to translate
* @return the corresponding FHIR resource
*/
@Override
CodeableConcept toFhirResource(@Nonnull Priority priority);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.openmrs.patinetflags.translators;

import org.hl7.fhir.r4.model.CodeableConcept;
import org.openmrs.module.fhir2.api.translators.ToFhirTranslator;
import org.openmrs.module.patientflags.Tag;

import javax.annotation.Nonnull;

public interface TagTranslator extends ToFhirTranslator<Tag, CodeableConcept> {

/**
* Maps an OpenMRS data element to a FHIR resource
*
* @param tag the OpenMRS data element to translate
* @return the corresponding FHIR resource
*/
@Override
CodeableConcept toFhirResource(@Nonnull Tag tag);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.openmrs.patinetflags.translators.impl;

import static org.apache.commons.lang3.Validate.notNull;

import javax.annotation.Nonnull;

import java.util.Collections;


import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Flag;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Narrative;
import org.hl7.fhir.r4.model.Period;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator;
import org.openmrs.module.patientflags.PatientFlag;
import org.openmrs.patinetflags.translators.PatientFlagTranslator;
import org.openmrs.patinetflags.translators.PriorityTranslator;
import org.openmrs.patinetflags.translators.TagTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PatientFlagTranslatorImpl implements PatientFlagTranslator {

@Autowired
private PatientReferenceTranslator patientReferenceTranslator;

@Autowired
private TagTranslator tagTranslator;

@Autowired
private PriorityTranslator priorityTranslator;

@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());

Narrative narrative = new Narrative();
narrative.setStatus(Narrative.NarrativeStatus.GENERATED);

XhtmlNode xhtmlNode = new XhtmlNode();
xhtmlNode.setName(patientFlag.getMessage());
narrative.setDiv(xhtmlNode);
flag.setText(narrative);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this in a translator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibacher where should I add this ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be best if you could plug into the narrative generation system here, otherwise, just leave it alone for now (I don't, off-hand, remember how that system works).



Identifier identifier = new Identifier();
identifier.setValue(String.valueOf(patientFlag.getPatientFlagId()));
flag.setIdentifier(Collections.singletonList(identifier));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identifier is always the UUID. Never use the database identifier for anything except internal operations.


if (patientFlag.getVoided()) {
flag.setStatus(Flag.FlagStatus.INACTIVE);
} else {
flag.setStatus(Flag.FlagStatus.ACTIVE);
}

patientFlag.getFlag().getTags().forEach(tag -> {
CodeableConcept codeableConcept = tagTranslator.toFhirResource(tag);
flag.addCategory(codeableConcept);
});

flag.setCode(priorityTranslator.toFhirResource(patientFlag.getFlag().getPriority()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code should be the actual message to display to the user.


flag.setSubject(patientReferenceTranslator.toFhirResource(patientFlag.getPatient()));

Period period = new Period();
period.setStart(patientFlag.getDateCreated());
flag.setPeriod(period);

return flag;
}

@Override
public PatientFlag toOpenmrsType(@Nonnull Flag flag) {
return null;
}
}
Loading