<commit_before>angular.module('os.biospecimen.common')
  .factory('SpecimenTypeUtil', function(PvManager) {

    function transformer(pv) {
      return {specimenClass: pv.parentValue, type: pv.value};
    }

    function loadSpecimenTypes() {
      return PvManager.loadPvsByParent('specimen-class', '', true, transformer);
    }

    function getSpecimenTypes(formCtrl) {
      return formCtrl.getCachedValues('pvs', 'specimen-type', loadSpecimenTypes);
    }

    function setType(specimen, types, type) {
      for (var i = 0; i < types.length; ++i) {
        if (types[i].type == type) {
          angular.extend(specimen, types[i]);
          break;
        }
      }
    }

    function init(specimen, types) {
      var type = specimen.type;
      if (!type) {
        return;
      }

      setType(specimen, types, type);
    }

    return {
      setClass: function(formCtrl, specimens) {
        getSpecimenTypes(formCtrl).then(
          function(types) {
            angular.forEach(specimens, function(specimen) { init(specimen, types); });
          }
        );
      },

      getSpecimenTypes: getSpecimenTypes
    }
  })
  .directive('osSpecimenTypes', function($timeout, SpecimenTypeUtil, PvManager) {
    var valuesQ = undefined;

    function linker(scope, element, attrs, formCtrl) {
      scope.types = [];
      valuesQ = SpecimenTypeUtil.getSpecimenTypes(formCtrl);
      valuesQ.then(function(types) { scope.types = types; });

      scope.onTypeSelect = function(type) {
        angular.extend(scope.specimen, type);
      }

      SpecimenTypeUtil.setClass(formCtrl, [scope.specimen]);
    }

    return {
      restrict: 'E',

      require: '^osFormValidator',

      scope: {
        specimen: '=',
      },

      replace: true,

      template: 
        '<div>' +
        '  <os-select ng-model="specimen.type" list="types" group-by="\'specimenClass\'"' +
        '    select-prop="type" display-prop="type" on-select="onTypeSelect($item)">' +
        '  </os-select></div>' +
        '</div>',<commit_msg>OPSMN-3200 Fixed containers are not loading according to selected specimen class and type.<commit_after>angular.module('os.biospecimen.common')
  .factory('SpecimenTypeUtil', function(PvManager) {

    function transformer(pv) {
      return {specimenClass: pv.parentValue, type: pv.value};
    }

    function loadSpecimenTypes() {
      return PvManager.loadPvsByParent('specimen-class', '', true, transformer);
    }

    function getSpecimenTypes(formCtrl) {
      return formCtrl.getCachedValues('pvs', 'specimen-type', loadSpecimenTypes);
    }

    function setType(specimen, types, type) {
      for (var i = 0; i < types.length; ++i) {
        if (types[i].type == type) {
          angular.extend(specimen, types[i]);
          break;
        }
      }
    }

    function init(specimen, types) {
      var type = specimen.type;
      if (!type) {
        return;
      }

      setType(specimen, types, type);
    }

    return {
      setClass: function(formCtrl, specimens) {
        getSpecimenTypes(formCtrl).then(
          function(types) {
            angular.forEach(specimens, function(specimen) { init(specimen, types); });
          }
        );
      },

      getSpecimenTypes: getSpecimenTypes
    }
  })
  .directive('osSpecimenTypes', function($timeout, SpecimenTypeUtil, PvManager) {
    var valuesQ = undefined;

    function linker(scope, element, attrs, formCtrl) {
      scope.types = [];
      scope.model = {value: scope.specimen.type};

      valuesQ = SpecimenTypeUtil.getSpecimenTypes(formCtrl);
      valuesQ.then(function(types) { scope.types = types; });

      scope.onTypeSelect = function(type) {
        angular.extend(scope.specimen, type);
      }

      SpecimenTypeUtil.setClass(formCtrl, [scope.specimen]);
    }

    return {
      restrict: 'E',

      require: '^osFormValidator',

      scope: {
        specimen: '=',
      },

      replace: true,

      template: 
        '<div>' +
        '  <os-select ng-model="model.value" list="types" group-by="\'specimenClass\'"' +
        '    select-prop="type" display-prop="type" on-select="onTypeSelect($item)">' +
        '  </os-select>' +
        '</div>',
{'fraction_non_alphanumeric': 0.14112327463112803, 'fraction_numerical': 0.0014278914802475012, 'mean_word_length': 2.508347245409015, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '367091', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1290, 'n_words': 228}