Web Application Code
A.3 InsertNewPatient Page
A.3.1 HTML
The following HTML code (Listing A.10) defines the layout of InsertNewPatient page.
1 <p style=" font-size:140 %">Inserire i dati del paziente:</p>
2 <p style=" font-size:140 %" align=" center " >ANAGRAFICA</p>
3
4 < form style=" display:block;border:groove ">
5 < fieldset style=" display:block;margin:1 %">
6 < label >
7 < input class=" mdl-textfield__input " style=" display:inline;
width:50 %; text-transform:uppercase " type=" text " id="
inName " placeholder=" Nome *" />
8 & nbsp; & nbsp; & nbsp;
9 < input class=" mdl-textfield__input " style=" display:inline;
width:47 %; text-transform:uppercase " type=" text " id="
inSurname " placeholder=" Cognome *" >
10 </ label >
11 </ fieldset >
12 </ form >< form style=" display:block;border:groove ">
13 < fieldset style=" display:block;margin:1 %">
14 < label >
15 < input class=" mdl-textfield__input " style="
display:inline;width:100 %" type=" email " id=" inEmail "
placeholder=" Email *" />
16 </ label >
17 </ fieldset >
18 </ form >< form style=" display:block;border:groove ">
19 < fieldset style=" display:block;margin:1 %">
20 < label >
21 < input class=" mdl-textfield__input " style="
display:inline;width:100 %; text-transform:uppercase " type=
" text " maxlength="16" id=" inCode " placeholder=" Codice Fiscale *" />
22 </ label >
23 </ fieldset >
24 </ form >< form style=" display:block;border:groove ">
25 < fieldset style=" display:block;margin:1 %">
26 < span style=" display: inline-block; width: 30% ">DATA DI NASCITA *</ span >
27 & nbsp; & nbsp; & nbsp;
28 < label >
29 < input class=" mdl-textfield__input " style="
display:inline;width:auto; " type=" date " data-date-format=
"DD MM YYYY " id=" inBirthday " placeholder=" DD-MM-YYYY " />
30 </ label >
31 </ fieldset >
32 </ form >< form style=" display:block;border:groove ">
33 < fieldset style=" display:block;margin:1 %">
34 < label >
35 < input class=" mdl-textfield__input " style="
display:inline;width:100 %; text-transform:uppercase " type=
" text " id=" inBirthplace " placeholder=" Luogo di Nascita " /
>
36 </ label >
37 </ fieldset >
38 </ form >< form style=" display:block;border:groove ">
39 < fieldset style=" display:block;margin:1 %">
40 < span style=" display: inline-block; width: 30% ">RESIDENZA</
span >
41 & nbsp; & nbsp; & nbsp;
42 < label >
43 < input class=" mdl-textfield__input " style="
display:inline;width:30 %; text-transform:uppercase " type="
text " id=" inResRoad " placeholder=" Via " />
44 & nbsp;
45 < input class=" mdl-textfield__input " style="
display:inline;width:30 %; text-transform:uppercase " type="
text " id=" inResCity " placeholder=" Citt & agrave " />
46 </ label >
47 </ fieldset >
48 </ form >< form style=" display:block;border:groove ">
49 < fieldset style=" display:block;margin:1 %">
50 < label >
51 < input class=" mdl-textfield__input " style="
display:inline;width:100 %; text-transform:uppercase " type=
" text " id=" inTelephone " placeholder=" Telefono " />
52 </ label >
53 </ fieldset >
54 </ form >< form style=" display:block;border:groove ">
55 < fieldset style=" display:block;margin:1 %">
56 < span style=" display:inline-block;width:30 %">SESSO</ span >
57 & nbsp; & nbsp; & nbsp;
58 < label >
59 < input type=" radio " name=" gender " id=" gender " value=" Maschio
">Uomo 60 </ label >
61 & nbsp; & nbsp;
62 < label >
63 < input type=" radio " name=" gender " id=" gender " value=" Femmina
">Donna 64 </ label >
65 </ fieldset >
66 </ form >
67 <p>(I parametri contrassegnati da * sono obbligatori )</p>
68
69 <br/><br/>
70 < button class=" mdl-button mdl-js-button mdl-button--raised "
type=" submit " id=" register " name=" register ">Registra</ button
>
71 & nbsp; & nbsp; & nbsp;
72 < button class=" mdl-button mdl-js-button mdl-button--raised " id=
" cancel " name=" cancel " >Annulla</ button >
Listing A.10: InsertNewPatient Page Elements
A.3.2 Js
To generate a new user, it is needed to define a dummy password. GeneratePass function, defined by code in Listing A.11, is used to do this.
1 function generatePass( ){
2 var chars = " 0123456789 abcdefghijklmnopqrstuvwxyz -ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
3 var pass = "";
4 for (var i = 0; i < 7; i++) {
5 pass += chars [ Math.floor(Math.random() * chars.length)];
6 }
7 return pass;
8 };
Listing A.11: GeneratePass Function
CheckDatafunction (Listing A.12) is instead devoted to verify that all manda-tory data have been inserted by the physician during registration. If the check is passed, handleSignUp function is called to perform sign up (Listing A.13).
1 function checkData( ) {
2 var ok = true;
3 var id = null;
4 var email = inEmail.val ue; 5 var name = inName.val ue;
6 var surname = inSurname.val ue; 7 var birthday = inBirthday.val ue; 8 var code = inCode.val ue;
9 if (! birthday ){
10 ok = false;
11 id = " pBirthday "; 12 }
13 if (! code ){
14 ok = false;
15 id = " pCode "; 16 }
17 if (! email ){
18 ok = false;
19 id = " pEmail "; 20 }
21 if (! surname ){
22 ok = false;
23 id = " pSurname ";
24 }
25 if (! name ){
26 ok = false;
27 id = " pName "; 28 }
29 if (!ok) {
30 var errorMessage = " Dati Mancanti !";
31 alert(errorMessage );
32 console.log(errorMessage );
33 document.getElementById(id ).focus();
34 } else {
35 handleSignUp( );
36 } 37 }
Listing A.12: CheckData Function
1 function handleSignUp( ){
2 var email = inEmail.val ue;
3 var name = inName.val ue.toUpperCase();
4 var surname = inSurname.val ue.toUpperCase();
5 var birthday = inBirthday.val ue;
6 var code = inCode.val ue.toUpperCase();
7 var birthplace = inBirthplace.val ue.toUpperCase();
8 var resRoad = inResRoad.val ue.toUpperCase();
9 var resCity = inResCity.val ue.toUpperCase();
10 var telephone = inTelephone.val ue;
11 var inGender = document.querySelector(" input [id='gender ']:
checked ");
12 var gender = "";
13 var pass = generatePass( );
14 var secondaryAuth = firebase
15 .initializeApp(config , " Secondary ");
16 if (inGender ){
17 gender = inGender.val ue; 18 }
19 secondaryAuth.auth().createUserWithEmailAndPassword(email , pass )
20 .then(function() {
21 var newUser = secondaryAuth.auth().currentUser; 22 newUser.updateProfile( { email: email });
23 patient = newUser.uid;
24 }).then(function() {
25 firebase.auth().sendPasswordResetEmail(email ).then(function() {
26 alert(" Email inviata al paziente. ");
27 }).then(function(){
28 var postData = {
29 DateOfBirth: birthday , 30 Email: email ,
31 FiscalCode: code , 32 Name: name ,
33 Surname: surname , 34 Gender: gender ,
35 Birthplace: birthplace , 36 ResidencyRoad: resRoad ,
37 ResidencyCity: resCity , 38 Telephone: telephone
39 };
40 var managementData = { 41 FiscalCode: code ,
42 Name: name + " " + surname
43 };
44 firebase.database().ref(" patients /" + patient + "/
PersonalData ").set(postData );
45 firebase.database().ref(" patientsUid /" + patient ).set (managementData );
46 }).then(function() {
47 console.log(" Paziente registrato ");
48 secondaryAuth.auth().signOut() 49 }).catch(function(error ){
50 var errorMessage = error.message;
51 alert(errorMessage );
52 console.log(error );
53 }).then(function(){
54 secondaryAuth.delete();
55 }).then(function(){
56 var firstVisitMessage = " Paziente registrato con successo. \n
\ nProseguire con la prima visita ?";
57 if (window.confirm(firstVisitMessage )){
58 window.location .replace(" newVisit.html " + "?" + " patient="
+ patient );
59 } else {
60 window.location .replace(" home.html ");
61 }
62 });
63 });
64 }
Listing A.13: HandleSignUp Function