CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • CiciCase Mod with custom field calculation
Pages: [1]

Author Topic: CiciCase Mod with custom field calculation  (Read 714 times)

ctyler

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.7.2
  • CMS version: Drupal 7.43
  • MySQL version: 5.6.17
  • PHP version: 5.5.12
CiciCase Mod with custom field calculation
March 16, 2016, 09:32:14 am
Hello All,
I have been charged with developing CivicCrm for my place of business. I was reading the CivicCRM Developer guide and it suggested that I post in the forums before starting on any code.  So here goes!
The company I work for is a nonprofit and we help people with disabilities both mental and physical. The Department that deals with seniors needs to produce reports to certain agencies. As part of the reporting, a matrix must be filled out – This is a questionnaire.
I currently have all of the question fields created in sections/tabs under CivicCase. The matrix is grouped by questions.  For example a section entitled Income will have 4-5 questions based on Income. Depending on the yes or no answers a final field (#6) will need to be automatically populated. For example the questions are:
1.   Does the household have income (both earned income and cash benefits)?
2.   Is the household's income greater than or equal to 200% of Federal Poverty Guidelines?
3.   Does the household show appropriate spending habits (Focus on meeting basic needs before purchasing luxuries, no unusually high costs, no spontaneous or inappropriate spending)
4.   Does the household need assistance (Outside of own income) to meet basic needs?
5.   Does the household have discretionary income and the ability to save?
6.   Score:
So if 1 is answered yes you would continue to 2. If 2 were answered yes you would continue to 3.  If 3 was “no” then a score would need to be recorded in field #6 above and no further questions would be needed. There will be several sections that will be about employment, Housing, etc. that would need to be scored similarly.  I think this is possible but I wanted to check to see if something similar has been done already. If not, could someone point me in the right direction as far as documentation. Any help would be appreciated.

Thank you,
Casey


JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: CiciCase Mod with custom field calculation
March 16, 2016, 09:59:05 am
Hi Casey,

Welcome!

First, a bit of administrivia - that developer documentation is out of date, it should tell you to go to Stack Exchange instead:  http://civicrm.stackexchange.com.

What you're looking to do will require some custom coding on your part - but I've certainly seen it done.

First - are you using CiviCRM with Drupal?  If so, using the Webform-CiviCRM integration to build this functionality will greatly reduce the amount of code you need to write.

Assuming you're NOT using Webform-CiviCRM integration, I can see two things you need to do here:
* Calculate the final score.  I would do this using jQuery, a hook, or both.  jQuery will let you update the score in real-time, but the calculations are done client-side - so it's possible for someone malicious to manipulate the score so it doesn't match what it's supposed to be.  Using a hook might be better - maybe https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre?  You could use this to calculate the score after someone presses "Submit".  This is generally more fool-proof, but the score won't be displayed before someone presses "Submit".  Also check out hook_civicrm_validateForm: https://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference
* Enable/disable questions based on the answer to previous questions.  If you use Webform-CiviCRM, this can be handled in the UI - if not, you'll need to inject some jQuery to handle it.

Some meta-tips:
* You'll need to know how to create an extension.  Install Civix first: https://github.com/totten/civix/.  Then check this out: https://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension.
* This page will show you how to inject your jQuery: https://wiki.civicrm.org/confluence/display/CRMDOC/Javascript+Reference

Good luck!  Don't hesitate to ask follow-up questions on Stack Exchange or here.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

ctyler

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.7.2
  • CMS version: Drupal 7.43
  • MySQL version: 5.6.17
  • PHP version: 5.5.12
Re: CiciCase Mod with custom field calculation
March 20, 2016, 03:33:17 pm
Hi JonGold,
Great info. Thank you very much!

Casey

ctyler

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.7.2
  • CMS version: Drupal 7.43
  • MySQL version: 5.6.17
  • PHP version: 5.5.12
Re: CiciCase Mod with custom field calculation
March 28, 2016, 10:44:32 am
Hi RonJon,
I am using Drupal and I have gotten everything to work the way I wanted using jQuery. However, I am having one problem. I am having a difficult time getting the values that are changed by  jQuery to save into the database. For instance if question 1 is yes than question 2 needs to be changed to no by jQuery. I get it to work on the form but when the case is saved the last option that was changed manually is recorded in the database - no what jQuery changed it too. Any idea how to solve that?

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: CiciCase Mod with custom field calculation
March 28, 2016, 10:56:30 am
Hi ctyler,

Glad to hear that you're mostly there!

I would need to know about your situation to give an answer - and at this point, I really recommend posting this to Stack Exchange, where more people will see it.  There's a good 60-second introduction to Stack Exchange at http://civicrm.stackexchange.com/tour.

When posting, don't forget to mention your Civi version number and also CMS.  Also, I'd want to know this:
* Are you using Webform-CiviCRM integration, a profile, or something else?
* Are any of the fields you're trying to save a Select2 element?  It could be that you're editing the Select2 element, which changes the display but not the underlying value.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

ctyler

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.7.2
  • CMS version: Drupal 7.43
  • MySQL version: 5.6.17
  • PHP version: 5.5.12
Re: CiciCase Mod with custom field calculation
March 29, 2016, 06:12:11 am
Hi JonGold,
I am sorry. You did tell me to use Stack Exchange. I will post this over there. You are right, I am  changing the Select2 element. I am not using Webform-CiviCRM.

Hope to see you on the Stack Exchange

Thanks you!
Casey

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • CiciCase Mod with custom field calculation

This forum was archived on 2017-11-26.