jeudi 6 février 2020

Can someone help me implement the Matlab "movefile" function into my if/else statement?

I have a Matlab script that looks at information in a .xsl file and a DICOM file header. I have recorded information on both files that need to match.

I've created a script that can review the information on both files and in an if/else statement it will display "Perfect Match", "Error 1", "Error 2". After that, I typically manually move the files to their respective folders.

I know about the function "movefile" but when I put it into my code, I can't seem to get it to work

clear;clc
Mosaiq_missing=[];Mismatch_dose_plan=[];no_plan=[];false_dose=[];

% Reads Data from this file
% Several patient file are in this location
dirpat='C:\Users\Desktop\Project\Patients\';
[patnamen,~]=getfil(dirpat);
% This contains the records I wish to match values 
%Mataches IDs from this file
dirloc='C:\Users\Desktop\Project\LINAC_MOSAIQ_values.xlsx';
MOSAIQ=readtable(dirloc);

% This is the path I want the folders to move to
dirperfect='C:\Users\Desktop\Project\Perfect_Match\';
direrrorrbwr='C:\Users\Desktop\Project\\Error1\';
direrrorDoSomething='C:\Users\Desktop\Project\\Error2\';

% MOSAIQ.ida=cellstr(num2str(MOSAIQ.ida));
oma=MOSAIQ(ismember(MOSAIQ.ida,patnamen),:);
oma2=MOSAIQ(ismember(MOSAIQ.Field_Name, patnamen),:);

co=[2 2 2 2 2 2];dc=1;
for pp=1:length(patnamen)
    clearvars -except dirpat patnamen dc pp Mosaiq_missing Mismatch_dose_plan no_plan false_dose wrong_dose_dir repeat oma oma_namen
    mismatch=0; hl=0;
    patientname=patnamen{pp};

    if ismember(patientname,oma.ida)
        display(['loading patient: ',patientname])
        dirloc=[fullfile(dirpat,patientname),'\'];
        pa = genpath(dirloc);
        splitfil=regexp(pa,'\;','split')';

% read dose plan locations 
     DOSEplek=cellfun(@isempty,regexp(splitfil,'DOSE'))==0;
     PLANplek=cellfun(@isempty,regexp(splitfil,'PLAN'))==0; 
     DOSE=splitfil(DOSEplek);
     PLAN=splitfil(PLANplek);


     if sum(PLANplek)>0
        [RTplan_files,~]=getfil(PLAN{1});

        for pl=1:length(RTplan_files)
            info=dicominfo(fullfile(PLAN{1},RTplan_files{pl}));

            beam_name=cell(length(fieldnames(  info.FractionGroupSequence.Item_1.ReferencedBeamSequence)),1);
            BeamMetersets=nan(length(fieldnames(  info.FractionGroupSequence.Item_1.ReferencedBeamSequence)),1);


            for p=1:length(fieldnames(   info.FractionGroupSequence.Item_1.ReferencedBeamSequence))
            BeamMetersets(p)=info.FractionGroupSequence.Item_1.ReferencedBeamSequence.(['Item_',num2str(p)]).BeamMeterset;
            beam_name(p)={info.BeamSequence.(['Item_',num2str(p)]).BeamDescription};
            end
            fraction_number=info.FractionGroupSequence.Item_1.NumberOfFractionsPlanned;


        end

        %match to MOSAIQ_EXCEL_FILE

                loc=ismember(oma.ida,patientname);%cellfun(@isempty,regexpi(oma_namen,patientnaam))==0;
                MOSAIQ_sel=table2cell(oma(loc,:));

                if size(MOSAIQ_sel,1)==size(BeamMetersets,1)
                    if sum(~ismember(BeamMetersets,cell2mat(MOSAIQ_sel(:,10))))==0
                        disp('Perfect Match')
                        movefile([dirpat,patientname],[dirperfect,patientname])

                    else
                        disp('Error1')
                        movefile([dirpat,patientname],[direrrorrbwr,patientname])
                        BeamMetersets;
                        mosaiq_beam_values=cell2mat(MOSAIQ_sel(:,10));


                    end

                else
                    disp('Error2')
                    movefile([dirpat,patientname],[direrrorDoSomething,patientname])


                end





     end
    end
end      

Aucun commentaire:

Enregistrer un commentaire