Skip to content

Commit cf446f7

Browse files
committed
Finalized Patient View
1 parent ce11d00 commit cf446f7

4 files changed

Lines changed: 21 additions & 14 deletions

File tree

common-data-defs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ const v2 = {
275275
name: 'Profile',
276276
itemKeys: [
277277
'profile-name',
278+
'profile-surname',
278279
'profile-sex',
279280
'family-children-count',
280281
'fertility-miscarriages-count'

common-lib.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export async function initHDSModel () {
1313
const service = new Pryv.Service(serviceInfoUrl);
1414
const serviceInfo = await service.info();
1515
model = new HDSLib.HDSModel(serviceInfo.assets['hds-model']);
16+
console.log('## model:', model);
1617
await model.load();
1718
}
1819
return model;

patient-history-controler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async function submitForm(formData, dateStr) {
161161
if (field.type === "date") {
162162
values[field.id] = formField.valueAsDate;
163163
} else if (field.type === "checkbox") {
164-
values[field.id] = formField.checked ? 'x' : '';
164+
values[field.id] = formField.checked ? 'true' : '';
165165
} else {
166166
values[field.id] = formField.value.trim();
167167
}

patient-lib.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ async function getFormHistorical (questionaryId, formKey) {
8787
label: itemDef.data.label.en,
8888
type: itemDef.data.type,
8989
options: itemDef.data.options,
90-
streamId: itemDef.data.streamId,
91-
eventType: itemDef.eventTypes[0] // take first type by default for now
90+
itemDef
9291
}
9392
});
9493
return formFields;
@@ -129,10 +128,13 @@ async function getFormPermanentContent (questionaryId, formKey) {
129128
if (e.events && e.events.length > 0) {
130129
const event = e.events[0];
131130
const valueAndTxt = valueAndTxtForField(event, itemDef);
131+
console.log('>> valueAndtxt', {event, valueAndTxt});
132132
content.value = valueAndTxt.value;
133133
content.valueTxt = valueAndTxt.txt;
134134
content.eventId = event.id; // will allow t track if the event is to be updated
135-
}
135+
} else {
136+
console.log('>> no event', e);
137+
}
136138
formContent.push(content);
137139
}
138140
return formContent;
@@ -228,23 +230,21 @@ function valueAndTxtForField (event, itemDef) {
228230
// ---------------- create / update data ---------------- //
229231

230232
function parseValue (value, field) {
231-
const type = field.type;
233+
const type = field.itemDef.data.type;
234+
console.log('>> parsValue', {value, field});
232235
if (value === undefined || value === null || value === '') {
233236
return '';
234237
}
235-
if (type === 'number' || field.parseValueToNum) {
238+
if (type === 'number') {
236239
return parseFloatCustom(value);
237240
}
238-
if (type === 'boolean') {
239-
return value === 'true';
240-
}
241241
if (type === 'date') {
242242
if (value instanceof Date && !isNaN(value)) {
243243
return value.toISOString();
244244
}
245245
return value === '';
246246
}
247-
if (type === 'select' && field.eventType === 'ratio/generic') {
247+
if (type === 'select' && field.itemDef.eventTypes[0] === 'ratio/generic') {
248248
const numValue = parseFloatCustom(value);
249249
if (numValue === '') return '';
250250
// relative to is the latest value of options
@@ -254,10 +254,13 @@ function parseValue (value, field) {
254254
relativeTo
255255
}
256256
}
257-
if (type === 'checkbox' && field.eventType === 'activity/plain') {
258-
if (value === 'x') return null; // will be handled as a value
257+
if (type === 'checkbox' && field.itemDef.eventTypes[0] === 'activity/plain') {
258+
if (value === 'true') return null; // will be handled as a value
259259
return '';
260260
}
261+
if (type === 'checkbox') {
262+
return value === 'true';
263+
}
261264
return value;
262265
}
263266

@@ -271,12 +274,14 @@ function parseFloatCustom(value) {
271274
}
272275

273276
async function handleFormSubmit (formData, values, date) {
277+
console.log('## handleForm', {formData, values, date});
274278
const apiCalls = [];
275279
for (const field of formData) {
276-
const streamId = field.streamId;
277-
const eventType = field.eventType;
280+
const streamId = field.itemDef.data.streamId;
281+
const eventType = field.itemDef.eventTypes[0];
278282
const eventId = field.eventId;
279283
const value = parseValue(values[field.id], field);
284+
console.log('>> parsed value:', value);
280285
if (value === '' && eventId) {
281286
// delete the event
282287
apiCalls.push({

0 commit comments

Comments
 (0)