Skip to content

Commit

Permalink
Created translations for appointment participants; patient, provider …
Browse files Browse the repository at this point in the history
…and apointment provider
  • Loading branch information
jecihjoy committed Apr 25, 2020
1 parent f56afeb commit fdbca3a
Show file tree
Hide file tree
Showing 12 changed files with 715 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ public class AppointmentFhirConstants extends FhirConstants {

public static final String APPOINTMENT_SPECIALITY_VALUESET_URI = HL7_FHIR_VALUE_SET_PREFIX
+ "/c80-practice-codes";

public static final String APPOINTMENT_PARTICIPANT_TYPE = HL7_FHIR_VALUE_SET_PREFIX
+ "/encounter-participant-type";

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.openmrs.module.fhir2.api.dao.FhirAppointmentDao;
import org.openmrs.module.fhir2.api.translators.AppointmentTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Primary
@Component
@Transactional
@Setter(AccessLevel.PACKAGE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.openmrs.module.fhirappnt.api.translators;

import org.hl7.fhir.r4.model.Appointment;
import org.openmrs.module.fhir2.api.translators.OpenmrsFhirUpdatableTranslator;

public interface AppointmentParticipantTranslator<T> extends OpenmrsFhirUpdatableTranslator<T, Appointment.AppointmentParticipantComponent> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.openmrs.module.fhirappnt.api.translators.impl;

import lombok.AccessLevel;
import lombok.Setter;
import org.hl7.fhir.r4.model.Appointment;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.openmrs.Patient;
import org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator;
import org.openmrs.module.fhir2.api.translators.impl.AbstractReferenceHandlingTranslator;
import org.openmrs.module.fhirappnt.api.AppointmentFhirConstants;
import org.openmrs.module.fhirappnt.api.translators.AppointmentParticipantTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Setter(AccessLevel.PACKAGE)
public class AppointmentPatientTranslatorImpl extends AbstractReferenceHandlingTranslator implements AppointmentParticipantTranslator<Patient> {

@Autowired
private PatientReferenceTranslator patientReferenceTranslator;

@Override
public Appointment.AppointmentParticipantComponent toFhirResource(Patient patient) {
if (patient == null) {
return null;
}
Appointment.AppointmentParticipantComponent participant = new Appointment.AppointmentParticipantComponent();
CodeableConcept role = new CodeableConcept();
role.addCoding(new Coding(AppointmentFhirConstants.APPOINTMENT_PARTICIPANT_TYPE, "Patient", "Patient"));
participant.setRequired(Appointment.ParticipantRequired.REQUIRED);
participant.setActor(patientReferenceTranslator.toFhirResource(patient));
participant.addType(role);
participant.setStatus(Appointment.ParticipationStatus.ACCEPTED);

return participant;
}

@Override
public Patient toOpenmrsType(Appointment.AppointmentParticipantComponent appointmentParticipantComponent) {
return toOpenmrsType(new Patient(), appointmentParticipantComponent);
}

@Override
public Patient toOpenmrsType(Patient patient, Appointment.AppointmentParticipantComponent appointmentParticipantComponent) {
if (appointmentParticipantComponent == null) {
return patient;
}

return patientReferenceTranslator.toOpenmrsType(appointmentParticipantComponent.getActor());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.openmrs.module.fhirappnt.api.translators.impl;

import lombok.AccessLevel;
import lombok.Setter;
import org.hl7.fhir.r4.model.Appointment;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.openmrs.Provider;
import org.openmrs.module.fhir2.api.dao.FhirPractitionerDao;
import org.openmrs.module.fhir2.api.translators.impl.AbstractReferenceHandlingTranslator;
import org.openmrs.module.fhirappnt.api.AppointmentFhirConstants;
import org.openmrs.module.fhirappnt.api.translators.AppointmentParticipantTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Setter(AccessLevel.PACKAGE)
public class AppointmentPractitionerTranslatorImpl extends AbstractReferenceHandlingTranslator implements AppointmentParticipantTranslator<Provider> {

@Autowired
private FhirPractitionerDao practitionerDao;

@Override
public Appointment.AppointmentParticipantComponent toFhirResource(Provider provider) {
if (provider == null) {
return null;
}
Appointment.AppointmentParticipantComponent participant = new Appointment.AppointmentParticipantComponent();
CodeableConcept role = new CodeableConcept();
role.addCoding(new Coding(AppointmentFhirConstants.APPOINTMENT_PARTICIPANT_TYPE, "Practitioner", "Practitioner"));
participant.setRequired(Appointment.ParticipantRequired.OPTIONAL);
participant.setActor(createPractitionerReference(provider));
participant.addType(role);

return participant;
}

@Override
public Provider toOpenmrsType(Appointment.AppointmentParticipantComponent appointmentParticipantComponent) {
return toOpenmrsType(new Provider(), appointmentParticipantComponent);
}

@Override
public Provider toOpenmrsType(Provider appointmentProvider, Appointment.AppointmentParticipantComponent appointmentParticipantComponent) {
if (appointmentParticipantComponent == null) {
return appointmentProvider;
}

return practitionerDao.getProviderByUuid(getReferenceId(appointmentParticipantComponent.getActor()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.openmrs.module.fhirappnt.api.translators.impl;
import lombok.AccessLevel;
import lombok.Setter;
import org.hl7.fhir.r4.model.Appointment;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.openmrs.module.appointments.model.AppointmentProvider;
import org.openmrs.module.appointments.model.AppointmentProviderResponse;
import org.openmrs.module.fhir2.api.dao.FhirPractitionerDao;
import org.openmrs.module.fhir2.api.translators.impl.AbstractReferenceHandlingTranslator;
import org.openmrs.module.fhirappnt.api.AppointmentFhirConstants;
import org.openmrs.module.fhirappnt.api.translators.AppointmentParticipantTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Setter(AccessLevel.PACKAGE)
public class AppointmentProviderTranslatorImpl extends AbstractReferenceHandlingTranslator implements AppointmentParticipantTranslator<AppointmentProvider> {

@Autowired
private FhirPractitionerDao practitionerDao;

@Override
public Appointment.AppointmentParticipantComponent toFhirResource(AppointmentProvider appointmentProvider) {
if (appointmentProvider == null || appointmentProvider.getProvider() == null) {
return null;
}
Appointment.AppointmentParticipantComponent participant = new Appointment.AppointmentParticipantComponent();
CodeableConcept role = new CodeableConcept();
role.addCoding(new Coding(AppointmentFhirConstants.APPOINTMENT_PARTICIPANT_TYPE, "AppointmentPractitioner", "AppointmentPractitioner"));
participant.setRequired(Appointment.ParticipantRequired.OPTIONAL);
participant.setActor(createPractitionerReference(appointmentProvider.getProvider()));
participant.addType(role);

switch (appointmentProvider.getResponse()) {
case ACCEPTED:
return participant.setStatus(Appointment.ParticipationStatus.ACCEPTED);
case TENTATIVE:
return participant.setStatus(Appointment.ParticipationStatus.TENTATIVE);
case AWAITING:
return participant.setStatus(Appointment.ParticipationStatus.NEEDSACTION);
case REJECTED:
return participant.setStatus(Appointment.ParticipationStatus.DECLINED);
case CANCELLED:
return participant.setStatus(Appointment.ParticipationStatus.NULL);
}

return participant;
}

@Override
public AppointmentProvider toOpenmrsType(Appointment.AppointmentParticipantComponent appointmentParticipantComponent) {
return toOpenmrsType(new AppointmentProvider(), appointmentParticipantComponent);
}

@Override
public AppointmentProvider toOpenmrsType(AppointmentProvider appointmentProvider, Appointment.AppointmentParticipantComponent appointmentParticipantComponent) {
if (appointmentParticipantComponent == null) {
return appointmentProvider;
}
appointmentProvider.setProvider(practitionerDao.getProviderByUuid(getReferenceId(appointmentParticipantComponent.getActor())));
switch (appointmentParticipantComponent.getStatus()) {
case ACCEPTED:
appointmentProvider.setResponse(AppointmentProviderResponse.ACCEPTED);
case TENTATIVE:
appointmentProvider.setResponse(AppointmentProviderResponse.TENTATIVE);
case NEEDSACTION:
appointmentProvider.setResponse(AppointmentProviderResponse.AWAITING);
case DECLINED:
appointmentProvider.setResponse(AppointmentProviderResponse.REJECTED);
case NULL:
appointmentProvider.setResponse(AppointmentProviderResponse.CANCELLED);
}

return appointmentProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import org.openmrs.module.fhirappnt.api.AppointmentFhirConstants;
import org.openmrs.module.fhirappnt.api.translators.AppointmentSpecialityTranslator;
import org.openmrs.module.appointments.model.Speciality;
import org.springframework.stereotype.Component;

@Component
public class AppointmentSpecialityTranslatorImpl implements AppointmentSpecialityTranslator {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
package org.openmrs.module.fhirappnt.api.translators.impl;

import lombok.AccessLevel;
import lombok.Setter;
import org.hl7.fhir.r4.model.Appointment;
import org.openmrs.Patient;
import org.openmrs.Provider;
import org.openmrs.module.appointments.model.AppointmentProvider;
import org.openmrs.module.appointments.model.AppointmentStatus;
import org.openmrs.module.fhir2.api.translators.AppointmentTranslator;
import org.openmrs.module.fhirappnt.api.translators.AppointmentParticipantTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

@Component
@Setter(AccessLevel.PACKAGE)
public class AppointmentTranslatorImpl implements AppointmentTranslator<org.openmrs.module.appointments.model.Appointment> {

@Autowired
private AppointmentParticipantTranslator<Patient> patientTranslator;

@Autowired
private AppointmentParticipantTranslator<Provider> providerTranslator;

@Autowired
private AppointmentParticipantTranslator<AppointmentProvider> appointmentParticipantTranslator;

@Override
public Appointment toFhirResource(org.openmrs.module.appointments.model.Appointment appointment) {
Appointment fhirAppointment = new Appointment();
fhirAppointment.setId(appointment.getUuid());
fhirAppointment.setStart(appointment.getStartDateTime());
fhirAppointment.setEnd(appointment.getEndDateTime());
fhirAppointment.addParticipant(patientTranslator.toFhirResource(appointment.getPatient()));
if (appointment.getProvider() != null){
fhirAppointment.addParticipant(providerTranslator.toFhirResource(appointment.getProvider()));
}

if (appointment.getProviders() != null) {
for (AppointmentProvider provider : appointment.getProviders()) {
fhirAppointment.addParticipant(appointmentParticipantTranslator.toFhirResource(provider));
}
}

switch (appointment.getStatus()) {
case Requested :
Expand Down Expand Up @@ -58,6 +83,23 @@ public org.openmrs.module.appointments.model.Appointment toOpenmrsType(org.openm
appointment.setStartDateTime(fhirAppointment.getStart());
appointment.setEndDateTime(fhirAppointment.getEnd());

Set<AppointmentProvider> providers = new HashSet<>();

if (fhirAppointment.hasParticipant()) {
for (Appointment.AppointmentParticipantComponent participantComponent : fhirAppointment.getParticipant()) {
if (participantComponent.getType().get(0).getCoding().get(0).getCode() == "Patient") {
appointment.setPatient(patientTranslator.toOpenmrsType(participantComponent));
} else if (participantComponent.getType().get(0).getCoding().get(0).getCode() == "Practitioner") {
appointment.setProvider(providerTranslator.toOpenmrsType(participantComponent));
} else {
AppointmentProvider provider = appointmentParticipantTranslator.toOpenmrsType(participantComponent);
provider.setAppointment(appointment);
providers.add(provider);
appointment.setProviders(providers);
}
}
}

if (fhirAppointment.hasStatus()) {
switch (fhirAppointment.getStatus()) {
case PROPOSED:
Expand All @@ -84,4 +126,4 @@ public org.openmrs.module.appointments.model.Appointment toOpenmrsType(org.openm

return appointment;
}
}
}
Loading

0 comments on commit fdbca3a

Please sign in to comment.