This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from rasanjanap/FM-187
- Loading branch information
Showing
7 changed files
with
279 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
api/src/main/java/org/openmrs/module/fhir/api/util/FHIRAppointmentUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ca.uhn.fhir.model.dstu2.resource.Appointment.Participant> participants = new ArrayList<ca.uhn.fhir.model.dstu2.resource.Appointment.Participant>(); | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
api/src/test/java/org/openmrs/module/fhir/api/AppointmnetServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<dataset> | ||
<appointmentscheduling_appointment_type appointment_type_id="1" name="Initial HIV Clinic Appointment" duration="54" description="Initial HIV Clinic Appointment Description" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" uuid="c0c579b0-8e59-401d-8a4a-976a0b183519" confidential="1"/> | ||
<appointmentscheduling_appointment_type appointment_type_id="2" name="Return TB Clinic Appointment" duration="5" description="Return TB Clinic Appointment Description" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" uuid="759799ab-c9a5-435e-b671-77773ada74e4" confidential="0"/> | ||
<appointmentscheduling_appointment_type appointment_type_id="3" name="Hospitalization2" description="Hospitalization Description" duration="10" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" retire_reason="Some Retire Reason" uuid="759799ab-c9a5-435e-b671-77773ada74e6" confidential="0"/> | ||
<appointmentscheduling_appointment_type appointment_type_id="4" name="Hospitalization" description="Hospitalization Description" duration="10" creator="1" date_created="2005-01-01 00:00:00.0" retired="true" retire_reason="Some Retire Reason" uuid="759799ab-c9a5-435e-b671-77373ada74e6" confidential="0"/> | ||
|
||
<appointmentscheduling_appointment_block appointment_block_id="1" start_date="2005-01-01 00:00:00.0" end_date="2005-01-01 11:00:00.0" provider_id="1" location_id="3" uuid="c0c579b0-8e59-401d-8a4a-976a0b183599" date_created="2005-01-01 00:00:00.0" date_changed="2005-01-01 00:00:00.0" date_voided="2005-01-01 00:00:00.0" voided="false" creator="1" changed_by="1"/> | ||
|
||
<provider provider_id="1" person_id="502" identifier="Test Provider" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" uuid="c0c549b0-8e59-401d-8a4a-976a0b183599" /> | ||
|
||
<appointmentscheduling_block_type_map appointment_block_id="1" appointment_type_id="1"/> | ||
|
||
<appointmentscheduling_time_slot time_slot_id="1" appointment_block_id="1" start_date="2006-01-01 00:00:00.0" end_date="2006-01-01 01:00:00.0" uuid="c0c579b0-8e59-401d-8a4a-976a0b183604" date_created="2005-01-01 00:00:00.0" voided="false" creator="1" /> | ||
|
||
<visit visit_id="1" patient_id="2" date_started="2005-01-01 00:00:00.0" uuid="c0c579b0-8e59-401d-8a4a-976a0b183600" date_created="2005-01-01 00:00:00.0" voided="false" creator="1" /> | ||
<patient patient_id="1" creator="1" date_created="2005-01-01 00:00:00.0" voided="false"/> | ||
|
||
<appointmentscheduling_appointment appointment_id="1" time_slot_id="1" appointment_type_id="1" patient_id="1" status="SCHEDULED" uuid="c0c579b0-8e59-401d-8a4a-976a0b183601" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/> | ||
|
||
<appointmentscheduling_appointment_status_history appointment_status_history_id="1" appointment_id="1" status="WAITING" start_date="2005-01-01 00:00:00.0" end_date="2005-01-01 01:00:00.0"/> | ||
|
||
<appointmentscheduling_appointment_request appointment_request_id="1" appointment_type_id="1" patient_id="2" provider_id="1" status="PENDING" requested_on="2014-01-01 00:00:00.0" requested_by="1" min_time_frame_value="0" min_time_frame_units="DAYS" max_time_frame_value="7" max_time_frame_units="DAYS" notes="ASAP" uuid="862c94f0-3dae-11e4-916c-0800200c9a66" date_created="2005-01-01 00:00:00.0" voided="false" creator="1"/> | ||
|
||
<location location_id="2" name="Xanadu" description="A metaphor for opulence, most famously in the English Romantic Samuel Taylor Coleridge's poem Kubla Khan." address1="800 Boylston Street" address2="" city_village="Boston" state_province="MA" postal_code="02115" country="USA" latitude="" longitude="" creator="1" date_created="2008-08-15 13:46:50.0" retired="false" uuid="9356400c-a5a2-4532-8f2b-2361b3446eb7"/> | ||
|
||
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters