Skip to content

Commit b4a11a8

Browse files
committed
partial need to parse values
1 parent 8f79c10 commit b4a11a8

5 files changed

Lines changed: 62 additions & 15 deletions

File tree

common-data-defs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ const formContent = [
4545
label: 'Nationality',
4646
dataFieldKey: 'nationality',
4747
},
48+
{
49+
streamId: 'family-children',
50+
eventType: 'count/generic',
51+
type: 'number',
52+
label: 'Nb of children',
53+
dataFieldKey: 'children-count',
54+
},
55+
{
56+
streamId: 'fertility-miscarriages',
57+
eventType: 'count/generic',
58+
type: 'number',
59+
label: 'Nb of miscarriages',
60+
dataFieldKey: 'miscarriages-count',
61+
},
62+
{
63+
streamId: 'fertility-cycles-charted-extimation',
64+
eventType: 'count/generic',
65+
type: 'number',
66+
label: 'Nb of charted cycles',
67+
dataFieldKey: 'charted-cycles-count',
68+
}
4869
];
4970

5071
const dataDefs = {

dr-controler.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,27 @@ const rowItems = ['name', 'surname', 'nationality'];
2828
*/
2929
async function setPatientList() {
3030
const table = document.getElementById('patients-table');
31+
const fields = drLib.getFields();
32+
// --- headers
33+
const headerRow = table.insertRow(-1);
34+
const headerUserCell = document.createElement("TH");
35+
headerUserCell.innerHTML = 'Username';
36+
headerRow.appendChild(headerUserCell);
37+
for (const field of fields) {
38+
const headerCell = document.createElement("TH");
39+
headerCell.innerHTML = field.label;
40+
headerRow.appendChild(headerCell);
41+
}
42+
43+
// --- patients
3144
const patients = await drLib.getPatientsList();
3245
for (const patient of Object.values(patients)) {
3346
const row = table.insertRow(-1);
3447
const cellUsername = row.insertCell(-1);
3548
cellUsername.innerHTML = patient.username;
36-
for (const field of rowItems) {
37-
row.insertCell(-1).innerHTML = patient.formData[field]?.value || '';
49+
for (const field of fields) {
50+
console.log('## field', field);
51+
row.insertCell(-1).innerHTML = patient.formData[field.dataFieldKey]?.value || '';
3852
}
3953
}
4054
}

dr-lib.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const drLib = {
44
showLoginButton,
55
getSharingToken,
66
getPatientsList,
7+
getFields
78
}
89

910
function showLoginButton (loginSpanId, stateChangeCallBack) {
@@ -80,8 +81,15 @@ async function getPatientsList () {
8081
return patients;
8182
}
8283

84+
/**
85+
* get the list of rows for the table
86+
*/
87+
function getFields () {
88+
return dataDefs.formContent;
89+
};
90+
8391
const dataFieldsCache = {};
84-
function initFieldsCache (event) {
92+
function initFieldsCache () {
8593
if (Object.keys(dataFieldsCache).length !== 0) return;
8694
for (const formField of dataDefs.formContent) {
8795
const dataFieldId = formField.streamId + ':' + formField.eventType;
@@ -112,7 +120,7 @@ function dataFieldFromEvent (event) {
112120
return field;
113121
}
114122

115-
// -------- initualization functions --------
123+
// -------- init functions --------
116124

117125
/**
118126
* Initialize the doctor account

dr.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,13 @@ <h2 class="card-title">Sharing link</h2>
4444

4545
</div>
4646
<div class="card-body">
47-
<h2 class="card-title">Data</h2>
47+
<h2 class="card-title">Patients</h2>
4848
<table id='patients-table' class="table">
4949
<thead>
50-
<tr>
51-
<th colspan="2"><b>Patients</b></td>
52-
</tr>
53-
<tr>
54-
<th scope="col">Username</th>
55-
<th scope="col">Name</th>
56-
<th scope="col">Surname</th>
57-
<th scope="col">Nationality</th>
58-
</tr>
50+
<!-- will be filled by setPatientList-->
5951
</thead>
6052
<tbody>
53+
<!-- will be filled by setPatientList-->
6154
</tbody>
6255
</table>
6356
</div>

patient-lib.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,25 @@ async function getFormContent () {
158158
};
159159

160160
// ---------------- create / update data ---------------- //
161+
162+
async function parseValue (value, type) {
163+
if (type === 'number') {
164+
return parseFloat(value);
165+
}
166+
if (type === 'boolean') {
167+
return value === 'true';
168+
}
169+
return value;
170+
}
171+
161172
async function handleFormSubmit (values) {
162173
const apiCalls = [];
163174
for (const field of formData) {
164175
const streamId = field.streamId;
165176
const eventType = field.eventType;
166177
const eventId = field.eventId;
167178
const value = values[field.id];
168-
179+
console.log('## Value', field.id, value);
169180
if (value === '' && eventId) {
170181
// delete the event
171182
apiCalls.push({

0 commit comments

Comments
 (0)