Skip to content

Commit

Permalink
Merge pull request #400 from NaturalSolutions/development
Browse files Browse the repository at this point in the history
Up version Master with development branch
  • Loading branch information
romfabbro committed Jan 12, 2017
2 parents 78ae379 + b25afe3 commit 6b12228
Show file tree
Hide file tree
Showing 279 changed files with 13,764 additions and 18,178 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Front/app/styles/_perso.less
Front/app/styles/img/perso/*

Back/build/*
Back/pserve*

**/config.js

Expand All @@ -30,3 +31,9 @@ Back/build/*
npm-debug.log
web.config
**/init.text
.idea/*
.vscode/*
Front/path_vars_backup2016-11-28_15h29m05s.txt
Front/path_vars_backup2016-11-28_15h29m05s.json

Back/init.txt
3 changes: 2 additions & 1 deletion Back/database/Pipe/DB_Mother/091_ERD_SP_SendData.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ GO




INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('91_ERD_SP_SendData',GETDATE(),(SELECT db_name()))


GO


33 changes: 21 additions & 12 deletions Back/database/Pipe/DB_Mother/092_ERD_CreateMessage_for_eColl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ GO





ALTER PROCEDURE [dbo].[pr_MessageExportProtoEntomo]
(
@ProtocoleID INT = NULL
Expand All @@ -19,7 +17,7 @@ BEGIN

BEGIN TRY
BEGIN TRAN
--DECLARE @ProtocoleID INT SET @ProtocoleID= NULL

IF OBJECT_ID('tempdb..#ProtocoleID') IS NOT NULL
DROP TABLE #ProtocoleID
Expand Down Expand Up @@ -60,7 +58,7 @@ BEGIN
FROM Station S
JOIN Observation O on o.FK_Station = s.ID
JOIN ProtocoleType PT ON o.FK_ProtocoleType = PT.ID AND PT.Name ='Entomo_Pop_Census'
JOIN ObservationDynPropValuesNow v ON v.FK_Observation = o.ID and v.Name = 'sampled' and v.ValueInt=1




Expand Down Expand Up @@ -133,22 +131,23 @@ BEGIN
)
OUTPUT INSERTED.pk_MessageSend INTO #MessageIDs
SELECT Pt.Name,o.id,dbo.GetProvenance() + '_' + convert(varchar,o.ID),'Create',getdate(),NULL,NULL
FROM Observation O JOIN ProtocoleType PT ON o.FK_ProtocoleType = PT.ID AND PT.Name ='Entomo_Pop_Census'
WHERE o.ID IN (select ID FROM #ProtocoleID)


FROM Observation O
JOIN ProtocoleType PT ON o.FK_ProtocoleType = PT.ID AND PT.Name ='Entomo_Pop_Census'
JOIN ObservationDynPropValuesNow v ON v.FK_Observation = o.ID and v.Name = 'sampled' and v.ValueInt=1
WHERE o.ID IN (select ID FROM #ProtocoleID)

INSERT INTO [dbo].[TMessageSendDetail]
([fk_MessageSend]
,[PropName]
,[PropValue]
,[Parametre])
select m.pk_MessageSend,C.PropName,PropValue,NULL
from Observation O JOIN [TMessageSend] M on m.[ObjectId] = O.ID
from Observation O
JOIN [TMessageSend] M on m.[ObjectId] = O.ID
CROSS APPLY
(
values
('ECol_id',replace(convert(varchar,O.original_id),'Fichier_Alex_ss_Prot_',''))
('ECol_id',Case WHEN o.original_id like 'Ecol_%' THEN replace(convert(varchar,O.original_id),'Ecol_','') ELSE NULL END )
,('Comments',O.Comments)
,('FK_Station',convert(varchar,O.FK_Station))

Expand All @@ -162,10 +161,15 @@ BEGIN
,[PropName]
,[PropValue]
,[Parametre])
SELECT m.pk_MessageSend,v.Name,CASE WHEN TYPEPROP ='STring' THEN ValueString WHEN Typeprop ='Integer' THEN convert(varchar,valueint) ELSE ValueString END,NULL
FROM ObservationDynPropValuesNow V JOIN [TMessageSend] M on convert(int,m.[ObjectId]) = V.FK_Observation
SELECT distinct m.pk_MessageSend,v.Name,CASE WHEN TYPEPROP ='STring' THEN ValueString WHEN Typeprop ='Integer' THEN convert(varchar,valueint) ELSE ValueString END,NULL
FROM ObservationDynPropValuesNow V
JOIN [TMessageSend] M on convert(int,m.[ObjectId]) = V.FK_Observation
WHERE M.pk_MessageSend in (SELECT ID FROM #MessageIDs)



---SELECT * FROM TMessageSend WHERE pk_MessageSend = 748436

print 'COMMIT TRAN'
IF @@TRANCOUNT > 0 COMMIT TRAN

Expand Down Expand Up @@ -195,6 +199,11 @@ END




GO


INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('092_ERD_CreateMessage_for_eColl',GETDATE(),(SELECT db_name()))


GO
128 changes: 79 additions & 49 deletions Back/database/Pipe/DB_Mother/093_SP_IN_eColl_ImportMessageFromERD.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



Expand Down Expand Up @@ -98,43 +94,60 @@ BEGIN

--SET IDENTITY_INSERT [Samples] ON


INSERT INTO [Samples]
(--ID,
[Original_Id]
,[Status]
,[Name]
,[Tampon]
,[CreationDate]
,[SampleDate]
,[Container]
,[Holder]
,[Position]
,[Comment]
,[ParentSample_ID]
,[Subject_ID]
,[TypeObj_ID]
,Qte)

SELECT DISTINCT /*convert(bigint,DID.PropValue) ID, */m.Provenance + '_' + convert(varchar,m.ObjectId),2,'','',getdate(),SV.ValueDate,NULL,NULL,NULL,DCo.PropValue,NULL,S.ID,ST.ID,convert(INT,DNb.PropValue)


UPDATE S SET S.ORiginal_ID = m.Provenance + '_' + convert(varchar,m.ObjectId)
FROM TMessageReceived M
JOIN TMessageReceivedDetail DID ON M.pk_MessageReceived=DID.fk_MessageReceived and DID.PropName = 'ECol_id' and DID.Provenance = m.Provenance and DID.PropValue IS NOT NULL
JOIN TMessageReceivedDetail DSta ON M.pk_MessageReceived=DSta.fk_MessageReceived and DSta.PropName = 'FK_Station' and DSta.Provenance = m.Provenance
JOIN TMessageReceivedDetail DCo ON M.pk_MessageReceived=DCo.fk_MessageReceived and DCo.PropName = 'Comments' and DCo.Provenance = m.Provenance
JOIN TMessageReceivedDetail DNb ON M.pk_MessageReceived=DNb.fk_MessageReceived and DNb.PropName = 'number' and DNb.Provenance = m.Provenance
JOIN Subjects S ON s.Original_Id = M.Provenance + '_' + DSta.PropValue
JOIN SampleTypes ST ON ST.Name = CASE WHEN convert(INT,DNb.PropValue) >1 THEN 'Group' ELSE 'Individual' END
LEFT JOIN SubjectDynPropValuesNow SV ON SV.Subject_ID = s.id and SV.Name ='StationDate'
JOIN TMessageReceivedDetail ecol ON M.pk_MessageReceived = ecol.fk_MessageReceived AND ecol.PropName = 'ecol_ID' AND ecol.Provenance = m.Provenance AND ecol.PropValue is NOT null
JOIN Samples S ON S.ID = ecol.PropValue
WHERE M.ObjectType ='Entomo_Pop_Census' AND m.Provenance like 'EcoReleve_%'
AND Importdate IS NULL
AND NOT EXISTS (SELECT * FROM Samples ES WHERE ES.original_ID = m.Provenance + '_' + convert(varchar,m.ObjectId))
--AND NOT EXISTS (SELECT * FROM Samples ES WHERE ES.original_ID = m.Provenance + '_' + convert(varchar,m.ObjectId))

IF OBJECT_ID('tempdb..#tempSampleID') IS NOT NULL
Drop table #tempSampleID

Create table #tempSampleID (ID int)

--INSERT INTO [Samples]
-- (--ID,
-- [Original_Id]
-- ,[Status]
-- ,[Name]
-- ,[Tampon]
-- ,[CreationDate]
-- ,[SampleDate]
-- ,[Container]
-- ,[Holder]
-- ,[Position]
-- ,[Comment]
-- ,[ParentSample_ID]
-- ,[Subject_ID]
-- ,[TypeObj_ID]
-- ,Qte)
--OUTPUT inserted.ID into #tempSampleID

--SELECT DISTINCT /*convert(bigint,DID.PropValue) ID, */m.Provenance + '_' + convert(varchar,m.ObjectId),2,'','',getdate(),SV.ValueDate,NULL,NULL,NULL,DCo.PropValue,NULL,S.ID,ST.ID,convert(INT,DNb.PropValue)
--FROM TMessageReceived M
--JOIN TMessageReceivedDetail DID ON M.pk_MessageReceived=DID.fk_MessageReceived and DID.PropName = 'ECol_id' and DID.Provenance = m.Provenance and DID.PropValue IS NOT NULL
--JOIN TMessageReceivedDetail DSta ON M.pk_MessageReceived=DSta.fk_MessageReceived and DSta.PropName = 'FK_Station' and DSta.Provenance = m.Provenance
--JOIN TMessageReceivedDetail DCo ON M.pk_MessageReceived=DCo.fk_MessageReceived and DCo.PropName = 'Comments' and DCo.Provenance = m.Provenance
--JOIN TMessageReceivedDetail DNb ON M.pk_MessageReceived=DNb.fk_MessageReceived and DNb.PropName = 'number' and DNb.Provenance = m.Provenance
--JOIN Subjects S ON s.Original_Id = M.Provenance + '_' + DSta.PropValue
--JOIN SampleTypes ST ON ST.Name = CASE WHEN convert(INT,DNb.PropValue) >1 THEN 'Group' ELSE 'Individual' END
--LEFT JOIN SubjectDynPropValuesNow SV ON SV.Subject_ID = s.id and SV.Name ='StationDate'
--WHERE M.ObjectType ='Entomo_Pop_Census' AND m.Provenance like 'EcoReleve_%'
--AND Importdate IS NULL
--AND NOT EXISTS (SELECT *
-- FROM Samples ES
-- WHERE ES.original_ID = m.Provenance + '_' + convert(varchar,m.ObjectId)
-- )


--SET IDENTITY_INSERT [Samples] OFF


-- CREATION DES SAMPLES SANS ID

INSERT INTO [Samples]
([Original_Id]
,[Status]
Expand All @@ -150,11 +163,13 @@ BEGIN
,[Subject_ID]
,[TypeObj_ID]
,Qte)
OUTPUT inserted.ID into #tempSampleID
SELECT DISTINCT m.Provenance + '_' + convert(varchar,m.ObjectId),2,'','',getdate(),SV.ValueDate,NULL,NULL,NULL,DCo.PropValue,NULL,S.ID,ST.ID,convert(INT,DNb.PropValue)
FROM TMessageReceived M
JOIN TMessageReceivedDetail DSta ON M.pk_MessageReceived=DSta.fk_MessageReceived and DSta.PropName = 'FK_Station' and DSta.Provenance = m.Provenance
JOIN TMessageReceivedDetail DCo ON M.pk_MessageReceived=DCo.fk_MessageReceived and DCo.PropName = 'Comments' and DCo.Provenance = m.Provenance
JOIN TMessageReceivedDetail DNb ON M.pk_MessageReceived=DNb.fk_MessageReceived and DNb.PropName = 'number' and DNb.Provenance = m.Provenance --and DNb.PropValue is not null
JOIN TMessageReceivedDetail ecol ON M.pk_MessageReceived = ecol.fk_MessageReceived AND ecol.PropName = 'ecol_ID' AND ecol.Provenance = m.Provenance AND ecol.PropValue is null
JOIN Subjects S ON s.Original_Id = M.Provenance + '_' + DSta.PropValue
JOIN SampleTypes ST ON ST.Name = CASE WHEN convert(INT,DNb.PropValue) >1 THEN 'Group' ELSE 'Individual' END
LEFT JOIN SubjectDynPropValuesNow SV ON SV.Subject_ID = s.id and SV.Name ='StationDate'
Expand All @@ -163,7 +178,6 @@ BEGIN
AND NOT EXISTS (SELECT * FROM Samples ES WHERE ES.original_ID = m.Provenance + '_' + convert(varchar,m.ObjectId))



---- Get originalspecies
--originalSpecies
INSERT INTO [SampleDynPropValues]
Expand All @@ -178,11 +192,13 @@ BEGIN
SELECT DISTINCT GETDATE(),NULL,NULL,D.PropValue,NULL,NULL,S.ID,DP.ID
FROM TMessageReceived M
JOIN Samples S on S.Original_Id = m.Provenance + '_' + convert(varchar,m.ObjectId)
JOIN #tempSampleID tp on tp.ID = s.ID
JOIN TMessageReceivedDetail D ON M.pk_MessageReceived=D.fk_MessageReceived and d.Provenance = m.Provenance
JOIN SampleDynProps DP ON DP.Name in ('determinatedSpecies')
WHERE Importdate IS NULL AND M.ObjectType ='Entomo_Pop_Census' AND m.Provenance like 'EcoReleve_%'
and d.PropName = 'taxon'
AND m.isMessageComplete = 1
AND m.isMessageComplete = 1
--AND NOT EXISTS (SELECT * FROM Samples ES WHERE ES.original_ID = m.Provenance + '_' + convert(varchar,m.ObjectId))
order by s.ID,DP.ID

INSERT INTO [SampleDynPropValues]
Expand All @@ -197,12 +213,14 @@ BEGIN
SELECT GETDATE(),NULL,NULL,D.PropValue,NULL,NULL,S.ID,Case WHEN DP.ID is NULL THEN (SELECT ID FROM SampleDynProps WHERE Name = 'Age') ELSE DP.ID END
FROM TMessageReceived M
JOIN Samples S on S.Original_Id = m.Provenance + '_' + convert(varchar,m.ObjectId)
JOIN #tempSampleID tp on tp.ID = s.ID
JOIN TMessageReceivedDetail D ON M.pk_MessageReceived=D.fk_MessageReceived and d.Provenance = m.Provenance
LEFT JOIN SampleDynProps DP ON dp.name = D.PropName
WHERE --Importdate IS NULL AND
WHERE Importdate IS NULL AND
M.ObjectType ='Entomo_Pop_Census' AND m.Provenance like 'EcoReleve_%'
and d.PropName in ('Stade','Sex')
AND m.isMessageComplete = 1
--AND NOT EXISTS (SELECT * FROM Samples ES WHERE ES.original_ID = m.Provenance + '_' + convert(varchar,m.ObjectId))
order by s.ID,DP.ID

-- TODO Créer un Event
Expand All @@ -215,7 +233,8 @@ BEGIN
,Sample_ID BIGINT
)


select *
from #tempSampleID
INSERT INTO [dbo].[EcolEvents]
([Status]
,[Name]
Expand All @@ -227,11 +246,21 @@ BEGIN
,[TypeObj_ID]
,[SamplePositionHisto_ID])
OUTPUT inserted.ID,inserted.sample_id into #EventCreated
select 2,'',GETDATE(),CASE WHEN D.PropValue IS NULL THEN '' ELSE D.PropValue END,NULL,NULL,S.id,T.ID ,NULL
FROM TMessageReceived M
JOIN Samples S on S.Original_Id =m.Provenance + '_' + convert(varchar,m.ObjectId)
select 4,'',GETDATE(),1,NULL,NULL,tp.id,T.ID ,NULL
FROM #tempSampleID tp
JOIN EcolEventtypes T ON T.Name ='Imported'
JOIN TMessageReceivedDetail D ON D.fk_MessageReceived = m.pk_MessageReceived and D.PropName='Identified_by'


--TMessageReceived M
--JOIN Samples S on S.Original_Id =m.Provenance + '_' + convert(varchar,m.ObjectId)
--JOIN EcolEventtypes T ON T.Name ='Imported'
----LEFT JOIN TMessageReceivedDetail D ON D.fk_MessageReceived = m.pk_MessageReceived and D.PropName='Identified_by'
--JOIN #tempSampleID tp on tp.ID = s.ID

select *
FROM #EventCreated

select count(*) FROM #tempSampleID

INSERT INTO [dbo].[EcolEventDynPropValues]
([StartDate]
Expand All @@ -242,16 +271,17 @@ BEGIN
,[ValueFloat]
,[EcolEvent_ID]
,[EcolEventDynProp_ID])

select getdate(),null,null,D.PropValue,NULL,NULL,C.Event_ID, DP.ID
from #EventCreated C JOIN Samples S on C.Sample_ID = S.ID
JOIN TMessageReceived M ON S.Original_Id = m.Provenance + '_' + convert(varchar,m.ObjectId)
JOIN TMessageReceivedDetail D ON D.fk_MessageReceived = m.pk_MessageReceived and D.PropName='taxon'
JOIN TMessageReceivedDetail D ON D.fk_MessageReceived = m.pk_MessageReceived and D.PropName='taxon' AND m.Provenance = d.Provenance
JOIN EcolEventDynProps DP ON DP.Name in ('species')

--UPDATE S
--SET Original_Id = m.ObjectOriginalID
--FROM Samples S JOIN TMessageReceived M ON S.Original_Id = CONVERT(varchar,m.ObjectID)
JOIN #tempSampleID tp on tp.ID = s.ID


UPDATE S
SET Original_Id = m.ObjectOriginalID
FROM Samples S JOIN TMessageReceived M ON S.Original_Id = CONVERT(varchar,m.ObjectID)



Expand Down Expand Up @@ -282,13 +312,13 @@ BEGIN
);
END CATCH
END
GO





INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('93_SP_IN_eColl_ImportMessageFromERD',GETDATE(),(SELECT db_name()))
GO

INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('93_SP_IN_eColl_ImportMessageFromERD',GETDATE(),(SELECT db_name()))

GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ALTER View [dbo].[allIndivLocationWithStations] as
(SELECT convert(varchar,l.[ID]) as ID
,[LAT]
,[LON]
,[Date]
,[type_]
,r.Region as region
,l.FK_Individual as FK_Individual
,NuLL as fieldActivity_Name
,l.Precision as precision
FROM [Individual_Location] l
LEFT JOIN Region r on r.ID = l.FK_Region

UNion ALL
SELECT 'sta_'+convert(varchar,o.FK_Station) as ID
,[LAT]
,[LON]
,StationDate as Date
,'station' as type_
,r.Region as region
,o.FK_Individual as FK_Individual
,fa.Name as fieldActivity_Name
,s.precision

FROM Station s
LEFT JOIN Region r on r.ID = s.FK_Region
LEFT JOIN fieldActivity fa on fa.ID = s.fieldActivityId
JOIN Observation o ON o.FK_Station = s.ID
group by o.FK_Station
,[LAT]
,[LON]
,StationDate
,r.Region
,o.FK_Individual
,fa.Name
,s.precision
)


GO



INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('95_Add_precision_to_VallindivLocation',GETDATE(),(SELECT db_name()))


GO
Loading

0 comments on commit 6b12228

Please sign in to comment.