Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <apex:form id="form">
- <apex:pageBlock title="Appointments Tables" id="TableDoctors">
- <apex:pageBlock >
- <apex:selectList value="{!selectedname}" size="1" multiselect="false" onChange="updateDoctors(this.value)">
- <h1>
- Select a doctor name:
- </h1>
- <apex:selectOptions value="{!selectedDocnamefields}"/>
- </apex:selectList>
- </apex:pageBlock>
- <apex:pageBlock >
- <apex:commandButton action="{!URLFOR("/apex/DoctorCreate")}" value="Add new doctor"/>
- </apex:pageBlock>
- <apex:pageBlock >
- <apex:pageBlockSection title="Working hours" id="TableDoctors">
- <apex:repeat value="{!Doctors}" var="d" rows="1">
- <apex:outputField value="{!d.Doctor__r.Working_Hours_Start__c}"/>
- <apex:outputField value="{!d.Doctor__r.Working_Hours_End__c}"/>
- </apex:repeat>
- </apex:pageBlockSection>
- </apex:pageBlock>
- <apex:pageBlock >
- <apex:selectList value="{!selectedPatientname}" size="1" multiselect="false" onChange="updatePatients(this.value)">
- <h1>
- Select a Patient name:
- </h1>
- <apex:selectOptions value="{!selectedPatnamefields}" />
- </apex:selectList>
- </apex:pageBlock>
- <apex:pageBlock >
- <apex:commandButton action="{!URLFOR("/apex/PatientCreate")}" value="Add new patient"/>
- </apex:pageBlock>
- <apex:pageBlock mode="edit">
- <apex:pageMessages />
- <apex:pageBlockSection id="TableDoctors" >
- <apex:inputField value="{!CreateAppointment.Appointment_Date__c}"/>
- <apex:inputField value="{!CreateAppointment.Duration_in_minutes__c}"/>
- </apex:pageBlockSection>
- <apex:pageBlockButtons location="bottom">
- <apex:commandButton value="Save" action="{!save}"/>
- </apex:pageBlockButtons>
- </apex:pageBlock>
- <apex:pageBlockTable value="{! Doctors }" var="d" columns="5" id="TableDoctors" >
- <apex:column value="{! d.Doctor__c }" />
- <apex:column value="{! d.Doctor__r.Name }"/>
- <apex:column value="{! d.Patient__r.Name }"/>
- <apex:column value="{! d.Appointment_Date__c }"/>
- <apex:column value="{! d.Duration_in_minutes__c }"/>
- </apex:pageBlockTable>
- </apex:pageBlock>
- <apex:actionFunction name="updateDoctors" action="{!getDoctors}" rerender="TableDoctors" immediate="false">
- <apex:param name="selectedDoc" assignTo="{!selectedname}" value="" />
- </apex:actionFunction>
- </apex:form>
- public class AppointmentsListController {
- public List<Appointment__c> Doctors {get;set;}
- public string selectedname{
- get{
- if(selectedname == null)
- selectedname ='Model API';
- return selectedname;
- }
- set;}
- Public List<Selectoption> getselectedDocnamefields(){
- List<Selectoption> Doctornamesel = new List<selectoption>();
- Doctornamesel.add(new selectOption('', '- None -'));
- 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]){
- Doctornamesel.add(new selectoption(Doc.Doctor__r.id, Doc.Doctor__r.Name));
- }
- return Doctornamesel;
- }
- public void getDoctors() {
- system.debug('SelectedName is: ' + selectedname);
- 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 ];
- }
- public List<Appointment__c> Patients {get;set;}
- public string selectedPatientname{
- get{
- if(selectedPatientname == null)
- selectedPatientname ='Model API';
- return selectedPatientname;
- }
- set;}
- Public List<Selectoption> getselectedPatnamefields(){
- List<Selectoption> Patientnamesel = new List<selectoption>();
- Patientnamesel.add(new selectOption('', '- None -'));
- for(Appointment__c Pat :[SELECT Id, Patient__r.Name FROM Appointment__c Where Doctor__r.Name!=Null]){
- Patientnamesel.add(new selectoption(Pat.Patient__r.id, Pat.Patient__r.Name));
- }
- return Patientnamesel;
- }
- public void getPatients() {
- system.debug('selectedPatientname is: ' + selectedPatientname);
- Patients = [SELECT Patient__r.Name FROM Appointment__c Where Patient__c =: selectedPatientname ];
- }
- public Appointment__c CreateAppointment { get; private set; }
- public AppointmentsListController() {
- Id id = ApexPages.currentPage().getParameters().get('id');
- CreateAppointment = (id == null) ? new Appointment__c() :
- [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 ];
- }
- public PageReference save() {
- try {
- upsert(CreateAppointment);
- } catch(System.DMLException e) {
- ApexPages.addMessages(e);
- return null;
- }
- // After successful Save, navigate to the default view page
- PageReference redirectSuccess = new ApexPages.StandardController(CreateAppointment).view();
- return (redirectSuccess);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement