Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

New back with rfid import #709

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@


ALTER PROCEDURE [dbo].[pr_checkValidatedLocationOnEquipmentProtocol]
@obsID int,
@FK_Sensor int,
@FK_Individual int,
@result int OUTPUT
AS


SET NOCOUNT ON
SET @result = NULL
DECLARE @StartDate datetime;
DECLARE @EndDate datetime;
DECLARE @stationDate datetime;
DECLARE @FK_MonitoredSite int;
--DECLARE @FK_Sensor int;
--DECLARE @FK_Individual int;

select @stationDate=StationDate, @FK_MonitoredSite=FK_MonitoredSite
FROM Station s
WHERE EXISTS (SELECT *
FROM Observation o where o.FK_Station = s.ID AND o.ID = @obsID)

IF @FK_Sensor IS NULL
BEGIN
SELECT @FK_Sensor = ValueInt
FROM ObservationDynPropValuesNow
WHERE FK_Observation = @obsID
AND Name = 'FK_Sensor'
END

SELECT @FK_Individual = FK_Individual
FROM Observation o where o.ID = @obsID

select @StartDate = StartDate , @EndDate = EndDate
from SensorEquipment
where FK_Sensor = @FK_sensor
and (@stationDate >= StartDate and (EndDate is null or @stationDate <= EndDate ) )


SELECT @result = 1 WHERE EXISTS (SELECT * FROM Individual_Location
WHERE date >= @stationDate
and (@EndDate is null or date <= @EndDate )
--AND ISNULL(FK_Individual, '') = IS@FK_Individual
AND FK_sensor = @FK_sensor )




GO


ALTER PROCEDURE [dbo].[pr_checkValidatedLocationOnEquipmentProtocolUpdate]
@obsID int,
@newFk_Sensor int,
@newFK_Indiv int,
@result int OUTPUT
AS
BEGIN

SET NOCOUNT ON
DECLARE
@StartDate datetime,
@EndDate datetime,
@stationDate datetime,
@FK_Sensor int,
@Fk_Individual int,
@FK_MonitoredSite int


SELECT @FK_Sensor = ValueInt
FROM ObservationDynPropValuesNow
WHERE FK_Observation = @obsID
AND Name = 'FK_Sensor'

SELECT @Fk_Individual = FK_Individual
FROM Observation
WHERE ID = @obsID

IF @Fk_Individual IS NULL
SET @Fk_Individual = 0

IF @newFK_Indiv IS NULL
SET @newFK_Indiv = 0

IF (@FK_Individual != @newFK_Indiv OR @FK_Sensor != @newFk_Sensor)
BEGIN

select @stationDate=StationDate, @FK_MonitoredSite=FK_MonitoredSite
FROM Station s
WHERE EXISTS (SELECT *
FROM Observation o where o.FK_Station = s.ID AND o.ID = @obsID)

select @StartDate = StartDate , @EndDate = EndDate
from SensorEquipment
where FK_Sensor = @FK_sensor
and (@stationDate >= StartDate and (EndDate is null or @stationDate <= EndDate ) )


SELECT @result = 1 WHERE EXISTS (select *from Individual_Location where
date >= @StartDate
and (@EndDate is null or date <= @EndDate )
and FK_sensor = @FK_sensor )
END

--SELECT @result

END

GO

UPDATE [BusinessRules] set params = '["ID","FK_Sensor","FK_Individual"]'
WHERE name = 'Disable_Delete_Protocole_Equipment'

GO

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


GO
46 changes: 45 additions & 1 deletion Back/ecoreleve_server/Views/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
import json
from datetime import datetime
from sqlalchemy import select, join, desc
from sqlalchemy import select, join, desc, not_
from collections import OrderedDict
from ..controllers.security import RootCore, Resource, SecurityRoot, context_permissions
from . import DynamicObjectView, DynamicObjectCollectionView, DynamicObjectValue, DynamicObjectValues
Expand All @@ -34,6 +34,50 @@ class IndividualValuesView(DynamicObjectValues):
model = IndividualDynPropValue
item = IndividualValueView

def retrieve(self):
from ..utils.parseValue import formatThesaurus

propertiesTable = Base.metadata.tables[self.parent.objectDB.GetDynPropTable()]
dynamicValuesTable = Base.metadata.tables[self.parent.objectDB.GetDynPropValuesTable()]
FK_name = self.parent.objectDB.GetSelfFKNameInValueTable()
FK_property_name = self.parent.objectDB.GetDynPropFKName()

tableJoin = join(dynamicValuesTable, propertiesTable,
dynamicValuesTable.c[FK_property_name] == propertiesTable.c['ID'])
query = select([dynamicValuesTable, propertiesTable.c['Name']]
).select_from(tableJoin).where(
dynamicValuesTable.c[FK_name] == self.parent.objectDB.ID
)

query = query.where(not_(propertiesTable.c['Name'].in_(['Release_Comments',
'Breeding ring kept after release',
'Box_ID',
'Date_Sortie',
'Poids']))
).order_by(desc(dynamicValuesTable.c['StartDate']))

result = self.session.execute(query).fetchall()
response = []

for row in result:
curRow = OrderedDict(row)
dictRow = {}
for key in curRow:
if curRow[key] is not None:
if key == 'ValueString' in key and curRow[key] is not None:
try:
thesauralValueObj = formatThesaurus(curRow[key])
dictRow['value'] = thesauralValueObj['displayValue']
except:
dictRow['value'] = curRow[key]
elif 'FK' not in key:
dictRow[key] = curRow[key]
dictRow['StartDate'] = curRow[
'StartDate'].strftime('%Y-%m-%d %H:%M:%S')
response.append(dictRow)

return response


class IndividualView(DynamicObjectView):
model = Individual
Expand Down
Loading