// Heart routing

// HG1         |   HG2         |   HG3         |   HG4         |   PM
//             |               |   H14 Y N     |   H15 Y N     |   H7  date
// H1  Y N     |   H1  Y N     |   H1  Y N     |   H1  Y N     |
// H2  0 1 2   |   H2  0 1 2   |   H2  0 1 2   |   H2  0 1 2   |   H2  0 1 2
// H3  Y N     |   H3  Y N     |   H3  Y N     |   H3  Y N     |   H3  Y N
// H4  date    |   H4  date    |   H4  date    |   H4  date    |   H4  date
// H5  date    |   H5  date    |   H5  date    |   H5  date    |   H5  date
// H6  Y N     |   H6  Y N     |   H6  Y N     |               |
// H7  date    |   H7  date    |   H7  date    |               |
// H8  Y N     |   H8  Y N     |   H8  Y N     |               |   H8  Y N
// H9  Y N     |   H9  Y N     |   H9  Y N     |               |   H9  Y N
// H10 Y N     |   H10 Y N     |   H10 Y N     |               |
// H11 Y N     |   H11 Y N     |   H11 Y N     |               |   H11 Y N
// H12 pmdec   |   H12 pmdec   |   H12 pmdec   |               |   H12 pmdec
// H13 cons    |   H13 cons    |   H13 cons    |   H13 cons    |   H13 cons

// Shorthand go functions
function goH1() { go('/heart/gen/suffering-symptoms'); }
function goH2() { go('/heart/gen/episodes-caused-in-last-12-months'); }
function goH3() { go('/heart/gen/episode-within-last-6-months'); }
function goH4() { go('/heart/gen/episode-most-recent'); }
function goH5() { go('/heart/gen/first-episode-in-last-12-months'); }
function goH6() { go('/heart/gen/have-pacemaker'); }
function goH7() { go('/heart/gen/pacemaker-date'); }
function goH8() { go('/heart/gen/pacemaker-reason'); }
function goH9() { go('/heart/gen/episodes-controlled'); }
function goH10() { go('/heart/gen/episodes-treated'); }
function goH11() { go('/heart/gen/pacemaker-fitted-after-episode'); }
function goPMDec() { go('/heart/gen/agree-to-conditions'); }
// function goH13() { go('/common/consultant-details'); }
function goH14() { go('/heart/gen/episode-within-last-12-months'); }
function goH15() { go('/heart/gen/cardioverter-implant'); }

var H1, H2, H3, H8;
try { H1 = responses["H"]["1"].response; } catch (err) {}
try { H2 = responses["H"]["2"].response; } catch (err) {}
try { H3 = responses["H"]["3"].response; } catch (err) {}
try { H8 = responses["H"]["8"].response; } catch (err) {}



// H1 routing
function goYesH1() {
    if (getCurrentConditionType() === "1") {
        goH2();
    } else if (getCurrentConditionType() === "2") {
        goH2();
    } else if (getCurrentConditionType() === "3") {
        goH2();
    } else if (getCurrentConditionType() === "4") {
        goH2();
    }
}
function goNoH1() {
    if (getCurrentConditionType() === "1") {
        goH2();
    } else if (getCurrentConditionType() === "2") {
        goH2();
    } else if (getCurrentConditionType() === "3") {
        goH2();
    } else if (getCurrentConditionType() === "4") {
        goH2();
    }
}

// H2 routing
function go0H2() {
    if (getCurrentConditionType() === "1") {
        goH6();
    } else if (getCurrentConditionType() === "2") {
        goH6();
    } else if (getCurrentConditionType() === "3") {
        
    } else if (getCurrentConditionType() === "4") {
        if (H1 === "N") {
            goConsultantDetails();
        } else {
            goSummary();
        }
    }
}
function go1H2() {
    if (getCurrentConditionType() === "1") {
        goH3();
    } else if (getCurrentConditionType() === "2") {
        goH3();
    } else if (getCurrentConditionType() === "3") {
        goH3();
    } else if (getCurrentConditionType() === "4") {
        goH3();
    }
}
function go2H2() {
    if (getCurrentConditionType() === "1") {
        goH4();
    } else if (getCurrentConditionType() === "2") {
        goH4();
    } else if (getCurrentConditionType() === "3") {
        goH4();
    } else if (getCurrentConditionType() === "4") {
        goH4();
    }
}

// H3 routing
function goYesH3() {
    if (getCurrentConditionType() === "1") {
        goH4();
    } else if (getCurrentConditionType() === "2") {
        goH4();
    } else if (getCurrentConditionType() === "3") {
        goH4();
    } else if (getCurrentConditionType() === "4") {
        goH4();
    }
}
function goNoH3() {
    if (getCurrentConditionType() === "1") {
        if (H1 === "N") {
            goH6();
        } else {
            goH4();
        }
    } else if (getCurrentConditionType() === "2") {
        if (H3 === "N") {
            goH6();
        } else {
            goH4();
        }
    } else if (getCurrentConditionType() === "3") {
        if (H1 === "N") {
            goH6();
        } else {
            goH4();
        }
    } else if (getCurrentConditionType() === "4") {
        if (H1 === "N") {
            goConsultantDetails();
        } else {
            goH4();
        }
    }
}

// H4 routing
function goNextH4() {
    if (getCurrentConditionType() === "1") {
        if (H2 === "2") {
            goH5();
        } else {
            goH6();
        }
    } else if (getCurrentConditionType() === "2") {
        if (H2 === "2") {
            goH5();
        } else {
            goH6();
        }
    } else if (getCurrentConditionType() === "3") {
        if (H2 === "2") {
            goH5();
        } else {
            goH6();
        }
    } else if (getCurrentConditionType() === "4") {
        if (H2 === "2") {
            goH5();
        } else {
            goSummary();
        }
    }
}

// H5 routing
function goNextH5() {
    if (getCurrentConditionType() === "1") {
        goH6();
    } else if (getCurrentConditionType() === "2") {
        goH6();
    } else if (getCurrentConditionType() === "3") {
        goH6();
    } else if (getCurrentConditionType() === "4") {
        goSummary();
    }
}

// H6 routing
function goYesH6() {
    if (getCurrentConditionType() === "1") {
        goH7();
    } else if (getCurrentConditionType() === "2") {
        goH7();
    } else if (getCurrentConditionType() === "3") {
        goH7();
    } else if (getCurrentConditionType() === "4") {
        
    }
}
function goNoH6() {
    if (getCurrentConditionType() === "1") {
        if ((H1 === "Y") && (H2 === "0")) {
            goSummary(); 
        } else if ((H1 === "N") && (H2 === "0")) {
            goConsultantDetails();
        } else {
            goH10();
        }
    } else if (getCurrentConditionType() === "2") {
        if (H2 === "0") {
            goSummary();
        } else {
            goH10();
        }
    } else if (getCurrentConditionType() === "3") {
        goH10();
    } else if (getCurrentConditionType() === "4") {
        
    }
}

// H7 routing
function goNextH7() {
    if (getCurrentConditionType() === "1") {
        goH8();
    } else if (getCurrentConditionType() === "2") {
        goH8();
    } else if (getCurrentConditionType() === "3") {
        goH8();
    } else if (getCurrentConditionType() === "4") {
        
    }
}

// H8 routing
function goYesH8() {
    if (getCurrentConditionType() === "1") {
        goH9();
    } else if (getCurrentConditionType() === "2") {
        goH9();
    } else if (getCurrentConditionType() === "3") {
        goH9();
    } else if (getCurrentConditionType() === "4") {
        
    }
}
function goNoH8() {
    if (getCurrentConditionType() === "1") {
        if (((H1 === "N") && (H2 === "0")) ||
          ((H1 === "N") && (H2 === "1") && (H3 === "Y")) ||
          ((H1 === "N") && (H2 === "2"))
        ) {
            goH9();
        } else {
            goPMDec();
        }
    } else if (getCurrentConditionType() === "2") {
        if (
            (H1 === "N") && (H2 === "2") ||
            (H1 === "N") && (H2 === "1") && (H3 === "Y")
        ) {
            goH9();
        } else {
            goPMDec();
        }
    } else if (getCurrentConditionType() === "3") {
        if ((H1 === "N") && (H2 === "2")) {
            goH9();
        } else {
            goPMDec();
        }
    } else if (getCurrentConditionType() === "4") {
        
    }
}

// H9 routing
function goYesH9() {
    if (getCurrentConditionType() === "1") {
        if (((H1 === "N") && (H2 === "1")) ||
          ((H1 === "N") && (H2 === "2"))
        ) {
            goH11();
        } else {
            goPMDec();
        }
    } else if (getCurrentConditionType() === "2") {
        if (H1 === "Y") {
            goPMDec();
        } else if (H1 === "N") {
            if (H2 === "0") {
                goPMDec();
            } else {
                goH11();
            }
        }
    } else if (getCurrentConditionType() === "3") {
        if (H1 === "Y") {
            goPMDec();
        } else {
            goH11();
        }
    } else if (getCurrentConditionType() === "4") {
        
    }
}
function goNoH9() {
    if (getCurrentConditionType() === "1") {
        goPMDec();
    } else if (getCurrentConditionType() === "2") {
        goPMDec();
    } else if (getCurrentConditionType() === "3") {
        goPMDec();
    } else if (getCurrentConditionType() === "4") {
        
    }
}

// H10 routing
function goYesH10() {
    if (getCurrentConditionType() === "1") {
        if (H1 === "Y") {
            goSummary(); 
        } else {
            goConsultantDetails();
        }
    } else if (getCurrentConditionType() === "2") {
        if (H1 === "N") {
            goConsultantDetails();
        } else {
            goSummary(); 
        }
    } else if (getCurrentConditionType() === "3") {
        if (H1 === "N") {
            goConsultantDetails();
        } else {
            goSummary(); 
        }
    } else if (getCurrentConditionType() === "4") {
  
    }
}
function goNoH10() {
    if (getCurrentConditionType() === "1") {
        goSummary();
    } else if (getCurrentConditionType() === "2") {
        goSummary();
    } else if (getCurrentConditionType() === "3") {
        goSummary();
    } else if (getCurrentConditionType() === "4") {
        
    }
}

// H11 routing
function goYesH11() {
    if (getCurrentConditionType() === "1") {
        goPMDec();
    } else if (getCurrentConditionType() === "2") {
        goPMDec();
    } else if (getCurrentConditionType() === "3") {
        goPMDec();
    } else if (getCurrentConditionType() === "4") {
        
    }
}
function goNoH11() {
    if (getCurrentConditionType() === "1") {
        goPMDec();
    } else if (getCurrentConditionType() === "2") {
        goPMDec();
    } else if (getCurrentConditionType() === "3") {
        goPMDec();
    } else if (getCurrentConditionType() === "4") {
        
    }
}

// H12 routing
function goYesH12() {
    if (getCurrentConditionType() === "1") {
        if ((H2 === "0")) {
            if ((H1 === "N") && (H8 === "N") && (H9 === "Y")) {
                goConsultantDetails();
            } else {
                goSummary();
            }
        } else if (H2 === "1") {
            if (H3 === "Y") {
                if (H9 === "Y") {
                    if (H11 === "N") {
                        goConsultantDetails();
                    } else {
                        goSummary();
                    }
                } else if (H9 === "N") {
                    goSummary();
                }
            } else if (H3 === "N") {
                if (H8 === "Y") {
                    if (H11 === "N") {
                        goConsultantDetails();
                    } else {
                        goSummary();
                    }
                } else if (H8 === "N") {
                    goConsultantDetails();
                }
            }
        } else if (H2 === "2") {
            if ((H9 === "Y") && (H11 === "N")) {
                goConsultantDetails();
            } else {
                goSummary();
            }
        }
    } else if (getCurrentConditionType() === "2") {
        if (H1 === "N") {
            if (H2 === "0") {
                if (H8 ==="N") {
                    goConsultantDetails();
                } else {
                    goSummary();
                }
            } else if (H2 === "1") {
                if (H3 === "Y") {
                    if (H9 === "Y") {
                        if (H11 === "N") {
                            goConsultantDetails();
                        } else {
                            goSummary();
                        }
                    } else if (H9 === "N") {
                        goSummary();
                    }
                }  else if (H3 === "N") {
                    if (H8 === "Y") {
                        if (H11 === "N") {
                            goConsultantDetails();
                        } else {
                            goSummary();
                        }
                    } else if (H8 === "N") {
                        goConsultantDetails();
                    }
                }
            } else if (H2 === "2") {
                if ((H9 === "Y") && (H11 === "N")) {
                    goConsultantDetails();
                } else {
                    goSummary();
                }
            }
        } else {
            goSummary();
        }
    } else if (getCurrentConditionType() === "3") {
        if (H1 === "N") {
            if (H8 === "Y") {
                if (H11 === "N") {
                    goConsultantDetails();
                } else {
                    goSummary();
                }
            } else if (H8 === "N") {
                goConsultantDetails();
            }
        } else {
            goSummary();
        }
    } else if (getCurrentConditionType() === "4") {
        
    }
}
function goNoH12() {
    if (getCurrentConditionType() === "1") {
        goSummary();
    } else if (getCurrentConditionType() === "2") {
        goSummary();
    } else if (getCurrentConditionType() === "3") {
        goSummary();
    } else if (getCurrentConditionType() === "4") {
        
    }
}
