<commit_before>(function(cornerstoneTools) {

    'use strict';

    // Returns a decimal value given a fractional value
    function fracToDec(fractionalValue) {
        return parseFloat('.' + fractionalValue);
    }

    function calculateSUV(image, storedPixelValue) {
        if (!dicomParser) {
            return;
        }

        var patientStudyModule = cornerstone.metaData.get('patientStudyModule', image.imageId);
        var seriesModule = cornerstone.metaData.get('generalSeriesModule', image.imageId);
        var modality = seriesModule.modality;

        // image must be PET
        if (modality !== 'PT') {
            return;
        }

        var modalityPixelValue = storedPixelValue * image.slope + image.intercept;

        var patientWeight = patientStudyModule.patientWeight; // in kg
        if (patientWeight === undefined) {
            return;
        }

        var petSequence = image.data.elements.x00540016;
        if (petSequence === undefined) {
            return;
        }

        petSequence = petSequence.items[0].dataSet;
        var startTime = dicomParser.parseTM(petSequence.string('x00181072'));
        var totalDose = petSequence.floatString('x00181074');
        var halfLife = petSequence.floatString('x00181075');
        var seriesAcquisitionTime = dicomParser.parseTM(image.data.string('x00080031'));

        if (!startTime || !totalDose || !halfLife || !seriesAcquisitionTime) {
            return;
        }

        var acquisitionTimeInSeconds = fracToDec(seriesAcquisitionTime.fractionalSeconds) + seriesAcquisitionTime.seconds + seriesAcquisitionTime.minutes * 60 + seriesAcquisitionTime.hours * 60 * 60;
        var injectionStartTimeInSeconds = fracToDec(startTime.fractionalSeconds) + startTime.seconds + startTime.minutes * 60 + startTime.hours * 60 * 60;
        var durationInSeconds = acquisitionTimeInSeconds - injectionStartTimeInSeconds;
        var correctedDose = totalDose * Math.exp(-durationInSeconds * Math.log(2) / halfLife);
        var suv = modalityPixelValue * patientWeight / correctedDose * 1000;

        return suv;
    }
<commit_msg>Accessing PET Isotope Module through metaData provider<commit_after>(function(cornerstoneTools) {

    'use strict';

    // Returns a decimal value given a fractional value
    function fracToDec(fractionalValue) {
        return parseFloat('.' + fractionalValue);
    }

    function calculateSUV(image, storedPixelValue) {
        if (!dicomParser) {
            return;
        }

        var patientStudyModule = cornerstone.metaData.get('patientStudyModule', image.imageId);
        var seriesModule = cornerstone.metaData.get('generalSeriesModule', image.imageId);
        var modality = seriesModule.modality;

        // image must be PET
        if (modality !== 'PT') {
            return;
        }

        var modalityPixelValue = storedPixelValue * image.slope + image.intercept;

        var patientWeight = patientStudyModule.patientWeight; // in kg
        if (patientWeight === undefined) {
            return;
        }

        var petSequenceModule = cornerstone.metaData.get('petIsotopeModule', image.imageId);
        if (petSequenceModule === undefined) {
            return;
        }

        var radiopharmaceuticalInfo = petSequenceModule.radiopharmaceuticalInfo;
        var startTime = radiopharmaceuticalInfo.radiopharmaceuticalStartTime;
        var totalDose = radiopharmaceuticalInfo.radionuclideTotalDose;
        var halfLife = radiopharmaceuticalInfo.radionuclideHalfLife;
        var seriesAcquisitionTime = seriesModule.seriesTime;

        if (!startTime || !totalDose || !halfLife || !seriesAcquisitionTime) {
            return;
        }

        var acquisitionTimeInSeconds = fracToDec(seriesAcquisitionTime.fractionalSeconds || 0) + seriesAcquisitionTime.seconds + seriesAcquisitionTime.minutes * 60 + seriesAcquisitionTime.hours * 60 * 60;
        var injectionStartTimeInSeconds = fracToDec(startTime.fractionalSeconds) + startTime.seconds + startTime.minutes * 60 + startTime.hours * 60 * 60;
        var durationInSeconds = acquisitionTimeInSeconds - injectionStartTimeInSeconds;
        var correctedDose = totalDose * Math.exp(-durationInSeconds * Math.log(2) / halfLife);
        var suv = modalityPixelValue * patientWeight / correctedDose * 1000;

        return suv;
    }

{'fraction_non_alphanumeric': 0.09026182820395039, 'fraction_numerical': 0.017455213596692696, 'mean_word_length': 2.926961226330027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4520150', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1133, 'n_words': 245}