Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. <apex:form id="form">
  2.  
  3. <apex:pageBlock title="Appointments Tables" id="TableDoctors">
  4. <apex:pageBlock >
  5. <apex:selectList value="{!selectedname}" size="1" multiselect="false" onChange="updateDoctors(this.value)">
  6. <h1>
  7. Select a doctor name:
  8. </h1>
  9. <apex:selectOptions value="{!selectedDocnamefields}"/>
  10. </apex:selectList>
  11. </apex:pageBlock>
  12.  
  13. <apex:pageBlock >
  14. <apex:commandButton action="{!URLFOR("/apex/DoctorCreate")}" value="Add new doctor"/>
  15. </apex:pageBlock>
  16.  
  17. <apex:pageBlock >
  18. <apex:pageBlockSection title="Working hours" id="TableDoctors">
  19.  
  20. <apex:repeat value="{!Doctors}" var="d" rows="1">
  21. <apex:outputField value="{!d.Doctor__r.Working_Hours_Start__c}"/>
  22. <apex:outputField value="{!d.Doctor__r.Working_Hours_End__c}"/>
  23. </apex:repeat>
  24. </apex:pageBlockSection>
  25. </apex:pageBlock>
  26.  
  27. <apex:pageBlock >
  28. <apex:selectList value="{!selectedPatientname}" size="1" multiselect="false" onChange="updatePatients(this.value)">
  29. <h1>
  30. Select a Patient name:
  31. </h1>
  32. <apex:selectOptions value="{!selectedPatnamefields}" />
  33. </apex:selectList>
  34. </apex:pageBlock>
  35.  
  36. <apex:pageBlock >
  37. <apex:commandButton action="{!URLFOR("/apex/PatientCreate")}" value="Add new patient"/>
  38. </apex:pageBlock>
  39.  
  40. <apex:pageBlock mode="edit">
  41. <apex:pageMessages />
  42. <apex:pageBlockSection id="TableDoctors" >
  43. <apex:inputField value="{!CreateAppointment.Appointment_Date__c}"/>
  44. <apex:inputField value="{!CreateAppointment.Duration_in_minutes__c}"/>
  45. </apex:pageBlockSection>
  46. <apex:pageBlockButtons location="bottom">
  47. <apex:commandButton value="Save" action="{!save}"/>
  48. </apex:pageBlockButtons>
  49. </apex:pageBlock>
  50.  
  51. <apex:pageBlockTable value="{! Doctors }" var="d" columns="5" id="TableDoctors" >
  52.  
  53. <apex:column value="{! d.Doctor__c }" />
  54. <apex:column value="{! d.Doctor__r.Name }"/>
  55. <apex:column value="{! d.Patient__r.Name }"/>
  56. <apex:column value="{! d.Appointment_Date__c }"/>
  57. <apex:column value="{! d.Duration_in_minutes__c }"/>
  58.  
  59. </apex:pageBlockTable>
  60. </apex:pageBlock>
  61. <apex:actionFunction name="updateDoctors" action="{!getDoctors}" rerender="TableDoctors" immediate="false">
  62. <apex:param name="selectedDoc" assignTo="{!selectedname}" value="" />
  63. </apex:actionFunction>
  64. </apex:form>
  65.  
  66. public class AppointmentsListController {
  67.  
  68.  
  69.  
  70. public List<Appointment__c> Doctors {get;set;}
  71. public string selectedname{
  72.  
  73. get{
  74. if(selectedname == null)
  75. selectedname ='Model API';
  76. return selectedname;
  77. }
  78. set;}
  79.  
  80. Public List<Selectoption> getselectedDocnamefields(){
  81. List<Selectoption> Doctornamesel = new List<selectoption>();
  82. Doctornamesel.add(new selectOption('', '- None -'));
  83. for(Appointment__c Doc :[SELECT Id, Doctor__r.Name, Doctor__r.Working_Hours_Start__c, Doctor__r.Working_Hours_End__c, Patient__r.Name, Appointment_Date__c, Duration_in_minutes__c FROM Appointment__c Where Doctor__r.Name!=Null]){
  84. Doctornamesel.add(new selectoption(Doc.Doctor__r.id, Doc.Doctor__r.Name));
  85. }
  86. return Doctornamesel;
  87. }
  88.  
  89. public void getDoctors() {
  90.  
  91. system.debug('SelectedName is: ' + selectedname);
  92. Doctors = [SELECT Doctor__r.Name, Doctor__r.Working_Hours_Start__c, Doctor__r.Working_Hours_End__c, Patient__r.Name, Appointment_Date__c, Duration_in_minutes__c FROM Appointment__c Where Doctor__c =: selectedname ];
  93.  
  94. }
  95.  
  96.  
  97. public List<Appointment__c> Patients {get;set;}
  98. public string selectedPatientname{
  99.  
  100. get{
  101. if(selectedPatientname == null)
  102. selectedPatientname ='Model API';
  103. return selectedPatientname;
  104. }
  105. set;}
  106.  
  107. Public List<Selectoption> getselectedPatnamefields(){
  108. List<Selectoption> Patientnamesel = new List<selectoption>();
  109. Patientnamesel.add(new selectOption('', '- None -'));
  110. for(Appointment__c Pat :[SELECT Id, Patient__r.Name FROM Appointment__c Where Doctor__r.Name!=Null]){
  111. Patientnamesel.add(new selectoption(Pat.Patient__r.id, Pat.Patient__r.Name));
  112. }
  113. return Patientnamesel;
  114. }
  115.  
  116.  
  117.  
  118. public void getPatients() {
  119.  
  120. system.debug('selectedPatientname is: ' + selectedPatientname);
  121. Patients = [SELECT Patient__r.Name FROM Appointment__c Where Patient__c =: selectedPatientname ];
  122.  
  123. }
  124.  
  125.  
  126.  
  127.  
  128. public Appointment__c CreateAppointment { get; private set; }
  129.  
  130. public AppointmentsListController() {
  131. Id id = ApexPages.currentPage().getParameters().get('id');
  132. CreateAppointment = (id == null) ? new Appointment__c() :
  133. [SELECT Doctor__r.Name, Patient__r.Name, Appointment_Date__c, Duration_in_minutes__c FROM Appointment__c WHERE Id = :id and Doctor__c = :selectedname and Patient__c = :selectedPatientname ];
  134. }
  135.  
  136. public PageReference save() {
  137. try {
  138. upsert(CreateAppointment);
  139. } catch(System.DMLException e) {
  140. ApexPages.addMessages(e);
  141. return null;
  142. }
  143. // After successful Save, navigate to the default view page
  144. PageReference redirectSuccess = new ApexPages.StandardController(CreateAppointment).view();
  145. return (redirectSuccess);
  146. }
  147.  
  148.  
  149.  
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement