Question T11361
Visible to All Users

Save hidden survey questions to survey results

created 2 years ago (modified 2 years ago)

[Ticket cloned from T11237: SurveyJS in Blazor WASM app]

Hello, Jane!

It works flawlessly! Thank you for this.

I bumped into another issue, given my configuration, and would like your input about what is the best way to achieve this.

I have a 5 page medical survey. The actors that will operate on this survey are patients and doctors.

The survey is tailored with a hidden variable that is being sent from the Blazor app to identify if the survey is for patient or doctors.

This variable controls the hidden and required properties of pages 3/4/5 - which are only to be completed by a doctor.

Now my problem is:

  1. Patient gets the full survey, but pages 3/4/5 are hidden and non-required, he completes he survey, saves it in the DB.
  2. The doctors opens the previously saved survey to complete his parts, but his parts are not available because they were hidden and non-required in the 1st part of the flow, when the patient completed his required parts.

My questions:

  1. How can I save the full JSON result, even though some pages are hidden and non-required? I think it is not possible.
  2. If 1) is out of the question, is there a way I can inject the doctor pages AFTER I load from DB the JSON result saved by the patient?

My code is something like this:

JavaScript
Survey.StylesManager.applyTheme("defaultV2"); let patientSurvey = new Survey.Model(); export function setIsDoctorValue(isDoctor) { patientSurvey.getQuestionByName("IsDoctor").value = isDoctor; }; export function setPatientName(PatientName) { patientSurvey.description = "Patient Name: " + PatientName; }; export function setSurveyJsonData(JsonData, objRef) { patientSurvey = new Survey.Model(JsonData); $("#surveyElement").Survey({ model: patientSurvey }); patientSurvey.onComplete.add(function (sender) { objRef.invokeMethodAsync('SendJsonSurveyResult', JSON.stringify(sender.data, null, 3)); document.querySelector('#surveyResult').textContent = "You will be redirected to your submissions page in 4 seconds..."; }); }; patientSurvey.onComplete.add(function (sender) { DotNet.invokeMethodAsync('MHU.Blazor.Public', 'SendJsonSurveyResult', JSON.stringify(sender.data, null, 3)); });

And in the Blazor side of the component:

C#
protected override async Task OnInitializedAsync() { VisibleProperty = true; objRef = DotNetObjectReference.Create(this); try { if (isNewSubmission) { var patient = await PatientsAppService.GetAsync(PatientId.Value); PatientName = patient.NameSurname; DefaultSubmissions = await DefaultSubmissionsAppService.GetListAsync( new GetDefaultSubmissionModelsInput() { Code= "TCI-MHSE-11", IsActive = true }); JsonModel = DefaultSubmissions.Items[0].RawJsonData; if (CurrentUser.IsInRole("Patient")) { await module.InvokeVoidAsync("setSurveyJsonData", JsonModel, objRef); await module.InvokeVoidAsync("setPatientName", PatientName); await module.InvokeVoidAsync("setIsDoctorValue", false); } else if (CurrentUser.IsInRole("Doctor")) { await module.InvokeVoidAsync("setSurveyJsonData", JsonModel, objRef); await module.InvokeVoidAsync("setPatientName", PatientName); await module.InvokeVoidAsync("setIsDoctorValue", true); } else { throw new UserFriendlyException("A critical error has occured. Please go back to the previous page and retry the operation."); } } else { var submission = await SubmissionsAppService.GetAsync(SubmissionId); var submissionJsonModel = submission.RawJsonData; if (CurrentUser.IsInRole("Patient")) { await module.InvokeVoidAsync("setSurveyJsonData", submissionJsonModel, objRef); await module.InvokeVoidAsync("setPatientName", PatientName); await module.InvokeVoidAsync("setIsDoctorValue", false); } else { await module.InvokeVoidAsync("setSurveyJsonData", submissionJsonModel, objRef); await module.InvokeVoidAsync("setPatientName", PatientName); await module.InvokeVoidAsync("setIsDoctorValue", true); } } VisibleProperty = false; } catch(UserFriendlyException ex) { await HandleErrorAsync(ex); } }
Comments (2)

    Hello Catalin,
    Thank you for the detailed explanation. From what I gather, you conditionally show survey pages/questions based on a user role (patient/doctor).

    How can I save the full JSON result, even though some pages are hidden and non-required? I think it is not possible.

    If you wish to save invisible question values to survey results, set the survey.clearInvisibleValues property to none.

    Please let me know if this option works for you.

      Hello Jane,

      It works. But now I realized I explained it in the wrong way.

      What I actually needed was a way for a doctor to continue using the same survey model, to complete the pages dedicated to his role in the survey, but loaded with the data completed by a patient in a previous step - Page 1 and 2.

      It was easier than I thought, I just had to load the survey model, then assign to it its previously saved data with survey.data = previouslySavedResult.

      Truly a great product SurveyJs!

      So all is good.

      Thank you very much!

      Answers approved by surveyjs Support

      created 2 years ago

      Hello Catalin,
      Thank you for the update. I'm happy to hear that you've managed to achieve your goal.

      Let me also mention two more settings which may help in your usage scenario.

      Enable the survey.sendResultOnPageNext option to save survey results once a user fills in a survey page. At this point, the survey.onPartialSend event is raised allowing you to send data to the server. This option allows you to save data immediately and may be useful if a respondent may leave the survey answered incompletely.

      You can also start a survey from the pages dedicated for doctors. For this, specify the survey.currentPageNo property.

      I would recommend that you refer to the Real Examples | Patient Medical History demo.

      It demonstrates a similar usage scenario and all the options mentioned above.

      Should you have any questions or require further assistance, you are always welcome to contact us at any time.