Example #1
0
        public string CalculateASAScore(string formInstanceId)
        {
            //get all the form responses for this form instance
            List <FormResponse> responses = _formResponseHelper.GetFormResponse(formInstanceId);

            return(FormScoreHelper.CalculateASAScore(responses));
        }
Example #2
0
        public List <FormResponse> Post([FromBody] Form formData)
        {
            InitializeDestination(ref formData);

            if (formData != null)
            {
                List <FormResponse> formResponses = new List <FormResponse>();
                string personId      = formData.FormParameters.Where(item => item.ParameterName.Equals("Person_Id")).FirstOrDefault().ParameterValue;
                string encounterId   = formData.FormParameters.Where(item => item.ParameterName.Equals("Encounter_Id")).FirstOrDefault().ParameterValue;
                string formContext   = formData.FormParameters.Where(item => item.ParameterName.Equals("Form_Context")).FirstOrDefault().ParameterKey;
                string formContextId = formData.FormParameters.Where(item => item.ParameterName.Equals("Form_Context")).FirstOrDefault().ParameterValue;

                FormInstance formInstance = _formInstanceHelper.GetFormInstance(formData.FormInstanceId);

                FormScore savedFormScore = _formInstanceHelper.GetFormScore(formInstance.FormInstanceId);

                foreach (var section in formData.Sections)
                {
                    foreach (var field in section.Fields)
                    {
                        foreach (var fieldData in field.FieldData)
                        {
                            var formResponse = new FormResponse
                            {
                                FormResponseId = Guid.NewGuid().ToString(),
                                FormInstanceId = formInstance.FormInstanceId,
                                FormId         = formData.FormId,
                                SectionId      = section.SectionId,
                                FieldId        = field.FieldId,
                                FieldType      = field.FieldControlTypeName,
                                FieldQuestion  = field.FieldLabelText,
                                ResponseText   = fieldData.Text,
                                ResponseValue  = fieldData.Value
                            };

                            formResponses.Add(formResponse);
                        }
                    }
                }

                _dynamicAPIClient.DeleteObjectByAttribute("dcs", "formresponse", "forminstance_id", formInstance.FormInstanceId);

                _dynamicAPIClient.PostObjectArray("dcs", "formresponse", formResponses);

                foreach (var destination in formData.DestinationEntities)
                {
                    string value = _dynamicAPIClient.ExecuteNonSQL(new SQLData()
                    {
                        Parameters   = destination.SQLParameters,
                        ReturnColumn = "_sequenceid",
                        Query        = destination.SQL
                    });
                }

                /*
                 * Below call need to be replaced by saving form scores based on the scoring model present in JSON. Implemented this way for Pre-op form delivery
                 */
                string  score    = FormScoreHelper.CalculateASAScore(formResponses);
                dynamic asaScore = JsonConvert.DeserializeObject(score);

                FormScore formScore = new FormScore();

                if (savedFormScore == null)
                {
                    formScore.FormScoreId = Guid.NewGuid().ToString();
                }
                else
                {
                    formScore.FormScoreId = savedFormScore.FormScoreId;
                }
                formScore.FormInstanceId    = formInstance.FormInstanceId;
                formScore.FormInstanceScore = asaScore.result.asascore;
                formScore.ReviewType        = asaScore.result.reviewtype;
                formScore.ScoreDescription  = asaScore.result.desc;
                formScore.ScoreId           = "ASAScore";

                _dynamicAPIClient.PostObject("dcs", "formscore", formScore);

                /*
                 * End of comments
                 */

                formInstance.Status = "Completed";
                _dynamicAPIClient.PostObject("dcs", "forminstance", formInstance);

                return(formResponses);
            }
            else
            {
                return(null);
            }
        }