     "_pageLabel=as_login_page"
 
     reimbursementUrl = "https://assure.ameli.fr/PortailAS/appmanager/" + \
-    "PortailAS/assure?_nfpb=true&_pageLabel=as_dernier_paiement_page"
+    "PortailAS/assure?_nfpb=true&_pageLabel=as_paiements_page"
+
+    refererUrl = "https://assure.ameli.fr/PortailAS/appmanager/" + \
+    "PortailAS/assure?_nfpb=true&_pageLabel=as_login_page"
 
     form =
         "connexioncompte_2numSecuriteSociale": requiredFields.login


    next()

customLinkBankOperation = (requiredFields, healthBills, data, next) ->
    identifier = 'C.P.A.M.'
    if requiredFields.bank_identifier isnt ""
        identifier = requiredFields.bank_identifier

    linkBankOperation(
        log: log


    $ = cheerio.load data.html

    # Get the start and end date to generate the bill's url
    startDate = $('#paiements_1dateDebut').attr('value')
    endDate = $('#paiements_1dateFin').attr('value')

    baseUrl = "https://assure.ameli.fr/PortailAS/paiements.do?actionEvt="

    billUrl = baseUrl + "afficherPaiementsComplementaires&DateDebut="
    billUrl += (startDate + "&DateFin=" + endDate)
    billUrl += "&Beneficiaire=tout_selectionner&afficherReleves=false&" + \
    "afficherIJ=false&afficherInva=false&afficherRentes=false&afficherRS=" + \
    "false&indexPaiement=&idNotif="

    billOptions =
        jar: true
        strictSSL: false
        url: billUrl

    request billOptions, (err, res, body) ->
        if err
            log.error err
            return next 'request error'
        else
            $ = cheerio.load body
            i = 0

            # Each bloc represents a month that includes 0 to n reimbursement
            $('.blocParMois').each ->

                $('[id^=lignePaiement' + i++ + ']').each ->

                    amount = $($(this).find('.col-montant').get(0)).text()
                    amount = amount.replace(' €', '').replace(',','.')
                    amount = parseFloat amount

                    month = $($(this).find('.col-date .mois').get(0)).text()
                    day = $($(this).find('.col-date .jour').get(0)).text()
                    date = day + ' ' + month
                    moment.locale 'fr'
                    date = moment(date, 'Do MMMM YYYY')

                    label = $($(this).find('.col-label').get(0)).text()

                    # Retrieve and extract the infos needed to generate the pdf
                    attrInfos = $(this).attr('onclick')
                    tokens = attrInfos.split("'")

                    idPaiement = tokens[1]
                    naturePaiement = tokens[3]
                    indexGroupe = tokens[5]
                    indexPaiement = tokens[7]

                    detailsUrl =  baseUrl + "chargerDetailPaiements&"
                    detailsUrl += "idPaiement=" + idPaiement  + "&"
                    detailsUrl += "naturePaiement=" + naturePaiement + "&"
                    detailsUrl += "indexGroupe=" + indexGroupe + "&"
                    detailsUrl += "indexPaiement=" + indexPaiement

                    lineId = indexGroupe + indexPaiement

                    bill =
                        amount: amount
                        type: 'health'
                        subtype: label
                        date: date
                        vendor: 'Ameli'
                        lineId: lineId
                        detailsUrl: detailsUrl

                    healthBills.fetched.push bill if bill.amount?

            async.each healthBills.fetched, getPdf, (err) ->
                next err


getPdf = (bill, callback) ->

    # Request the generated url to get the detailed pdf
    detailsOptions =
        jar: true
        strictSSL: false
        url: bill.detailsUrl

    request detailsOptions, (err, res, body) ->
        if err
            log.error err
            return callback 'request error'
        else
            $ = cheerio.load body

            pdfUrl = $('[id=liendowndecompte' + bill.lineId + ']').attr('href')
            if pdfUrl
                pdfUrl = "https://assure.ameli.fr" + pdfUrl
                bill.pdfurl = pdfUrl
                callback null


buildNotification = (requiredFields, healthBills, data, next) ->
