1. Multi Establishment HIMS Sample Application
  2. using practo.integration.sdk; using System; using System.Collections.Generic; using System.Xml; namespace dotnet_sampleapp { /// <summary> /// This sample application illustrates how should an HIMS developer integrate with Practo SDK library /// for a multi-establishment scenario. /// </summary> public class SampleMultiEstablishmentHIMSApplication { public static Dictionary<string, IPractoEstablishmentIntegrationSDK> practoSDKDictionary = new Dictionary<string, IPractoEstablishmentIntegrationSDK>(); public static Dictionary<string, IPractoEstablishmentIntegrationSDKCallback> practoCallbackDictionary = new Dictionary<string, IPractoEstablishmentIntegrationSDKCallback>(); public static PractoEstablishmentMapping mapper; static void Main(string[] args) { // Assume that a multi-centre group of hospitals consists of multiple establishments, // where each establishment is uniquely identified by(local establishment ID, group ID). // For each establishment, a unique profile has to be first created on Practo.com. // Subsequently, an establishment secret key needs to be first generated for // each establishment and saved within external configuration // file(e.g.establishmentGroupMapper.xml as illustrated below). try { XmlDocument xDoc = new XmlDocument(); xDoc.Load("PractoEstablishmentMapping.xml"); mapper = new PractoEstablishmentMapping(xDoc); // HIMS application credentials; created from Practo developer portal. string applicationID = "*******"; string applicationSecret = "******************"; foreach (string establishmentKey in mapper.GetAllEstablishmentKeys()) { // Create Practo SDK for each establishment // Practo SDK must only be created through the PractoIntegrationSDKFactory. practoSDKDictionary[establishmentKey] = PractoIntegrationSDKFactory.GetSDKInstance( establishmentKey); // Create separate instances of SDK Callbacks corresponding to each establishment. practoCallbackDictionary[establishmentKey] = new SampleSDKCallback(establishmentKey); // initialize each instance of Practo SDK string scheme = "http"; string host = "agent.host"; int port = 7070; // agent.port try { practoSDKDictionary[establishmentKey].Init(applicationID, applicationSecret, establishmentKey, practoCallbackDictionary[establishmentKey], scheme, host, port ); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } // Suppose we want to register a new Doctor in local establishment and group id. internal void RegisterDoctor(string groupId, string localEstablishmentId) { // Lookup establishmentKey based on local establishment ID and group ID string practoEstablishmentKey = mapper.GetEstablishmentKey(groupId, localEstablishmentId); if (string.ReferenceEquals(practoEstablishmentKey, null)) { Console.WriteLine("The hospital represented by groupId: " + groupId + ", localEstablishmentId: " + localEstablishmentId + " is not yet integrated with Practo. No establishmentKey generated on Practo yet"); return; } IPractoEstablishmentIntegrationSDK practoSDK = practoSDKDictionary[practoEstablishmentKey]; // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference string name = "Krupa Sagar"; string localDoctorId = "2000"; string phoneNumber = "9090909090"; string emailId = "hbksgar@hospitalABC.com"; string specialityName = "Dermatologist"; string departmentName = "Dermatology"; int slotDurationInMinutes = 15; WeeklyAvailability weeklyTiming = new WeeklyAvailability(); try { weeklyTiming.AddDoctorTimings(DayOfWeek.Monday, "09:00", "12:00") .AddDoctorTimings(DayOfWeek.Tuesday, "09:00", "14:00") .AddDoctorTimings(DayOfWeek.Wednesday, "13:00", "18:30"); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } List<string> doctorMobileNumbers = new List<string>(); doctorMobileNumbers.Add(phoneNumber); List<string> doctorEmailIds = new List<string>(); doctorEmailIds.Add(emailId); List<string> doctorSpecialityName = new List<string>(); doctorSpecialityName.Add(specialityName); string registrationNumber = "KA1234"; string councilName = "Karnataka Medical Council"; string registrationYear = "2002"; DoctorRegistrationDetails registrationDetails = new DoctorRegistrationDetails(); registrationDetails.RegistrationNumber = registrationNumber; registrationDetails.CouncilName = councilName; registrationDetails.RegistrationYear = registrationYear; List<DoctorRegistrationDetails> doctorRegistrationDetails = new List<DoctorRegistrationDetails>(); doctorRegistrationDetails.Add(registrationDetails); try { practoSDK.RegisterDoctor( name, localDoctorId, doctorMobileNumbers, doctorEmailIds, doctorSpecialityName, doctorRegistrationDetails, departmentName, slotDurationInMinutes, weeklyTiming); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } // Suppose we want to update existing Doctor in local establishment and group id. internal void UpdateDoctor(string groupId, string localEstablishmentId) { // Lookup establishmentKey based on local establishment ID and group ID string practoEstablishmentKey = mapper.GetEstablishmentKey(groupId, localEstablishmentId); if (string.ReferenceEquals(practoEstablishmentKey, null)) { Console.WriteLine("The hospital represented by groupId: " + groupId + ", localEstablishmentId: " + localEstablishmentId + " is not yet integrated with Practo. No establishmentKey generated on Practo yet"); return; } IPractoEstablishmentIntegrationSDK practoSDK = practoSDKDictionary[practoEstablishmentKey]; // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference string localDoctorId = "2000"; string phoneNumber = "9090909090"; string emailId = "hbksgar@hospitalABC.com"; string specialityName = "Dermatologist"; WeeklyAvailability weeklyTiming = new WeeklyAvailability(); try { weeklyTiming.AddDoctorTimings(DayOfWeek.Monday, "09:00", "12:00") .AddDoctorTimings(DayOfWeek.Tuesday, "09:00", "14:00") .AddDoctorTimings(DayOfWeek.Wednesday, "13:00", "18:30"); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } List<string> doctorMobileNumbers = new List<string>(); doctorMobileNumbers.Add(phoneNumber); List<string> doctorEmailIds = new List<string>(); doctorEmailIds.Add(emailId); List<string> doctorSpecialityName = new List<string>(); doctorSpecialityName.Add(specialityName); // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference string registrationNumber = "KA1234"; string councilName = "Karnataka Medical Council"; string registrationYear = "2002"; DoctorRegistrationDetails registrationDetails = new DoctorRegistrationDetails(); registrationDetails.RegistrationNumber = registrationNumber; registrationDetails.CouncilName = councilName; registrationDetails.RegistrationYear = registrationYear; List<DoctorRegistrationDetails> doctorRegistrationDetails = new List<DoctorRegistrationDetails>(); doctorRegistrationDetails.Add(registrationDetails); try { practoSDK.UpdateDoctorDetails( localDoctorId, doctorMobileNumbers, doctorEmailIds, doctorSpecialityName, doctorRegistrationDetails, weeklyTiming); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } // Suppose we want to add new appointment for a doctor in local // establishment and group id. internal void AddAppointment(string groupId, string localEstablishmentId) { // Lookup establishmentKey based on local establishment ID and group ID string practoEstablishmentKey = mapper.GetEstablishmentKey(groupId, localEstablishmentId); if (string.ReferenceEquals(practoEstablishmentKey, null)) { Console.WriteLine("The hospital represented by groupId: " + groupId + ", localEstablishmentId: " + localEstablishmentId + " is not yet integrated with Practo. No establishmentKey generated on Practo yet"); return; } IPractoEstablishmentIntegrationSDK practoSDK = practoSDKDictionary[practoEstablishmentKey]; // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference string localAppointmentID = "1101"; string startDateTime = "2017-07-11T10:00Z"; string endDateTime = "2017-07-11T10:15Z"; string patientFirstName = "rajat"; string patientMiddleName = "middle"; string patientLastName = "garg"; string localDoctorId = "2000"; List<string> patientMobileNumbers = new List<string>(); patientMobileNumbers.Add("9999999999"); List<string> patientEmailIds = new List<string>(); patientEmailIds.Add("random@random.com"); PatientDetails patient = new PatientDetails(); patient.EmailIds = patientEmailIds; patient.MobileNumbers = patientMobileNumbers; patient.FirstName = patientFirstName; patient.MiddleName = patientMiddleName; patient.LastName = patientLastName; try { practoSDK.AddAppointment( localAppointmentID, localDoctorId, startDateTime, endDateTime, patient, AppointmentStatus.CONFIRMED); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } // Suppose we want to update an appointment for a doctor in local // establishment and group id. internal void UpdateAppointment(string groupId, string localEstablishmentId) { // Lookup establishmentKey based on local establishment ID and group ID string practoEstablishmentKey = mapper.GetEstablishmentKey(groupId, localEstablishmentId); if (string.ReferenceEquals(practoEstablishmentKey, null)) { Console.WriteLine("The hospital represented by groupId: " + groupId + ", localEstablishmentId: " + localEstablishmentId + " is not yet integrated with Practo. No establishmentKey generated on Practo yet"); return; } IPractoEstablishmentIntegrationSDK practoSDK = practoSDKDictionary[practoEstablishmentKey]; // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference string localAppointmentID = "1101"; string newStartDateTime = "2017-07-11T11:00Z"; string newEndDateTime = "2017-07-12T11:15Z"; string patientID = "IN1234"; string patientFirstName = "rajat"; string patientMiddleName = "middle"; string patientLastName = "garg"; string dateOfBirth = "20-03-1985"; List<string> patientMobileNumbers = new List<string>(); patientMobileNumbers.Add("9999999999"); List<string> patientEmailIds = new List<string>(); patientEmailIds.Add("random@random.com"); PatientDetails patient = new PatientDetails(); patient.EmailIds = patientEmailIds; patient.MobileNumbers = patientMobileNumbers; patient.FirstName = patientFirstName; patient.MiddleName = patientMiddleName; patient.LastName = patientLastName; patient.UniqueHospitalId = patientID; patient.DateOfBirth = dateOfBirth; patient.Gender = Gender.MALE; patient.MaritalStatus = MaritalStatus.UNMARRIED; try { practoSDK.UpdateAppointment( localAppointmentID, newStartDateTime, newEndDateTime, patient, AppointmentStatus.CONFIRMED); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } // Suppose we want to add doctor availability timings only for particular days // in local establishment and group id. internal void AddDoctorAvailability(string groupId, string localEstablishmentId) { // Lookup establishmentKey based on local establishment ID and group ID string practoEstablishmentKey = mapper.GetEstablishmentKey(groupId, localEstablishmentId); if (string.ReferenceEquals(practoEstablishmentKey, null)) { Console.WriteLine("The hospital represented by groupId: " + groupId + ", localEstablishmentId: " + localEstablishmentId + " is not yet integrated with Practo. No establishmentKey generated on Practo yet"); return; } IPractoEstablishmentIntegrationSDK practoSDK = practoSDKDictionary[practoEstablishmentKey]; // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference // Add doctor timings for a particular date string startDateTimeUTC = "2017-04-10T18:30Z"; string endDateTimeUTC = "2017-04-10T09:30Z"; string localDoctorId = "2000"; // 5) call SDK method to add doctor timings for particular date-time duration // e.g. 04-April-2017 [09:00 am - 03:00 pm] IST try { practoSDK.ConfigureDoctorTimings(localDoctorId, startDateTimeUTC, endDateTimeUTC, AvailabilityType.ALLOW); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } // Suppose we want to mark doctor leave for a particular day in // local establishment and group id. internal void UpdateDoctorAvailability(string groupId, string localEstablishmentId) { // Lookup establishmentKey based on local establishment ID and group ID string practoEstablishmentKey = mapper.GetEstablishmentKey(groupId, localEstablishmentId); if (string.ReferenceEquals(practoEstablishmentKey, null)) { Console.WriteLine("The hospital represented by groupId: " + groupId + ", localEstablishmentId: " + localEstablishmentId + " is not yet integrated with Practo. No establishmentKey generated on Practo yet"); return; } IPractoEstablishmentIntegrationSDK practoSDK = practoSDKDictionary[practoEstablishmentKey]; // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference string startDateTimeUTC = "2017-07-04T18:30Z"; string endDateTimeUTC = "2017-07-05T18:30Z"; string localDoctorId = "2000"; try { practoSDK.ConfigureDoctorTimings(localDoctorId, startDateTimeUTC, endDateTimeUTC, AvailabilityType.BLOCK); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } // Suppose we want notify patient check-in event in local establishment and group id. private void NotifyAppointmentVisitEventToPracto(string groupId, string localEstablishmentId) { // Lookup establishmentKey based on local establishment ID and group ID string practoEstablishmentKey = mapper.GetEstablishmentKey(groupId, localEstablishmentId); if (string.ReferenceEquals(practoEstablishmentKey, null)) { Console.WriteLine("The hospital represented by groupId: " + groupId + ", localEstablishmentId: " + localEstablishmentId + " is not yet integrated with Practo. No establishmentKey generated on Practo yet"); return; } IPractoEstablishmentIntegrationSDK practoSDK = practoSDKDictionary[practoEstablishmentKey]; // These parameters are expected to be populated by HIMS developer // Following paramter values are just reference string localAppointmentID = "1101"; string checkinTime = "2017-07-11T17:50Z"; string patientLocalId = "100"; try { practoSDK.NotifyAppointmentVisitEvent(localAppointmentID, AppointmentVisitEvent.PATIENT_CHECKIN, checkinTime, patientLocalId); } catch (SDKException ex) { Console.WriteLine(ex.Message.ToString()); } } // Close all Practo SDK instances internal void CloseAllPractoSDK() { PractoIntegrationSDKFactory.CloseAll(); } } }
  3. SDK Callback Sample Application
  4. using System.Collections.Generic; using practo.integration.sdk; using System.Xml; namespace dotnet_sampleapp { internal class SampleSDKCallback : IPractoEstablishmentIntegrationSDKCallback { private readonly string establishmentKey; private readonly PractoEstablishmentMapping mapper; public SampleSDKCallback(string establishmentKey) { this.establishmentKey = establishmentKey; XmlDocument xDoc = new XmlDocument(); xDoc.Load("PractoEstablishmentMapping.xml"); mapper = new PractoEstablishmentMapping(xDoc); } public PractoAppointmentResponse HandlePractoAppointmentCreated( string establishmentKey, string practoAppointmentId, string doctorId, string startTime, string endTime, PatientDetails patientDetails, AppointmentStatus status, string eventTime) { // Lookup the local establishment ID and group ID based on establishmentKey KeyValuePair<string, string> groupDetail = mapper.GetGroupDetails(establishmentKey); string groupId = groupDetail.Key; string localEstablishmentId = groupDetail.Value; // Suppose you want to assert that patient mobile number is not null if (patientDetails == null || patientDetails.MobileNumbers == null || patientDetails.MobileNumbers.Count == 0) { throw new SDKException("Mobile number not found"); } // TODO: HIMS developer must store the Practo appointment details corresponding to the // input combination of (doctorId, groupId, localEstablishmentId) within their systems. // After successfully storing the appointment, developer must return the // local appointment ID as the response. // Assuming local appointment ID and uhid string localAppointmentId = "100"; string uhid = "UHID1200"; // create response object PractoAppointmentResponse response = new PractoAppointmentResponse( localAppointmentId, uhid, null); return response; } public PractoAppointmentResponse HandlePractoAppointmentUpdated( string establishmentKey, string practoAppointmentId, string appointmentId, string startTime, string endTime, PatientDetails patientDetails, AppointmentStatus status, string eventTime) { // Lookup the local establishment ID and group ID based on establishmentKey KeyValuePair<string, string> groupDetail = mapper.GetGroupDetails(establishmentKey); string groupId = groupDetail.Key; string localEstablishmentId = groupDetail.Value; // TODO: HIMS developer must store the Practo appointment details corresponding to the // input combination of (doctorId, groupId, localEstablishmentId) within their systems. // After successfully storing the appointment, developer must return the // local appointment ID as the response. // Assuming local uhid string uhid = "UHID1200"; PractoAppointmentResponse response = new PractoAppointmentResponse( appointmentId, uhid, null); return response; } public List<CalendarSyncResponse> HandleCalendarSync( string establishmentKey, string doctorId, string syncStartTime, string syncEndTime) { // Lookup the local establishment ID and group ID based on establishmentKey KeyValuePair<string, string> groupDetail = mapper.GetGroupDetails(establishmentKey); string groupId = groupDetail.Key; string localEstablishmentId = groupDetail.Value; List<CalendarSyncResponse> calenderSync = new List<CalendarSyncResponse>(); // TODO: HIMS developer must use (local establishment ID, group ID) to fetch appointments // for the input time duration, in order to sync the doctor calendar with Practo. // Assume the following output for sample reference. /* for (int i = 0; i <= 10; i++) { string localAppointmentId = "220" + i; string startTime = "2017-03-26T10:00Z"; string endTime = "2017-03-26T10:15Z"; string patientFirstName = "rajat"; string patientMiddleName = "middle"; string patientLastName = "garg"; string patientUhid = "MRN10025"; string patientMobileNo = "9898984545"; string patientEmailId = "rajat.garg@hospitalXYZ.com"; PatientDetails patientDetails = new PatientDetails(); patientDetails.FirstName = patientFirstName; patientDetails.MiddleName = patientMiddleName; patientDetails.LastName = patientLastName; patientDetails.UniqueHospitalId = patientUhid; patientDetails.MaritalStatus = MaritalStatus.UNMARRIED; List<string> patientMobileNos = new List<string>(); patientMobileNos.Add(patientMobileNo); patientDetails.MobileNumbers = patientMobileNos; List<string> patientEmailIds = new List<string>(); patientEmailIds.Add(patientEmailId); patientDetails.EmailIds = patientEmailIds; CalendarSyncResponse response = new CalendarSyncResponse( localAppointmentId, startTime, endTime, patientDetails, AppointmentStatus.CONFIRMED ); Console.WriteLine("Sending calender sync for local establishment id: " + groupDetail.Key + " and group id: " + groupDetail.Value + " with response: " + response.ToString()); calenderSync.Add(response); } */ return calenderSync; } public void HandleDoctorAddUpdateResponse(string establishmentKey, string doctorId, DoctorAddUpdateResponse responseStatus, string responseMessage) { // Lookup the local establishment ID and group ID based on establishmentKey KeyValuePair<string, string> groupDetail = mapper.GetGroupDetails(establishmentKey); string groupId = groupDetail.Key; string localEstablishmentId = groupDetail.Value; // TODO: HIMS developer can use doctor details add/update acknowledgement from Practo } public void HandleDoctorStatusChange(string establishmentKey, string doctorId, DoctorStatus doctorStatus) { // Lookup the local establishment ID and group ID based on establishmentKey KeyValuePair<string, string> groupDetail = mapper.GetGroupDetails(establishmentKey); string groupId = groupDetail.Key; string localEstablishmentId = groupDetail.Value; // TODO: HIMS developer can use doctor status change acknowledgement from Practo } public void HandleAppointmentAddUpdateResponse( string establishmentKey, string appointmentId, AppointmentAddUpdateResponse responseStatus, string responseMessage) { // Lookup the local establishment ID and group ID based on establishmentKey KeyValuePair<string, string> groupDetail = mapper.GetGroupDetails(establishmentKey); string groupId = groupDetail.Key; string localEstablishmentId = groupDetail.Value; // TODO: HIMS developer can use appointment details add/update acknowledgement from Practo } } }
  5. Practo Establishment Mapping Loader
  6. using System.Collections.Generic; using System.Xml; namespace dotnet_sampleapp { /// <summary> /// This class loads configuration of (practoEstablishmentKey, local establishment ID, group ID) /// mappings from an external xml file, and exposes convenience methods to perform lookup /// based on either practoEstablishmentKey, or (local establishment ID, group ID) /// </summary> public class PractoEstablishmentMapping { private XmlDocument xDoc = null; private Dictionary<string, KeyValuePair<string, string>> establishmentDictionary = null; private Dictionary<KeyValuePair<string, string>, string> groupDictionary = null; public PractoEstablishmentMapping(XmlDocument xDoc) { this.xDoc = xDoc; establishmentDictionary = new Dictionary<string, KeyValuePair<string, string>>(); groupDictionary = new Dictionary<KeyValuePair<string, string>, string>(); foreach (XmlNode node in this.xDoc.DocumentElement.ChildNodes) { string practoEstablishmentKey = node.ChildNodes.Item(0).InnerText; string groupId = node.ChildNodes.Item(1).InnerText; string localEstablishmentID = node.ChildNodes.Item(2).InnerText; establishmentDictionary.Add(practoEstablishmentKey, new KeyValuePair<string, string>(groupId, localEstablishmentID)); groupDictionary.Add(new KeyValuePair<string, string>(groupId, localEstablishmentID), practoEstablishmentKey); } } public KeyValuePair<string, string> GetGroupDetails(string practoEstablishmentKey) { return establishmentDictionary[practoEstablishmentKey]; } public string GetEstablishmentKey(string groupId, string localEstablishmentID) { return groupDictionary[new KeyValuePair<string, string>(groupId, localEstablishmentID)]; } public List<string> GetAllEstablishmentKeys() { return new List<string>(establishmentDictionary.Keys); } } }
  7. Practo Establishment Mapping xml
  8. <?xml version="1.0" encoding="UTF-8"?> <mappings> <map> <practoEstablishmentKey>b37t91gbi312h3971gui23b913hg1u</practoEstablishmentKey> <groupId>10</groupId> <localEstablishmentID>1201</localEstablishmentID> </map> <map> <practoEstablishmentKey>kuhweb0192u0182hi23bub2iy3b198</practoEstablishmentKey> <groupId>11</groupId> <localEstablishmentID>1202</localEstablishmentID> </map> </mappings>