Skip to content

Commit

Permalink
API to Create CareTeam & Its Participants
Browse files Browse the repository at this point in the history
  • Loading branch information
kalai-tw committed Mar 4, 2024
1 parent 27781c8 commit 0e2bc24
Show file tree
Hide file tree
Showing 19 changed files with 886 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api/src/main/java/org/openmrs/module/ipd/api/dao/CareTeamDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.openmrs.module.ipd.api.dao;

import org.openmrs.Visit;
import org.openmrs.api.db.DAOException;
import org.openmrs.module.ipd.api.model.CareTeam;
import org.openmrs.module.ipd.api.model.Schedule;

public interface CareTeamDAO {

CareTeam saveCareTeam(CareTeam careTeam) throws DAOException;

CareTeam getCareTeamByVisit(Visit visit) throws DAOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.openmrs.module.ipd.api.dao.impl;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.openmrs.Visit;
import org.openmrs.api.db.DAOException;
import org.openmrs.module.ipd.api.dao.CareTeamDAO;
import org.openmrs.module.ipd.api.model.CareTeam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class HibernateCareTeamDAO implements CareTeamDAO {

private static final Logger log = LoggerFactory.getLogger(HibernateCareTeamDAO.class);
private final SessionFactory sessionFactory;

@Autowired
public HibernateCareTeamDAO(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

@Override
public CareTeam saveCareTeam(CareTeam careTeam) throws DAOException {
sessionFactory.getCurrentSession().saveOrUpdate(careTeam);
return careTeam;
}

@Override
public CareTeam getCareTeamByVisit(Visit visit) throws DAOException {
Query query = sessionFactory.getCurrentSession()
.createQuery("FROM CareTeam careteam " +
"WHERE careteam.visit = :visit ");

query.setParameter("visit", visit);

return (CareTeam) query.uniqueResult();
}
}
105 changes: 105 additions & 0 deletions api/src/main/java/org/openmrs/module/ipd/api/model/CareTeam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.openmrs.module.ipd.api.model;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openmrs.BaseChangeableOpenmrsData;
import org.openmrs.Concept;
import org.openmrs.Patient;
import org.openmrs.Visit;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Data
@NoArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@Entity
@Table(name = "care_team")
public class CareTeam extends BaseChangeableOpenmrsData {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "care_team_id")
private Integer careTeamId;

/**
* FHIR:subject
* Patient for Whom care team is for
*/
@ManyToOne(optional = true)
@JoinColumn(name = "patient_id")
private Patient patient;

@OneToOne
@JoinColumn(name = "visit_id", referencedColumnName = "visit_id")
private Visit visit;

/**
* FHIR:period.start
* Starting time with inclusive boundary
*/
@Column(name = "start_time")
private Date startTime;

/**
* FHIR:period.end
* Ending time with inclusive boundary, if not ongoing
*/
@Column(name = "end_time")
private Date endTime;

/**
* FHIR:performer
* @see <a href="https://build.fhir.org/careteam-definitions.html#CareTeam.participant">
* https://build.fhir.org/careteam-definitions.html#CareTeam.participant
* </a>Identifies all people and organizations who are expected to be involved in the care team.
*/
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "care_team_id")
private Set<CareTeamParticipant> participants;


@Override
public Integer getId() {
return this.careTeamId;
}

@Override
public void setId(Integer careTeamId) {
this.careTeamId=careTeamId;
}

public Patient getPatient() {
return patient;
}

public void setPatient(Patient patient) {
this.patient = patient;
}

public Visit getVisit() {
return visit;
}

public void setVisit(Visit visit) {
this.visit = visit;
}

public Date getStartTime() {
return startTime;
}

public void setStartTime(Date startTime) {
this.startTime = startTime;
}

public Date getEndTime() {
return endTime;
}

public void setEndTime(Date endTime) {
this.endTime = endTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package org.openmrs.module.ipd.api.model;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.openmrs.BaseChangeableOpenmrsData;
import org.openmrs.Concept;
import org.openmrs.Provider;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

@Data
@NoArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@Entity
@Table(name = "care_team_participant")
public class CareTeamParticipant extends BaseChangeableOpenmrsData {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "care_team_participant_id")
private Integer careTeamParticipantId;

/**
* FHIR:member
* Indicates Who is involved .
*/
@OneToOne(optional = false)
@JoinColumn(name = "provider_id")
private Provider provider;

/**
* FHIR:function
* @see <a href="https://hl7.org/fhir/valueset-participant-role.html">
* https://hl7.org/fhir/valueset-participant-role.html
* </a>
* i.e. performer, verifier, witness
*/
@ManyToOne(optional = true)
@JoinColumn(name = "role")
private Concept role;

/**
* FHIR:coverage.coveragePeriod.start
* Starting time with inclusive boundary
*/
@Column(name = "start_time")
private Date startTime;

/**
* FHIR:coverage.coveragePeriod.end
* Ending time with inclusive boundary, if not ongoing
*/
@Column(name = "end_time")
private Date endTime;

@Override
public Integer getId() {
return getCareTeamParticipantId();
}

@Override
public void setId(Integer careTeamParticipantId) {
this.careTeamParticipantId=careTeamParticipantId;
}

public Provider getProvider() {
return provider;
}

public void setProvider(Provider provider) {
this.provider = provider;
}

public Concept getRole() {
return role;
}

public void setRole(Concept role) {
this.role = role;
}

public Date getStartTime() {
return startTime;
}

public void setStartTime(Date startTime) {
this.startTime = startTime;
}

public Date getEndTime() {
return endTime;
}

public void setEndTime(Date endTime) {
this.endTime = endTime;
}

public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj != null && this.getClass() == obj.getClass()) {
CareTeamParticipant other = (CareTeamParticipant) obj;
return Objects.equals(this.getUuid(), other.getUuid());
} else {
return false;
}
}

public int hashCode() {
int hash = Objects.hash(new Object[]{this.getUuid()});
return hash;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.openmrs.module.ipd.api.service;

import org.openmrs.Visit;
import org.openmrs.api.APIException;
import org.openmrs.module.ipd.api.model.CareTeam;
import org.openmrs.module.ipd.api.model.Schedule;
import org.springframework.stereotype.Service;
import org.openmrs.api.OpenmrsService;


@Service
public interface CareTeamService extends OpenmrsService {

CareTeam saveCareTeam(CareTeam careTeam) throws APIException;

CareTeam getCareTeamByVisit(Visit visit) throws APIException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.openmrs.module.ipd.api.service.impl;


import org.openmrs.Visit;
import org.openmrs.api.APIException;
import org.openmrs.api.impl.BaseOpenmrsService;
import org.openmrs.module.ipd.api.dao.CareTeamDAO;
import org.openmrs.module.ipd.api.model.CareTeam;
import org.openmrs.module.ipd.api.model.Schedule;
import org.openmrs.module.ipd.api.service.CareTeamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CareTeamServiceImpl extends BaseOpenmrsService implements CareTeamService {

private static final Logger log = LoggerFactory.getLogger(CareTeamServiceImpl.class);

private final CareTeamDAO careTeamDAO;

@Autowired
public CareTeamServiceImpl(CareTeamDAO careTeamDAO) {
this.careTeamDAO = careTeamDAO;
}

@Override
public CareTeam saveCareTeam(CareTeam careTeam) throws APIException {
return careTeamDAO.saveCareTeam(careTeam);
}

@Override
public CareTeam getCareTeamByVisit(Visit visit) throws APIException {
return careTeamDAO.getCareTeamByVisit(visit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.*;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class DateTimeUtil {
public static LocalDateTime convertEpocUTCToLocalTimeZone(long utcTime) {
Expand All @@ -19,4 +20,10 @@ public static LocalDateTime convertDateToLocalDateTime(Date date) {
public static Date convertLocalDateTimeDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}

public static Date convertEpochTimeToDate(Long utcTime) {
return new Date(TimeUnit.SECONDS.toMillis(utcTime));
}


}
Loading

0 comments on commit 0e2bc24

Please sign in to comment.