diff --git a/schema/stored_programs/sp_retrieve_scm_container.sql b/schema/stored_programs/sp_retrieve_scm_container.sql new file mode 100644 index 00000000..70452ece --- /dev/null +++ b/schema/stored_programs/sp_retrieve_scm_container.sql @@ -0,0 +1,164 @@ +/* Tests: +CALL retrieve_scm_container(34888, False, NULL)\G +CALL retrieve_scm_container(34888, False, 'boaty')\G +CALL retrieve_scm_container(34888, True, NULL)\G +CALL retrieve_scm_container(34888, True, 'boaty')\G +*/ + +DELIMITER ;; + +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `retrieve_scm_container`(p_id int unsigned, p_useContainerSession boolean, p_authLogin varchar(45)) +READS SQL DATA +COMMENT 'Returns a single-row result-set with the container for the given ID' +BEGIN + + IF p_id IS NOT NULL THEN + + IF p_useContainerSession = True THEN + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT c.containerId "containerId", + c.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN BLSession bs ON bs.sessionId = c.sessionId + JOIN Proposal p ON p.proposalId = bs.proposalId + JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + JOIN Session_has_Person shp ON shp.sessionId = bs2.sessionId + JOIN Person per on per.personId = shp.personId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.containerId = p_id AND per.login = p_authLogin; + + ELSE + + SELECT c.containerId "containerId", + c.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN BLSession bs ON bs.sessionId = c.sessionId + JOIN Proposal p ON p.proposalId = bs.proposalId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.containerId = p_id; + + + END IF; + + ELSE + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT c.containerId "containerId", + d.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN Dewar d ON c.dewarId = d.dewarId + JOIN Shipping s ON s.shippingId = d.shippingId + JOIN Proposal p ON p.proposalId = s.proposalId + JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + JOIN Session_has_Person shp ON shp.sessionId = bs2.sessionId + JOIN Person per on per.personId = shp.personId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.containerId = p_id AND per.login = p_authLogin; + + ELSE + + SELECT c.containerId "containerId", + d.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN Dewar d ON c.dewarId = d.dewarId + JOIN Shipping s ON s.shippingId = d.shippingId + JOIN Proposal p ON p.proposalId = s.proposalId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.containerId = p_id; + + END IF; + + END IF; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_id can not be NULL'; + END IF; + +END;; + +DELIMITER ; \ No newline at end of file diff --git a/schema/stored_programs/sp_retrieve_scm_container_for_barcode.sql b/schema/stored_programs/sp_retrieve_scm_container_for_barcode.sql new file mode 100644 index 00000000..fe742d8a --- /dev/null +++ b/schema/stored_programs/sp_retrieve_scm_container_for_barcode.sql @@ -0,0 +1,165 @@ +/* Tests: + +CALL retrieve_scm_container_for_barcode('VMXiSim-001', False, NULL)\G +CALL retrieve_scm_container_for_barcode('VMXiSim-001', False, 'boaty')\G +CALL retrieve_scm_container_for_barcode('VMXiSim-001', True, NULL)\G +CALL retrieve_scm_container_for_barcode('VMXiSim-001', True, 'boaty')\G + +*/ + +DELIMITER ;; + +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `retrieve_scm_container_for_barcode`(p_barcode varchar(45), p_useContainerSession boolean, p_authLogin varchar(45)) +READS SQL DATA +COMMENT 'Returns a single-row result-set with the container for the given barcode' +BEGIN + + IF p_barcode IS NOT NULL THEN + + IF p_useContainerSession = True THEN + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT c.containerId "containerId", + c.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN BLSession bs ON bs.sessionId = c.sessionId + JOIN Proposal p ON p.proposalId = bs.proposalId + JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + JOIN Session_has_Person shp ON shp.sessionId = bs2.sessionId + JOIN Person per on per.personId = shp.personId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.barcode = p_barcode AND per.login = p_authLogin; + + ELSE + + SELECT c.containerId "containerId", + c.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN BLSession bs ON bs.sessionId = c.sessionId + JOIN Proposal p ON p.proposalId = bs.proposalId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.barcode = p_barcode; + + END IF; + + ELSE + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT c.containerId "containerId", + d.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN Dewar d ON c.dewarId = d.dewarId + JOIN Shipping s ON s.shippingId = d.shippingId + JOIN Proposal p ON p.proposalId = s.proposalId + JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + JOIN Session_has_Person shp ON shp.sessionId = bs2.sessionId + JOIN Person per on per.personId = shp.personId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.barcode = p_barcode AND per.login = p_authLogin; + + ELSE + + SELECT c.containerId "containerId", + d.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN Dewar d ON c.dewarId = d.dewarId + JOIN Shipping s ON s.shippingId = d.shippingId + JOIN Proposal p ON p.proposalId = s.proposalId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE c.barcode = p_barcode; + + END IF; + + END IF; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_barcode can not be NULL'; + END IF; + +END;; + +DELIMITER ; \ No newline at end of file diff --git a/schema/stored_programs/sp_retrieve_scm_containers_for_session.sql b/schema/stored_programs/sp_retrieve_scm_containers_for_session.sql new file mode 100644 index 00000000..ef00ae63 --- /dev/null +++ b/schema/stored_programs/sp_retrieve_scm_containers_for_session.sql @@ -0,0 +1,170 @@ +/* Tests: +CALL retrieve_scm_containers_for_session('cm', '14451', NULL, 'in_storage', NULL)\G +CALL retrieve_scm_containers_for_session('cm', '14451', NULL, 'in_storage', 'boaty')\G +CALL retrieve_scm_containers_for_session('cm', '14451', 99, 'in_storage', NULL)\G +CALL retrieve_scm_containers_for_session('cm', '14451', 99, 'in_storage', 'boaty')\G +*/ + +DELIMITER ;; + +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `retrieve_scm_containers_for_session`( + p_proposalCode varchar(45), + p_proposalNumber varchar(45), + p_sessionNumber int unsigned, + p_status varchar(45), + p_authLogin varchar(45) +) +READS SQL DATA +COMMENT 'Returns a multi-row result-set with the containers for the given session defined by proposal code, proposal number and session number' +BEGIN + + IF p_proposalCode IS NOT NULL AND p_proposalNumber IS NOT NULL THEN + + IF p_sessionNumber IS NOT NULL THEN + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT c.containerId "containerId", + c.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN BLSession bs ON bs.sessionId = c.sessionId + JOIN Proposal p ON p.proposalId = bs.proposalId + JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + JOIN Session_has_Person shp ON shp.sessionId = bs2.sessionId + JOIN Person per on per.personId = shp.personId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE p.proposalCode = p_proposalCode AND p.proposalNumber = p_proposalNumber AND bs.visit_number = p_sessionNumber AND c.containerStatus = p_status AND per.login = p_authLogin; + + ELSE + + SELECT c.containerId "containerId", + c.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN BLSession bs ON bs.sessionId = c.sessionId + JOIN Proposal p ON p.proposalId = bs.proposalId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE p.proposalCode = p_proposalCode AND p.proposalNumber = p_proposalNumber AND bs.visit_number = p_sessionNumber AND c.containerStatus = p_status; + + + END IF; + + ELSE + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT c.containerId "containerId", + d.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN Dewar d ON c.dewarId = d.dewarId + JOIN Shipping s ON s.shippingId = d.shippingId + JOIN Proposal p ON p.proposalId = s.proposalId + JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + JOIN Session_has_Person shp ON shp.sessionId = bs2.sessionId + JOIN Person per on per.personId = shp.personId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE p.proposalCode = p_proposalCode AND p.proposalNumber = p_proposalNumber AND c.containerStatus = p_status AND per.login = p_authLogin; + + ELSE + + SELECT c.containerId "containerId", + d.dewarId "dewarId", + c.sessionId "sessionId", + p.proposalId "proposalId", + c.ownerId "ownerId", + per2.login "ownerUsername", + c.code "name", + c.containerType "type", + c.barcode "barcode", + c.beamlineLocation "beamline", + c.sampleChangerLocation "location", + c.containerStatus "status", + c.capacity "capacity", + c.storageTemperature "storageTemperature", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber", + + c.comments "comments", + et.name "experimentType" + FROM Container c + JOIN Dewar d ON c.dewarId = d.dewarId + JOIN Shipping s ON s.shippingId = d.shippingId + JOIN Proposal p ON p.proposalId = s.proposalId + LEFT JOIN Person per2 ON per2.personId = c.ownerId + LEFT JOIN ExperimentType et ON et.experimentTypeId = c.experimentTypeId + WHERE p.proposalCode = p_proposalCode AND p.proposalNumber = p_proposalNumber AND c.containerStatus = p_status; + + END IF; + + END IF; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory arguments p_proposalCode and p_proposalNumber can not be NULL'; + END IF; + +END;; + +DELIMITER ; \ No newline at end of file diff --git a/schema/stored_programs/sp_retrieve_scm_sample.sql b/schema/stored_programs/sp_retrieve_scm_sample.sql new file mode 100644 index 00000000..23490de7 --- /dev/null +++ b/schema/stored_programs/sp_retrieve_scm_sample.sql @@ -0,0 +1,247 @@ +/* Tests: +CALL retrieve_scm_sample(398828, False, NULL)\G +CALL retrieve_scm_sample(398828, False, 'boaty')\G +CALL retrieve_scm_sample(398828, True, NULL)\G +CALL retrieve_scm_sample(398828, True, 'boaty')\G +*/ + +DELIMITER ;; + +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `retrieve_scm_sample`(p_id int unsigned, p_useContainerSession boolean, p_authLogin varchar(45)) +READS SQL DATA +COMMENT 'Returns a single-row result-set with the sample for the given ID' +BEGIN + + IF p_id IS NOT NULL THEN + + IF p_useContainerSession = True THEN + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN BLSession bs ON c.sessionId = bs.sessionId + INNER JOIN Proposal p ON p.proposalId = bs.proposalId + INNER JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + INNER JOIN Session_has_Person shp ON bs2.sessionId = shp.sessionId + INNER JOIN Person pe ON pe.personId = shp.personId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE pe.login = p_authLogin AND bls.blSampleId = p_id; + + ELSE + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN BLSession bs ON c.sessionId = bs.sessionId + INNER JOIN Proposal p ON p.proposalId = bs.proposalId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE bls.blSampleId = p_id; + + END IF; + + ELSE + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN Dewar d ON d.dewarId = c.dewarId + INNER JOIN Shipping s ON s.shippingId = d.shippingId + INNER JOIN Proposal p ON p.proposalId = s.proposalId + INNER JOIN BLSession bs ON bs.proposalId = p.proposalId + INNER JOIN Session_has_Person shp ON bs.sessionId = shp.sessionId + INNER JOIN Person pe ON pe.personId = shp.personId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE pe.login = p_authLogin AND bls.blSampleId = p_id; + + ELSE + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN Dewar d ON d.dewarId = c.dewarId + INNER JOIN Shipping s ON s.shippingId = d.shippingId + INNER JOIN Proposal p ON p.proposalId = s.proposalId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE bls.blSampleId = p_id; + + END IF; + + END IF; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_id can not be NULL'; + END IF; + +END;; + +DELIMITER ; \ No newline at end of file diff --git a/schema/stored_programs/sp_retrieve_scm_sample_for_container_barcode_and_location.sql b/schema/stored_programs/sp_retrieve_scm_sample_for_container_barcode_and_location.sql new file mode 100644 index 00000000..b5530e2f --- /dev/null +++ b/schema/stored_programs/sp_retrieve_scm_sample_for_container_barcode_and_location.sql @@ -0,0 +1,252 @@ +/* Tests: +CALL retrieve_scm_sample_for_container_barcode_and_location('VMXiSim-001', 1, False, NULL)\G +CALL retrieve_scm_sample_for_container_barcode_and_location('VMXiSim-001', 1, False, 'boaty')\G +CALL retrieve_scm_sample_for_container_barcode_and_location('VMXiSim-001', 1, True, NULL)\G +CALL retrieve_scm_sample_for_container_barcode_and_location('VMXiSim-001', 1, True, 'boaty')\G + +CALL retrieve_scm_sample_for_container_barcode_and_location('test_plate3', 1, False, NULL)\G +CALL retrieve_scm_sample_for_container_barcode_and_location('test_plate3', 1, False, 'boaty')\G + +*/ + +DELIMITER ;; + +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `retrieve_scm_sample_for_container_barcode_and_location`(p_barcode varchar(45), p_location varchar(45), p_useContainerSession boolean, p_authLogin varchar(45)) +READS SQL DATA +COMMENT 'Returns a single-row result-set (although can be multi-row if multiple samples per location in a container) with the sample for the given container barcode and sample location.' +BEGIN + + IF p_barcode IS NOT NULL AND p_location IS NOT NULL THEN + + IF p_useContainerSession = True THEN + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN BLSession bs ON c.sessionId = bs.sessionId + INNER JOIN Proposal p ON p.proposalId = bs.proposalId + INNER JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + INNER JOIN Session_has_Person shp ON bs2.sessionId = shp.sessionId + INNER JOIN Person pe ON pe.personId = shp.personId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE pe.login = p_authLogin AND c.barcode = p_barcode AND bls.location = p_location; + + ELSE + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN BLSession bs ON c.sessionId = bs.sessionId + INNER JOIN Proposal p ON p.proposalId = bs.proposalId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE c.barcode = p_barcode AND bls.location = p_location; + + END IF; + + ELSE + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN Dewar d ON d.dewarId = c.dewarId + INNER JOIN Shipping s ON s.shippingId = d.shippingId + INNER JOIN Proposal p ON p.proposalId = s.proposalId + INNER JOIN BLSession bs ON bs.proposalId = p.proposalId + INNER JOIN Session_has_Person shp ON bs.sessionId = shp.sessionId + INNER JOIN Person pe ON pe.personId = shp.personId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE pe.login = p_authLogin AND c.barcode = p_barcode AND bls.location = p_location; + + ELSE + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN Dewar d ON d.dewarId = c.dewarId + INNER JOIN Shipping s ON s.shippingId = d.shippingId + INNER JOIN Proposal p ON p.proposalId = s.proposalId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE c.barcode = p_barcode AND bls.location = p_location; + + END IF; + + END IF; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory arguments p_barcode and p_location can not be NULL'; + END IF; + +END;; + + +DELIMITER ; \ No newline at end of file diff --git a/schema/stored_programs/sp_retrieve_scm_samples_for_container_id.sql b/schema/stored_programs/sp_retrieve_scm_samples_for_container_id.sql new file mode 100644 index 00000000..fe4eadf1 --- /dev/null +++ b/schema/stored_programs/sp_retrieve_scm_samples_for_container_id.sql @@ -0,0 +1,250 @@ +/* Tests: +CALL retrieve_scm_samples_for_container_id(1335, False, NULL)\G + +CALL retrieve_scm_samples_for_container_id(34888, False, NULL)\G +CALL retrieve_scm_samples_for_container_id(34888, False, 'boaty')\G +CALL retrieve_scm_samples_for_container_id(34888, True, NULL)\G +CALL retrieve_scm_samples_for_container_id(34888, True, 'boaty')\G + +*/ + +DELIMITER ;; + +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `retrieve_scm_samples_for_container_id`(p_containerId int unsigned, p_useContainerSession boolean, p_authLogin varchar(45)) +READS SQL DATA +COMMENT 'Returns a multi-row result-set with the samples for the given container ID' +BEGIN + + IF p_containerId IS NOT NULL THEN + + IF p_useContainerSession = True THEN + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN BLSession bs ON c.sessionId = bs.sessionId + INNER JOIN Proposal p ON p.proposalId = bs.proposalId + INNER JOIN BLSession bs2 ON bs2.proposalId = p.proposalId + INNER JOIN Session_has_Person shp ON bs2.sessionId = shp.sessionId + INNER JOIN Person pe ON pe.personId = shp.personId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE pe.login = p_authLogin AND bls.containerId = p_containerId; + + ELSE + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + bs.visit_number "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN BLSession bs ON c.sessionId = bs.sessionId + INNER JOIN Proposal p ON p.proposalId = bs.proposalId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE bls.containerId = p_containerId; + + END IF; + + ELSE + + IF p_authLogin IS NOT NULL THEN + -- Authorise only if the person (p_authLogin) is a member of a session on the proposal. + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN Dewar d ON d.dewarId = c.dewarId + INNER JOIN Shipping s ON s.shippingId = d.shippingId + INNER JOIN Proposal p ON p.proposalId = s.proposalId + INNER JOIN BLSession bs ON bs.proposalId = p.proposalId + INNER JOIN Session_has_Person shp ON bs.sessionId = shp.sessionId + INNER JOIN Person pe ON pe.personId = shp.personId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE pe.login = p_authLogin AND bls.containerId = p_containerId; + + ELSE + + SELECT DISTINCT bls.blSampleId "sampleId", + pr.proteinId "materialId", + bls.containerId "containerId", + bls.diffractionPlanId "planId", + c.sessionId "sessionId", + p.proposalId "proposalId", + + bls.name "sampleName", + bls.code "sampleCode", + bls.volume "sampleVolume", + bls.dimension1 "thickness", + bls.comments "sampleComments", + bls.location "sampleLocation", + bls.subLocation "sampleSubLocation", + bls.blSampleStatus "sampleStatus", + + pr.name "materialName", + pr.acronym "materialAcronym", + pr.sequence "materialFormula", + pr.density "materialDensity", + pr.safetyLevel "materialSafetyLevel", -- enum(GREEN, YELLOW, RED) + pr.description "materialChemicalDescription", + pr.molecularMass "materialMolecularMass", + compt.name "materialType", -- protein, DNA, RNA, small molecule, ... + conct.name "materialConcentrationType", + pr.isotropy "materialIsotropy", -- enum('isotropic','anisotropic') + + et.name "planExperimentType", + pc.name "planPurificationColumn", + plan.robotPlateTemperature "planRobotPlateTemperature", + plan.exposureTemperature "planExposureTemperature", + plan.transmission "planTransmission", + + p.proposalCode "proposalCode", + p.proposalNumber "proposalNumber", + NULL "sessionNumber" + FROM BLSample bls + INNER JOIN Container c ON c.containerId = bls.containerId + INNER JOIN Dewar d ON d.dewarId = c.dewarId + INNER JOIN Shipping s ON s.shippingId = d.shippingId + INNER JOIN Proposal p ON p.proposalId = s.proposalId + LEFT JOIN Crystal cr ON cr.crystalId = bls.crystalId + LEFT JOIN Protein pr ON pr.proteinId = cr.proteinId + LEFT JOIN ComponentType compt ON compt.componentTypeId = pr.componentTypeId + LEFT JOIN ConcentrationType conct ON conct.concentrationTypeId = pr.concentrationTypeId + LEFT JOIN DiffractionPlan plan ON plan.diffractionPlanId = bls.diffractionPlanId + LEFT JOIN ExperimentType et ON et.experimentTypeId = plan.experimentTypeId AND et.proposalType = 'scm' + LEFT JOIN PurificationColumn pc ON pc.purificationColumnId = plan.purificationColumnId + WHERE bls.containerId = p_containerId; + + END IF; + + END IF; + + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument p_containerId can not be NULL'; + END IF; + +END;; + +DELIMITER ; \ No newline at end of file