const fetch = require('node-fetch');
const request = require('request');
const cheerio = require('cheerio')
var url = "https://govforms.gov.il/mw/forms/ChildHealthDeclaration@molsa.gov.il";
let dataUriel = {
"processID": null,
"formData": {
"declarationProperties": {
"childInformation": {
"idNum": "00000000",
"lastName": "XXXXXX",
"firstName": "XXXXXXXX"
},
"parentInformation": {
"idNum": "000000",
"lastName": "XXXXXXx",
"firstName": "XXXXX"
},
"childBirthDate": "xxx/2018",
"daycareManager": "xxxx",
"dayCareCity": {
"dataCode": "xxxx",
"dataText": "xxxxx"
},
"dayCareName": {
"dataCode": "xxxxx",
"dataText": "xxxxxxx"
},
"parentMobile": "xxxxxx",
"parentEmail": "avram.eps@gmail.com",
"parentFirstDeclaration": true,
"parentSecondDeclaration": true,
"parentDeclaration3": true,
"declarationDate": "29/06/2020",
"name": "declarationProperties",
"state": "completed",
"next": "",
"prev": "",
"isClosed": true
},
"containersViewModel": {
"showPrintButton": false,
"currentContainerName": "declarationProperties",
"validatedStatus": true
},
"formInformation": {
"isFormSent": false,
"loadingDate": "29/06/2020",
"firstLoadingDate": "",
"isMobile": false,
"language": "hebrew"
}
},
"language": "he",
"attachments": []
}
function parseRequestId(text) {
let $ = cheerio.load(text)
let json = JSON.parse($('#govFormsScript')[0].children[0].data.split('=')[1])
return json.process.requestID;
}
function getDateString() {
var d = new Date();
return ("0" + d.getDate()).slice(-2) + "/" + ("0" + (d.getMonth() + 1)).slice(-2) + "/" +
d.getFullYear();
}
function sendDeclertion(details) {
request.get(url, function (error, res, body) {
if (!error) {
details.requestID = parseRequestId(body);
details.formData.declarationProperties.declarationDate = getDateString();
details.formData.formInformation.loadingDate = getDateString();
console.log(details.requestID)
fetch("https://govforms.gov.il/MW/Process/Data/", {
"headers": {
"content-type": "application/json",
},
body: JSON.stringify(details),
"method": "POST",
})
.then(res => res.json()) // expecting a json response
.then(json => console.log(json));
}
})
}
sendDeclertion(dataUriel)