Skip to content

Commit

Permalink
add button Detail pacienta on zadanka page Zadanky Covid-19
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Drahnik <[email protected]>
  • Loading branch information
ldrahnik committed Sep 12, 2021
1 parent 84300f3 commit 4cb9770
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 18 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ Osobní informace pacientů podmíněné přihlášením do modulu [Pacienti COV

![Preview](preview/tlacitko_stahnout_certifikat.PNG)

- Přidává tlačítko **Detail pacienta** na stránku Overovani

![Preview](preview/tlacitko_detail_pacienta_zadanky_covid_19.PNG)

## Pacienti COVID-19

- Přidává tlačítko **Detail pacienta** na detail žádanky

![Preview](preview/tlaciko_detail_pacienta.PNG)
![Preview](preview/tlacitko_detail_pacienta.PNG)

- Přidává tlačítko **Vyhledat moje žádanky** na detail pacienta do sekce **Žádanky a testy**

Expand Down
60 changes: 60 additions & 0 deletions background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,61 @@ function loadOckoUzisPatientInfo(zadanka, callback) {
xhr.send(urlParams.toString());
}

function getRegistrLoginCookieName() {
return "MyUniqueKey";
}

function getRegistrDomain() {
return "eregpublicsecure.ksrzis.cz";
}

function getRegistrUrl() {
return "https://" + getRegistrDomain();
}

function getRegistrCUDOvereniCisloZadankyUrl(kodOsoby, heslo, cisloZadanky) {
var urlParams = new URLSearchParams();

urlParams.set("PracovnikKodOsoby", kodOsoby);
urlParams.set("heslo", heslo);
urlParams.set("Cislo", cisloZadanky);

return getRegistrUrl() + "/Registr/CUD/Overeni/Json" + "?" + urlParams.toString();
}

function getZadanka(cisloZadanky, callback) {
chrome.cookies.get({
url: getRegistrUrl(),
name: getRegistrLoginCookieName()
},
function(cookie) {

if(!cookie) {
return;
}

var cookieParams = new URLSearchParams(cookie.value);

var kodOsoby = cookieParams.get("kodOsoby");
var heslo = cookieParams.get("heslo");

var url = getRegistrCUDOvereniCisloZadankyUrl(kodOsoby, heslo, cisloZadanky);

var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type","application/json; charset=UTF-8");
xhr.onreadystatechange = function() {
if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {

var data = JSON.parse(xhr.responseText);

callback(data);
}
};
xhr.send();
});
}

chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.text === 'OckoUzisPatientInfo') {
loadOckoUzisPatientInfo(msg.data, Credentials => {
Expand All @@ -135,5 +190,10 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
sendResponse(result);
});
return true;
} else if(msg.text === 'GetZadankaData' && msg.data.Cislo) {
getZadanka(msg.data.Cislo, function(result) {
sendResponse(result);
});
return true;
}
});
81 changes: 65 additions & 16 deletions content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ const getCertifikatElementId = "link_registr_cud_overeni_getcertifikat_cislo_" +
var getCertifikatLinkElement = document.getElementById(getCertifikatElementId);

if(
!getCertifikatElement &&
!getCertifikatLinkElement &&
CisloElement &&
CisloElement.value
) {

var getCertifikatLinkElement = document.createElement("a");
getCertifikatLinkElement = document.createElement("a");

getCertifikatLinkElement.setAttribute("class", "button-action ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only valid");
getCertifikatLinkElement.setAttribute("id", getCertifikatElementId);
Expand All @@ -349,6 +349,53 @@ if(
document.querySelector("div.actions").appendChild(getCertifikatLinkElement);
}

function vyhledaniPacienta(cisloZadanky) {

chrome.runtime.sendMessage({
"text": "GetZadankaData",
"data": {
"Cislo": cisloZadanky
}
}, function (data) {
if(data) {
var form = createVyhledaniPacientaForm(
data.TestovanyJmeno,
data.TestovanyPrijmeni,
data.TestovanyDatumNarozeniText,
data.TestovanyNarodnostKod,
data.TestovanyCisloPojistence,
true
);

actionsDiv.appendChild(form);
form.submit();
}
});
}

const detailPacientaButtonElementId = "detail-pacienta-button";
var detailPacientaButtonElement = document.getElementById(detailPacientaButtonElementId);

if(
!detailPacientaButtonElement &&
CisloElement &&
CisloElement.value
) {
var detailPacientaButtonElement = document.createElement("button");
detailPacientaButtonElement.type = "button";
detailPacientaButtonElement.id = detailPacientaButtonElementId;
detailPacientaButtonElement.innerText = "Detail pacienta";
detailPacientaButtonElement.setAttribute("class", "button-action ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only valid")

detailPacientaButtonElement.addEventListener('click', function() {

vyhledaniPacienta(CisloElement.value);

}, false);

document.querySelector("div.actions").appendChild(detailPacientaButtonElement);
}


var actionsDiv = document.querySelector(".actions");

Expand All @@ -359,16 +406,17 @@ var CisloPojistenceLabel = document.querySelector('label[for="Zadanka_TestovanyC
var DatumNarozeniLabel = document.querySelector('label[for="Zadanka_TestovanyDatumNarozeni"]');
var Narodnost = document.getElementById("TestovanyNarodnost");

function createVyhledaniPacientaForm(Jmeno, Prijmeni, DatumNarozeni, StatniPrislusnost, CisloPojistence) {
const detailPacientaId = "detail-pacienta";
var detailPacienta = document.getElementById(detailPacientaId);
if(detailPacienta) {
function createVyhledaniPacientaForm(Jmeno, Prijmeni, DatumNarozeni, StatniPrislusnost, CisloPojistence, withoutSubmitButton) {
const detailPacientaFormId = "detail-pacienta-form";
var form = document.getElementById(detailPacientaFormId);
if(form) {
return;
}

var form = document.createElement("form");
form = document.createElement("form");
form.action = getRegistrCUDVyhledaniPacientaUrl();
form.method = "POST";
form.id = detailPacientaFormId;
form.target = "_blank";


Expand Down Expand Up @@ -416,14 +464,15 @@ function createVyhledaniPacientaForm(Jmeno, Prijmeni, DatumNarozeni, StatniPrisl
form.appendChild(inputDatumNarozeni);
}

var submit = document.createElement("button");
submit.name = "_submit";
submit.type = "submit";
submit.setAttribute("id", detailPacientaId)
submit.setAttribute("class", "button-action ui-button ui-corner-all ui-widget")
submit.value = "None";
submit.innerHTML = "Detail pacienta";
form.appendChild(submit);
if(!withoutSubmitButton) {
var submit = document.createElement("button");
submit.name = "_submit";
submit.type = isSubmitHidden ? "submit" : "hidden";
submit.setAttribute("class", "button-action ui-button ui-corner-all ui-widget")
submit.value = "None";
submit.innerHTML = "Detail pacienta";
form.appendChild(submit);
}

return form;
}
Expand Down Expand Up @@ -470,7 +519,7 @@ if(

var urlParams = getRegistrCUDZadankyMojeZadankyUrlParams(Jmeno, Prijmeni, CisloPojistence);
var url = getRegistrCUDZadankyMojeZadankyUrl() + "?" + urlParams.toString();

vyhledatMojeZadankyLinkElement = document.createElement("a");
vyhledatMojeZadankyLinkElement.setAttribute("class", "button-action ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only valid");
vyhledatMojeZadankyLinkElement.setAttribute("id", vyhledatMojeZadankyLinkElementId);
Expand Down
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}],
"permissions": [
"*://*.ksrzis.cz/*",
"tabs"
"tabs",
"cookies"
]
}
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4cb9770

Please sign in to comment.