Skip to content

Commit ea0cecc

Browse files
committed
Adding streams creation on patient side
1 parent 90c51b3 commit ea0cecc

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

patient-lib.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ function parseFloatCustom(value) {
248248
async function handleFormSubmit (collectorClient, formData, formKey, values, date) {
249249
console.log('## handleForm', {formData, values, date});
250250
const apiCalls = [];
251+
// list of items that will be created or updated
252+
const itemDefsToCreateOrUpdate = new Set();
251253
for (const field of formData) {
252254
const streamId = field.itemDef.data.streamId;
253255
const eventType = field.itemDef.eventTypes[0];
@@ -270,6 +272,9 @@ async function handleFormSubmit (collectorClient, formData, formKey, values, dat
270272
continue;
271273
}
272274

275+
// bellow update or create
276+
itemDefsToCreateOrUpdate.add(field.itemDef);
277+
273278
if (eventId) {
274279
// update the event
275280
apiCalls.push({
@@ -300,6 +305,10 @@ async function handleFormSubmit (collectorClient, formData, formKey, values, dat
300305
console.log('## No changes to submit');
301306
return;
302307
}
308+
309+
// ensure streams exists
310+
await collectorClient.app.connection.streamsAutoCreate.ensureExistsForItems(itemDefsToCreateOrUpdate);
311+
303312
// send the API calls
304313
const res = await collectorClient.app.connection.api(apiCalls);
305314
console.log('## Form submitted', res);

0 commit comments

Comments
 (0)