classdef ShoulderCaseLoader < handle properties (Access = private) normal pathological end methods function obj = ShoulderCaseLoader(varargin) dataRootPath = obj.getDataRootPath(varargin); obj.normal = CasesFinderNormal(dataRootPath); obj.pathological = CasesFinderPathological(dataRootPath); end function output = containsCase(obj,SCase) output = or( obj.normal.containsCase(SCase), obj.pathological.containsCase(SCase)); end function output = getNumberOfCases(obj) output = obj.normal.getNumberOfCases + obj.pathological.getNumberOfCases; end function output = isEmpty(obj) output = not((obj.getNumberOfCases > 0)); end function output = getAllNormalCasesIDs(obj) output = obj.normal.getAllCasesIDs; end function output = getAllPathologicalCasesIDs(obj) output = obj.pathological.getAllCasesIDs; end function output = getAllCasesIDs(obj) normalIDs = obj.normal.getAllCasesIDs; pathologicalIDs = obj.pathological.getAllCasesIDs; output = {}; for i = 1:obj.normal.getNumberOfCases output{end+1} = normalIDs{i}; end for i = 1:obj.pathological.getNumberOfCases output{end+1} = pathologicalIDs{i}; end end function output = loadCase(obj,SCaseID) % Load existing ShoulderCase assert(obj.containsCase(SCaseID),'SCase not found') % Find ShoulderCase container = obj.getContainerOf(SCaseID); pathToCase = container.getPathTo(SCaseID); % Try to find saved ShoulderCase data caseMatlabFile = fullfile(pathToCase,'matlab','SCase.mat'); assert(logical(exist(caseMatlabFile,'file')),'No archive found for this SCase'); loaded = load(caseMatlabFile); assert(isfield(loaded,'SCase'),'No SCase field found in the archive'); SCase = loaded.SCase; assert(isequal(class(SCase),'ShoulderCase'),'The found SCase is not a ShoulderCase instance'); % Updated output with found archive output = SCase; % Update data paths output.dataCTPath = pathToCase; output.propagateDataPath; end function output = createEmptyCase(obj,SCaseID) % Create empty ShoulderCase assert(obj.containsCase(SCaseID),'Not enough data found to create the SCase. Must contains dicom files.') % Find ShoulderCase container = obj.getContainerOf(SCaseID); pathToCase = container.getPathTo(SCaseID); SCase = ShoulderCase(SCaseID,pathToCase); % Updated output with found archive output = SCase; end end methods (Access = private, Hidden = true) function output = getDataRootPath(obj,arguments) output = []; if isempty(arguments) TextFileOrPath = 'config.txt'; elseif not(ischar(arguments{1})) return else TextFileOrPath = arguments{1}; end if endsWith(TextFileOrPath,'.txt') output = FileExtractor.getVariableFromTextFile('dataDir',TextFileOrPath); else output = TextFileOrPath; end end function output = getContainerOf(obj,SCase) output = []; if obj.normal.containsCase(SCase) output = obj.normal; elseif obj.pathological.containsCase(SCase) output = obj.pathological; end end end end