diff --git a/api/pom.xml b/api/pom.xml index 2d149af4..6feec8f0 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -12,7 +12,8 @@ Copyright (C) OpenMRS, LLC. All Rights Reserved. --> - + 4.0.0 @@ -84,12 +85,60 @@ com.phloc phloc-commons + + org.openmrs.module + emrapi-api + ${emrApiConditionModuleApiVersion} + provided + + + org.openmrs.module + emrapi-api-1.12 + ${emrApiConditionModuleApiVersion} + provided + org.openmrs.module emrapi-condition-list - 1.5 + ${emrApiConditionModuleApiVersion} + provided + + + org.openmrs.module + appointmentscheduling-api + ${appointmentschedulingVersion} + provided + + + org.openmrs.module + reporting-api + ${reportingModuleApiVersion} provided + + org.openmrs.module + calculation-api + ${calculationModuleApiVersion} + provided + + + org.openmrs.module + serialization.xstream-api-2.0 + ${serializationModuleApiVersion} + provided + + + org.openmrs.module + providermanagement-api + 2.4 + provided + + + org.openmrs.module + reportingcompatibility-api + 2.0.0-SNAPSHOT + provided + diff --git a/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRAppointmentUtil.java b/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRAppointmentUtil.java new file mode 100644 index 00000000..8ce63f02 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRAppointmentUtil.java @@ -0,0 +1,114 @@ +/* + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.api.util; + +import ca.uhn.fhir.model.api.TemporalPrecisionEnum; +import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; +import ca.uhn.fhir.model.dstu2.composite.CodingDt; +import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; +import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; +import ca.uhn.fhir.model.dstu2.valueset.AppointmentStatusEnum; +import ca.uhn.fhir.model.dstu2.valueset.ParticipantTypeEnum; +import ca.uhn.fhir.model.primitive.BaseDateTimeDt; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.InstantDt; +import org.openmrs.ConceptMap; +import org.openmrs.Condition; +import org.openmrs.module.appointmentscheduling.Appointment; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class FHIRAppointmentUtil { + + public static ca.uhn.fhir.model.dstu2.resource.Appointment generateFHIRAppointment(Appointment appointment) { + ca.uhn.fhir.model.dstu2.resource.Appointment fhirAppointment = new ca.uhn.fhir.model.dstu2.resource.Appointment(); + IdDt id = new IdDt(); + id.setValue(appointment.getUuid()); + fhirAppointment.setId(id); + + //Set appointment id as a identifier + IdentifierDt identifier = new IdentifierDt(); + identifier.setValue(Integer.toString(appointment.getAppointmentId())); + fhirAppointment.addIdentifier(identifier); + + //Set patient reference + ResourceReferenceDt patient = FHIRUtils.buildPatientOrPersonResourceReference(appointment.getPatient()); + + //Set practitioner reference + ResourceReferenceDt practitioner = FHIRUtils.buildPractitionerReference(appointment.getTimeSlot().getAppointmentBlock().getProvider()); + + List participants = new ArrayList(); + ca.uhn.fhir.model.dstu2.resource.Appointment.Participant participantPatient = new ca.uhn.fhir.model.dstu2.resource.Appointment.Participant(); + participantPatient.setActor(patient); + + ca.uhn.fhir.model.dstu2.resource.Appointment.Participant participantPractitioner = new ca.uhn.fhir.model.dstu2.resource.Appointment.Participant(); + participantPractitioner.setActor(practitioner); + + //Add participant and provider + participants.add(participantPatient); + participants.add(participantPractitioner); + + fhirAppointment.setParticipant(participants); + + //Set appointment status + Appointment.AppointmentStatus appointmentStatus = appointment.getStatus(); + + if (Appointment.AppointmentStatus.CANCELLED.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.CANCELLED); + } else if (Appointment.AppointmentStatus.SCHEDULED.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.BOOKED); + } else if (Appointment.AppointmentStatus.RESCHEDULED.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.BOOKED); + } else if (Appointment.AppointmentStatus.WALKIN.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.PENDING); + } else if (Appointment.AppointmentStatus.INCONSULTATION.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.ARRIVED); + } else if (Appointment.AppointmentStatus.CANCELLED.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.CANCELLED); + } else if (Appointment.AppointmentStatus.CANCELLED_AND_NEEDS_RESCHEDULE.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.CANCELLED); + } else if (Appointment.AppointmentStatus.MISSED.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.NO_SHOW); + } else if (Appointment.AppointmentStatus.COMPLETED.getName().equalsIgnoreCase(appointmentStatus.getName())) { + fhirAppointment.setStatus(AppointmentStatusEnum.FULFILLED); + } else { + fhirAppointment.setStatus(AppointmentStatusEnum.PENDING); + } + + //Set start date + fhirAppointment.setStart(appointment.getTimeSlot().getStartDate(), TemporalPrecisionEnum.DAY); + + //Set end date + fhirAppointment.setStart(appointment.getTimeSlot().getEndDate(), TemporalPrecisionEnum.DAY); + + //Set reason + CodeableConceptDt reason = new CodeableConceptDt(); + reason.setText(appointment.getReason()); + fhirAppointment.setReason(reason); + + //Set appointment type + CodeableConceptDt type = new CodeableConceptDt(); + type.setText(appointment.getAppointmentType().getName()); + fhirAppointment.setType(type); + + return fhirAppointment; + } + + public static Appointment generateOpenMRSAppointmentModuleAppointment() { + return null; + } +} diff --git a/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRUtils.java b/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRUtils.java index 81c9c672..9d3469dc 100644 --- a/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRUtils.java +++ b/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRUtils.java @@ -141,6 +141,30 @@ public static ResourceReferenceDt buildPatientOrPersonResourceReference(org.open return reference; } + /** + * Generates practitioner referenceDt + * + * @param provider the provider ob + * + * @return the practitioner resource reference + */ + public static ResourceReferenceDt buildPractitionerReference(org.openmrs.Provider provider) { + ResourceReferenceDt providerDt = new ResourceReferenceDt(); + StringBuilder providerNameDisplay = new StringBuilder(); + providerNameDisplay.append(provider.getName()); + providerNameDisplay.append("("); + providerNameDisplay.append(FHIRConstants.IDENTIFIER); + providerNameDisplay.append(":"); + providerNameDisplay.append(provider.getIdentifier()); + providerNameDisplay.append(")"); + providerDt.setDisplay(providerNameDisplay.toString()); + IdDt providerRef = new IdDt(); + String providerUri = FHIRConstants.PRACTITIONER + "/" + provider.getUuid(); + providerRef.setValue(providerUri); + providerDt.setReference(providerRef); + return providerDt; + } + public static CodingDt getCodingDtByConceptMappings(ConceptMap conceptMap) { //Set concept source concept name as the display value and set concept uuid if name is empty String display = conceptMap.getConceptReferenceTerm().getName(); diff --git a/api/src/main/java/org/openmrs/module/fhir/appointment/AppointmentModuleStrategy.java b/api/src/main/java/org/openmrs/module/fhir/appointment/AppointmentModuleStrategy.java index e6b9c95f..ac9b3ae4 100644 --- a/api/src/main/java/org/openmrs/module/fhir/appointment/AppointmentModuleStrategy.java +++ b/api/src/main/java/org/openmrs/module/fhir/appointment/AppointmentModuleStrategy.java @@ -14,6 +14,9 @@ package org.openmrs.module.fhir.appointment; import ca.uhn.fhir.model.dstu2.resource.Appointment; +import org.openmrs.api.context.Context; +import org.openmrs.module.appointmentscheduling.api.AppointmentService; +import org.openmrs.module.fhir.api.util.FHIRAppointmentUtil; import java.util.List; @@ -21,7 +24,9 @@ public class AppointmentModuleStrategy implements GenericAppointmentStrategy { @Override public Appointment getAppointmentById(String uuid) { - return null; + AppointmentService appointmentService = Context.getService(AppointmentService.class); + org.openmrs.module.appointmentscheduling.Appointment appointment = appointmentService.getAppointmentByUuid(uuid); + return FHIRAppointmentUtil.generateFHIRAppointment(appointment); } @Override diff --git a/api/src/test/java/org/openmrs/module/fhir/api/AppointmnetServiceTest.java b/api/src/test/java/org/openmrs/module/fhir/api/AppointmnetServiceTest.java new file mode 100644 index 00000000..978af507 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/fhir/api/AppointmnetServiceTest.java @@ -0,0 +1,52 @@ +/* + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.api; + +import ca.uhn.fhir.model.dstu2.resource.Appointment; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.openmrs.api.context.Context; +import org.openmrs.test.BaseModuleContextSensitiveTest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@Ignore +public class AppointmnetServiceTest extends BaseModuleContextSensitiveTest { + + protected static final String APPOINMENT_INITIAL_DATA_XML = "org/openmrs/api/include/ProviderServiceTest-initial.xml"; + + public AppointmentService getService() { + return Context.getService(AppointmentService.class); + } + + @Before + public void runBeforeEachTest() throws Exception { + executeDataSet(APPOINMENT_INITIAL_DATA_XML); + } + + @Test + public void shouldSetupContext() { + assertNotNull(getService()); + } + + @Test + public void getPractitioner_shouldReturnResourceIfExists() { + String appointmentUUid = "c0c579b0-8e59-401d-8a4a-976a0b183601"; + Appointment fhirAppointment = getService().getAppointmentById(appointmentUUid); + assertNotNull(fhirAppointment); + assertEquals(appointmentUUid, fhirAppointment.getId().toString()); + } +} diff --git a/api/src/test/resources/standardAppointmentTestDataset.xml b/api/src/test/resources/standardAppointmentTestDataset.xml new file mode 100644 index 00000000..6cba0adf --- /dev/null +++ b/api/src/test/resources/standardAppointmentTestDataset.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f1a13043..9c84b4c2 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,11 @@ 2.1.4.RELEASE 2.7.1 UTF-8 + 1.5 + 0.10.0 + 1.0 + 0.2.11 + 1.13