-
Notifications
You must be signed in to change notification settings - Fork 38
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
Changes from 4 commits
4ed742a
3e43860
4db1284
abf7082
44fc7f5
426021e
5ae17b0
b3db661
13e0f84
4042779
7dcf60d
87bec2d
1791da9
d898a0e
8bb38c0
676e850
5961c59
83b44cb
8596b8a
74d14f7
2e8f8d7
7d76bfc
fadbbd2
003c8f4
3558739
d885314
1d36ae2
95241ea
17e90b8
acc7041
df8718b
60fe9a5
0e60f5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
|
||
</project> |
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); | ||
} |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't do this in a translator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ibacher where should I add this ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these for?
There was a problem hiding this comment.
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.