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-636: Enhancements in Existing FHIR Task Resource #539

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@

import lombok.AccessLevel;
import lombok.Setter;
import org.hl7.fhir.r4.model.Annotation;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Period;
import org.hl7.fhir.r4.model.Task;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.translators.ConceptTranslator;
import org.openmrs.module.fhir2.api.translators.ReferenceTranslator;
import org.openmrs.module.fhir2.api.translators.TaskInputTranslator;
import org.openmrs.module.fhir2.api.translators.TaskOutputTranslator;
Expand All @@ -45,6 +48,9 @@ public class TaskTranslatorImpl implements TaskTranslator {
@Autowired
private TaskOutputTranslator taskOutputTranslator;

@Autowired
private ConceptTranslator conceptTranslator;

@Override
public Task toFhirResource(@Nonnull FhirTask openmrsTask) {
notNull(openmrsTask, "The openmrsTask object should not be null");
Expand Down Expand Up @@ -116,6 +122,30 @@ private void setFhirTaskFields(FhirTask openmrsTask, Task fhirTask) {
.filter(Objects::nonNull).collect(Collectors.toList()));
}

if (openmrsTask.getTaskCode() != null) {
fhirTask.setCode(conceptTranslator.toFhirResource(openmrsTask.getTaskCode()));
}

if (openmrsTask.getPartOfReferences() != null && !openmrsTask.getPartOfReferences().isEmpty()) {
fhirTask.setPartOf(openmrsTask.getPartOfReferences().stream().map(referenceTranslator::toFhirResource)
.collect(Collectors.toList()));
}

if (openmrsTask.getExecutionStartTime() != null || openmrsTask.getExecutionEndTime() != null) {
Period period = new Period();
if (openmrsTask.getExecutionStartTime() != null) {
period.setStart(openmrsTask.getExecutionStartTime());
}
if (openmrsTask.getExecutionEndTime() != null) {
period.setEnd(openmrsTask.getExecutionEndTime());
}
fhirTask.setExecutionPeriod(period);
}

if (openmrsTask.getComment() != null) {
fhirTask.addNote(new Annotation().setText(openmrsTask.getComment()));
}

fhirTask.setAuthoredOn(openmrsTask.getDateCreated());

if (openmrsTask.getDateChanged() != null) {
Expand Down Expand Up @@ -183,6 +213,28 @@ private void setOpenmrsTaskFields(FhirTask openmrsTask, Task fhirTask) {
.filter(Objects::nonNull).collect(Collectors.toSet()));
}

if (fhirTask.hasCode()) {
openmrsTask.setTaskCode(conceptTranslator.toOpenmrsType(fhirTask.getCode()));
}

if (fhirTask.hasExecutionPeriod()) {
if (fhirTask.getExecutionPeriod().hasStart()) {
openmrsTask.setExecutionStartTime(fhirTask.getExecutionPeriod().getStart());
}
if (fhirTask.getExecutionPeriod().hasEnd()) {
openmrsTask.setExecutionEndTime(fhirTask.getExecutionPeriod().getEnd());
}
}

if (fhirTask.hasPartOf()) {
openmrsTask.setPartOfReferences(
fhirTask.getPartOf().stream().map(referenceTranslator::toOpenmrsType).collect(Collectors.toSet()));
}

if (fhirTask.hasNote()) {
openmrsTask.setComment(fhirTask.getNoteFirstRep().getText());
}

openmrsTask.setName(FhirConstants.TASK + "/" + fhirTask.getId());

}
Expand Down
36 changes: 36 additions & 0 deletions api/src/main/java/org/openmrs/module/fhir2/model/FhirTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import java.util.Date;
import java.util.Set;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openmrs.BaseOpenmrsMetadata;
import org.openmrs.Concept;

@Data
@NoArgsConstructor
Expand Down Expand Up @@ -129,4 +132,37 @@ public enum TaskIntent {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "location_reference_id", referencedColumnName = "reference_id")
private FhirReference locationReference;

/**
* Type of Task
*/
@ManyToOne
@JoinColumn(name = "task_code", referencedColumnName = "concept_id")
protected Concept taskCode;

/**
* Task that this particular task is part of.
*/
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "fhir_task_part_of_reference", joinColumns = @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "reference_id"))
private Set<FhirReference> partOfReferences;

/**
* Actual start time of the execution
*/
@Column(name = "execution_start_time")
private Date executionStartTime;

/**
* Actual end time of the execution
*/
@Column(name = "execution_end_time")
private Date executionEndTime;

/**
* Comment made about the task
*/
@Column(name = "comment")
private String comment;

}
43 changes: 43 additions & 0 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1067,4 +1067,47 @@
<column name="attribute_type_id" />
</createIndex>
</changeSet>

<changeSet id="alter_fhir_task_20230903" author="r.kalai">
<preConditions onFail="MARK_RAN" onError="WARN">
<tableExists tableName="fhir_task"/>
</preConditions>
<addColumn tableName="fhir_task">
<column name="execution_start_time" type="datetime"/>
<column name="execution_end_time" type="datetime"/>
<column name="task_code" type="int"/>
<column name="comment" type="varchar(255)"/>
</addColumn>
<addForeignKeyConstraint baseTableName="fhir_task" baseColumnNames="task_code"
constraintName="task_code_fk"
referencedTableName="concept"
referencedColumnNames="concept_id"/>
</changeSet>

<changeSet id="add_part_of_reference_join_table_20200311" author="r.kalai">
<preConditions onFail="MARK_RAN" onError="WARN">
<not>
<tableExists tableName="fhir_task_part_of_reference"/>
</not>
<tableExists tableName="fhir_task"/>
<tableExists tableName="fhir_reference"/>
</preConditions>
<createTable tableName="fhir_task_part_of_reference">
<column name="task_id" type="int">
<constraints nullable="false"/>
</column>
<column name="reference_id" type="int">
<constraints nullable="false"/>
</column>
</createTable>
<addForeignKeyConstraint baseTableName="fhir_task_part_of_reference" baseColumnNames="task_id"
constraintName="task_part_of_fk"
referencedTableName="fhir_task"
referencedColumnNames="task_id"/>
<addForeignKeyConstraint baseTableName="fhir_task_part_of_reference" baseColumnNames="reference_id"
constraintName="reference_part_of_fk"
referencedTableName="fhir_reference"
referencedColumnNames="reference_id"/>
</changeSet>

</databaseChangeLog>
Loading
Loading