/
Set default value for child based on value of parent/primary specimen
Got feedback or spotted a mistake?

Leave a comment at the end of this page or email contact@krishagni.com

Set default value for child based on value of parent/primary specimen

Using custom configuration, users can set the default value for the child based on the value of the parent/primary specimen.

Add the code in the dictionary after the "fields" section. This code is only works on the Add Specimen page where you are creating the child specimen and on nth step 

Example 1: Set default value for custom field 'Biobank Technician' at child specimens level based on selection of value at primary specimens level

 Click here to expand...
"onValueChange": {
          "specimen.extensionDetail.attrsMap.FC15": [
            "function(opts) {",
            "  angular.forEach(opts.viewCtx.spmnCtx.aliquots, ",
            "    function(aliquot) { ",
            "      var user = opts.fns.get(opts.object, opts.field);",
            "      opts.fns.set(aliquot, 'extensionDetail.attrsMap.FC15', user);",
            "    }",
            "  );",
            "}"
          ],

Screenshot when the user selects the 'Biobank Technician' at Parent/Primary specimen level:

Screenshot when Biobank Technician automatically copied from primary/parent specimen level to aliquot level:

Example 2: Blank out related fields when updating the value for another field

 Click here to expand...

Added the value for TubeType= 'Serum Separator Vacutainer' and assigned the values below two fields.

1. "Cardiac Troponin I (ng/L)" = 'Test Data To Be Blanked' 
2. "Cardiac Troponin T (ng/L)"= 'Test Data To Be Blanked' 
Now I have to edit the specimen and change the 'TubeType' to ='EDTA Vacutainer', the values added for the above two fields get blanked using the below code.
"onValueChange" : {
                 "specimen.collectionEvent.container" : [ 
                  "function(opts) {", 
                    " var container = opts.fns.get(opts.object, opts.field);", 
                    " if (container != 'Serum Separator Vacutainer') {", 
                    " opts.fns.set(opts.object, 'specimen.extensionDetail.attrsMap.ST28', null);", 
                  " opts.fns.set(opts.object, 'specimen.extensionDetail.attrsMap.ST29', null);", 
" }", 
"}" ]
}

Example 3: Populate anatomic site as 'Blood' if specimen type is 'Plasma' or 'Lung, NOS' if specimen type is 'Fresh Tissue'

 Click here to expand...
"onValueChange" : {
                 "specimen.type" : [
                  "function(opts) {",
                    " var type = opts.fns.get(opts.object, opts.field);",
                    " if (type == 'Plasma') {",
                    " opts.fns.set(opts.object, 'specimen.anatomicSite', 'Blood');",
          " }",
					" else if (type == 'Fresh Tissue') {",
                    " opts.fns.set(opts.object, 'specimen.anatomicSite', 'Lung, NOS');",
          " }",
          "}" ]
          } 

Auto-selected 'Blood' if specimen type is 'Plasma':

Auto-selected 'Lung, NOS' if specimen type is 'Fresh Tissue':

Example 4: Copy/cascade the value of parent specimens to child specimens

 Click here to expand...
    "onValueChange" : {
      "specimen.createdBy" : [ "function(opts) {", "  var user = opts.fns.get(opts.object, opts.field); ", "  opts.viewCtx.setToAllChildren(opts.object, opts.field, user, true); ", "}" ],
      "specimen.createdOn" : [ "function(opts) {", "  var user = opts.fns.get(opts.object, opts.field); ", "  opts.viewCtx.setToAllChildren(opts.object, opts.field, user, true); ", "}" ]
    }



Example JSON

Related content

Populate the value based on the selection of other field value/s
Populate the value based on the selection of other field value/s
More like this
Hide/Set default value to specimen fields
Hide/Set default value to specimen fields
More like this
Initialise values based on other fields
Initialise values based on other fields
More like this
Define Defaults on Unplanned Specimen Page
Define Defaults on Unplanned Specimen Page
More like this
Configure Specimen Collection Page (nth Step)
Configure Specimen Collection Page (nth Step)
Read with this
Configuring Fields in Specimen Table and Tree (TO DO)
Configuring Fields in Specimen Table and Tree (TO DO)
More like this
Got feedback or spotted a mistake?

Leave a comment at the end of this page or email contact@krishagni.com