1. SDK Sample Application
  2. package com.practo.integration.sdk.sampleapp; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Map; import com.practo.integration.sdk.AppointmentStatus; import com.practo.integration.sdk.AppointmentVisitEvent; import com.practo.integration.sdk.DoctorRegistrationDetails; import com.practo.integration.sdk.Gender; import com.practo.integration.sdk.PatientDetails; import com.practo.integration.sdk.PractoEstablishmentIntegrationSDK; import com.practo.integration.sdk.PractoEstablishmentIntegrationSDKCallback; import com.practo.integration.sdk.SDKException; import com.practo.integration.sdk.WeeklyAvailability; import com.practo.integration.sdk.WeeklyAvailability.DayOfWeek; import com.practo.integration.sdk.impl.PractoIntegrationSDKFactory; public class SampleHIMSApplication { public static void main(String[] args) { String applicationID = "xxxxxx"; String applicationSecret = "xxxxxxxxxxxxxx"; String establishmentKey = "xxxxxxxxxxxxx"; // Create an instance of class that implements PractoIntegrationSDKCallback interface PractoEstablishmentIntegrationSDKCallback sdkCallback = new SampleSDKCallback(); // Create an instance of Practo SDK for a particular establishment PractoEstablishmentIntegrationSDK practoSDK = PractoIntegrationSDKFactory.getSDKInstance(establishmentKey); // first try to initialize with wrong agent config; should fail try { practoSDK.init(applicationID, applicationSecret, establishmentKey, sdkCallback, "http", "localhost1", 7070); } catch (SDKException e) { e.printStackTrace(); } // now try to initialize with wrong credentials; should fail with 401 error try { String invalidEstablishmentKey = establishmentKey + "INVALID"; practoSDK.init(applicationID, applicationSecret, invalidEstablishmentKey, sdkCallback, "http", "localhost", 7070); } catch (SDKException e) { e.printStackTrace(); } // doctor details String doctorName = "Dr. Rajiv Sharma"; String localDoctorId = "2580"; String doctorPhoneNum = "9845098450"; String doctorEmailId = "dr.rajiv@RajivHospital.com"; String doctorSpecialityName = "Ortho surgeon"; String registrationNumber = "KA1234"; String councilName = "Karnataka Medical Council"; String registrationYear = "2002"; String localDepartmentName = "Orthopaedics"; int slotDurationInMinutes = 15; WeeklyAvailability weeklyTimings = new WeeklyAvailability(); try { weeklyTimings.addDoctorTimings(DayOfWeek.MONDAY, "09:00", "12:00"). addDoctorTimings(DayOfWeek.MONDAY, "15:00", "18:30"). addDoctorTimings(DayOfWeek.WEDNESDAY, "09:00", "12:00"). addDoctorTimings(DayOfWeek.FRIDAY, "12:00", "14:00"); } catch (SDKException e) { } DoctorRegistrationDetails registrationDetails = new DoctorRegistrationDetails(); registrationDetails.setRegistrationNumber(registrationNumber); registrationDetails.setCouncilName(councilName); registrationDetails.setRegistrationYear(registrationYear); // try adding a doctor without init() succeeding; should fail try { practoSDK.registerDoctor(doctorName, localDoctorId, Arrays.asList(doctorPhoneNum), Arrays.asList(doctorEmailId), Arrays.asList(doctorSpecialityName), Arrays.asList(registrationDetails), localDepartmentName, slotDurationInMinutes, weeklyTimings); } catch (SDKException e1) { e1.printStackTrace(); } // success cases try { // first connect to Practo try { practoSDK.init(applicationID, applicationSecret, establishmentKey, sdkCallback, "http", "localhost", 7070); } catch (SDKException e1) { e1.printStackTrace(); } // now close SDK and again call init() practoSDK.close(); try { practoSDK.init(applicationID, applicationSecret, establishmentKey, sdkCallback, "http", "localhost", 7070); } catch (SDKException e1) { e1.printStackTrace(); } // 1) call SDK method to register the doctor try { practoSDK.registerDoctor(doctorName, localDoctorId, Arrays.asList(doctorPhoneNum), Arrays.asList(doctorEmailId), Arrays.asList(doctorSpecialityName), Arrays.asList(registrationDetails), localDepartmentName, slotDurationInMinutes, weeklyTimings); } catch (SDKException e1) { e1.printStackTrace(); } // 2) call SDK method to update the doctor details try { practoSDK.updateDoctorDetails(localDoctorId, Arrays.asList(doctorPhoneNum), Arrays.asList(doctorEmailId), Arrays.asList(doctorSpecialityName), Arrays.asList(registrationDetails), weeklyTimings); } catch (SDKException e1) { e1.printStackTrace(); } // add a local appointment String localAppointmentId = "10"; String startDateTime = "2017-03-31T12:30Z"; String endDateTime = "2017-03-31T12:45Z"; String patientFirstName = "rajat"; String patientLastName = "garg"; String patientLocalId = "MRN10025"; String patientMobileNo = "9898984545"; String patientEmailId = "rajat.garg@RajivHospital.com"; String dateOfBirth = "20-03-1985"; PatientDetails patientDetails = new PatientDetails(); patientDetails.setFirstName(patientFirstName); patientDetails.setLastName(patientLastName); patientDetails.setMobileNumbers(Arrays.asList(patientMobileNo)); patientDetails.setEmailIds(Arrays.asList(patientEmailId)); patientDetails.setDateOfBirth(dateOfBirth); patientDetails.setGender(Gender.MALE); // 3) call SDK method to add an appointment try { practoSDK.addAppointment(localAppointmentId, localDoctorId, startDateTime, endDateTime, patientDetails, AppointmentStatus.CONFIRMED); } catch (SDKException e1) { e1.printStackTrace(); } // make some changes to appointment details String newStartDateTime = "2017-03-31T18:00Z"; String newEndDateTime = "2017-03-31T18:15Z"; patientDetails.setUniqueHospitalId(patientLocalId); // 4) call SDK method to update an appointment try { practoSDK.updateAppointment(localAppointmentId, newStartDateTime, newEndDateTime, patientDetails, AppointmentStatus.CONFIRMED); } catch (SDKException e1) { e1.printStackTrace(); } // add doctor timings for particular days String startDate = "2017-04-10"; String endDate = "2017-04-11"; String startTime = "10:00"; String endTime = "12:00"; Map<String, String> dayAvailability = new HashMap<String, String>(); dayAvailability.put(startTime, endTime); // 5) call SDK method to add doctor availability timings only for particular days try { practoSDK.overrideDoctorTimings(localDoctorId, startDate, endDate, dayAvailability); } catch (SDKException e1) { e1.printStackTrace(); } // 6) call SDK method to mark doctor leave for a particular day try { practoSDK.overrideDoctorTimings(localDoctorId, startDate, startDate, null); } catch (SDKException e1) { e1.printStackTrace(); } // 7) call SDK method to notify patient check-in event String checkinTime = "2017-03-31T17:50Z"; try { practoSDK.notifyAppointmentVisitEvent(localAppointmentId, AppointmentVisitEvent.PATIENT_CHECKIN, checkinTime, patientLocalId); } catch (SDKException e1) { e1.printStackTrace(); } // sleep for 60 seconds; wait for any callback events to arrive try { Thread.sleep(60*1000L); } catch (InterruptedException e) {} } finally { // 8) close the SDK instance PractoIntegrationSDKFactory.closeAll(); System.out.println(String.format("[%s] Closed SDK instance", new Date())); } } }
  3. SDK Callback Sample Application
  4. package com.practo.integration.sdk.sampleapp; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import com.practo.integration.sdk.AppointmentAddUpdateResponse; import com.practo.integration.sdk.AppointmentStatus; import com.practo.integration.sdk.CalendarSyncResponse; import com.practo.integration.sdk.DoctorAddUpdateResponse; import com.practo.integration.sdk.DoctorStatus; import com.practo.integration.sdk.MaritalStatus; import com.practo.integration.sdk.PatientDetails; import com.practo.integration.sdk.PractoAppointmentResponse; import com.practo.integration.sdk.PractoEstablishmentIntegrationSDKCallback; import com.practo.integration.sdk.SDKException; public class SampleSDKCallback implements PractoEstablishmentIntegrationSDKCallback { @Override public void handleDoctorStatusChange(String establishmentKey, String doctorId, DoctorStatus doctorStatus) throws SDKException { System.out.println("*** Inside HIMS SDK Callback. Method called: handleDoctorStatusChange() ***"); System.out.println(String.format("[%s] Received establishmentKey: [%s] doctorId: [%s]" + "doctorStatus [%s]", new Date(), establishmentKey, doctorId, doctorStatus)); } @Override public PractoAppointmentResponse handlePractoAppointmentCreated(String establishmentKey, String appointmentId, String doctorId, String startTime, String endTime, PatientDetails patientDetails, AppointmentStatus status, String eventTime) throws SDKException { // validate that patient mobile number is not null if (patientDetails == null || patientDetails.getMobileNumbers() == null || patientDetails.getMobileNumbers().isEmpty()) { throw new SDKException("Mobile number not found"); } // TODO: HIMS application must store Practo appointment in its internal systems and return response String localAppointmentId = "1212"; String uhid = "UHID1200"; System.out.println(String.format("[%s] Received Practo appointment created event. EstablishmentKey: " + "[%s] appointmentId: [%s] doctorId: [%s] startTime: [%s] endTime: [%s] patient details: [%s]" + " status [%s] event time: [%s]. Returning local appointment ID: [%s] and UHID: [%s]", new Date(), establishmentKey, appointmentId, doctorId, startTime, endTime, patientDetails.toString(), status, eventTime, localAppointmentId, uhid)); // create response object PractoAppointmentResponse response = new PractoAppointmentResponse(localAppointmentId, uhid, null); return response; } @Override public PractoAppointmentResponse handlePractoAppointmentUpdated(String establishmentKey, String practoAppointmentId, String appointmentId, String startTime, String endTime, PatientDetails patientDetails, AppointmentStatus status, String eventTime) throws SDKException { // validate that patient mobile number is not null if (patientDetails == null || patientDetails.getMobileNumbers() == null || patientDetails.getMobileNumbers().isEmpty()) { throw new SDKException("Mobile number not found"); } // TODO: HIMS application must update Practo appointment stored in its internal systems and return response String localAppointmentId = "1215"; String uhid = "UHID1200"; System.out.println(String.format("[%s] Received Practo appointment updated event. EstablishmentKey: " + "[%s] practo appointmentId: [%s] local appointmentId: [%s] startTime: [%s] endTime: [%s] " + "patient details: [%s] status [%s] event time: [%s]. Returning local appointment ID: [%s]" + " and UHID: [%s]", new Date(), establishmentKey, practoAppointmentId, appointmentId, startTime, endTime, patientDetails.toString(), status, eventTime, localAppointmentId, uhid)); // create response object PractoAppointmentResponse response = new PractoAppointmentResponse(localAppointmentId, uhid, null); return response; } @Override public List<CalendarSyncResponse> handleCalendarSync(String establishmentKey, String doctorId, String syncStartTime, String syncEndTime) throws SDKException { System.out.println(String.format("[%s] Received calendar sync event for establishmentKey: [%s]" + " doctorId: [%s] syncStartTime [%s] syncEndTime [%s]", new Date(), establishmentKey, doctorId, syncStartTime, syncEndTime)); List<CalendarSyncResponse> syncResponseList = new ArrayList<CalendarSyncResponse>(); for (int i = 0; i < 12; i++) { String localAppointmentId = "220" + i; String startTime = "2017-03-26T10:00Z"; String endTime = "2017-03-26T10:15Z"; String patientFirstName = "rajat"; String patientLastName = "garg"; String patientUhid = "MRN10025"; String patientMobileNo = "9898984545"; String patientEmailId = "rajat.garg@hospitalXYZ.com"; PatientDetails patientDetails = new PatientDetails(); patientDetails.setFirstName(patientFirstName); patientDetails.setLastName(patientLastName); patientDetails.setMobileNumbers(Arrays.asList(patientMobileNo)); patientDetails.setEmailIds(Arrays.asList(patientEmailId)); patientDetails.setUniqueHospitalId(patientUhid); patientDetails.setMaritalStatus(MaritalStatus.MARRIED); CalendarSyncResponse response = new CalendarSyncResponse(localAppointmentId, startTime, endTime, patientDetails, AppointmentStatus.CONFIRMED); System.out.println("Sending calendar sync response: " + response.toString()); syncResponseList.add(response); } return syncResponseList; } @Override public void handleDoctorAddUpdateResponse(String establishmentKey, String doctorId, DoctorAddUpdateResponse responseStatus, String responseMessage) throws SDKException { System.out.println(String.format("[%s] Received doctor add/update response for establishmentKey: " + "[%s] doctorId: [%s] status: [%s] responseMessage: [%s]", new Date(), establishmentKey, doctorId, responseStatus, responseMessage)); } @Override public void handleAppointmentAddUpdateResponse(String establishmentKey, String appointmentId, AppointmentAddUpdateResponse responseStatus, String responseMessage) throws SDKException { System.out.println(String.format("[%s] Received appointment ACK response for establishmentKey: " + "[%s] appointmentId: [%s] status: [%s] responseMessage: [%s]", new Date(), establishmentKey, appointmentId, responseStatus, responseMessage)); } }