Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #115 from rasanjanap/FM-187
Browse files Browse the repository at this point in the history
  • Loading branch information
harsha89 committed Jun 22, 2016
2 parents 004ca8d + 6623632 commit 6896ef4
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 3 deletions.
53 changes: 51 additions & 2 deletions api/pom.xml
Expand Up @@ -12,7 +12,8 @@
Copyright (C) OpenMRS, LLC. All Rights Reserved.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -84,12 +85,60 @@
<groupId>com.phloc</groupId>
<artifactId>phloc-commons</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-api</artifactId>
<version>${emrApiConditionModuleApiVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-api-1.12</artifactId>
<version>${emrApiConditionModuleApiVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-condition-list</artifactId>
<version>1.5</version>
<version>${emrApiConditionModuleApiVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>appointmentscheduling-api</artifactId>
<version>${appointmentschedulingVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reporting-api</artifactId>
<version>${reportingModuleApiVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>calculation-api</artifactId>
<version>${calculationModuleApiVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api-2.0</artifactId>
<version>${serializationModuleApiVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>providermanagement-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reportingcompatibility-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
@@ -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;
}
}
24 changes: 24 additions & 0 deletions api/src/main/java/org/openmrs/module/fhir/api/util/FHIRUtils.java
Expand Up @@ -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();
Expand Down
Expand Up @@ -14,14 +14,19 @@
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;

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
Expand Down
@@ -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());
}
}
27 changes: 27 additions & 0 deletions api/src/test/resources/standardAppointmentTestDataset.xml
@@ -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&apos;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>
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -72,6 +72,11 @@
<thymeleafVersion>2.1.4.RELEASE</thymeleafVersion>
<phlocSchematronVersion>2.7.1</phlocSchematronVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<appointmentschedulingVersion>1.5</appointmentschedulingVersion>
<reportingModuleApiVersion>0.10.0</reportingModuleApiVersion>
<calculationModuleApiVersion>1.0</calculationModuleApiVersion>
<serializationModuleApiVersion>0.2.11</serializationModuleApiVersion>
<emrApiConditionModuleApiVersion>1.13</emrApiConditionModuleApiVersion>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit 6896ef4

Please sign in to comment.