54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
|
|
|
||
|
|
# datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
|
||
|
|
import firebase_admin
|
||
|
|
from firebase_admin import credentials, firestore
|
||
|
|
import os
|
||
|
|
from google.cloud.firestore_v1.base_query import FieldFilter
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
key_path = os.getcwd() + '/keys/hpos-qa-firebase-adminsdk.json'
|
||
|
|
cred = credentials.Certificate(key_path)
|
||
|
|
firebase_admin.initialize_app(cred)
|
||
|
|
|
||
|
|
def classify(calculatedRatio):
|
||
|
|
if calculatedRatio < 0.05:
|
||
|
|
return "Inconclusive. Very low Absorbance - Repeat test with Higher Blood Volume"
|
||
|
|
if calculatedRatio > 0.05 and calculatedRatio < 0.155:
|
||
|
|
return "Normal"
|
||
|
|
if calculatedRatio > 0.155 and calculatedRatio < 0.175:
|
||
|
|
return "Negative Borderline. Repeat Test"
|
||
|
|
if calculatedRatio > 0.175 and calculatedRatio < 0.22:
|
||
|
|
return "Sickle Cell Trait"
|
||
|
|
if calculatedRatio > 0.22 and calculatedRatio < 0.25:
|
||
|
|
return "Positive for Sickle Cell. HPLC for Confirmation"
|
||
|
|
if calculatedRatio > 0.25 and calculatedRatio < 0.35:
|
||
|
|
return "Sickle Cell Disease"
|
||
|
|
if calculatedRatio > 0.35:
|
||
|
|
return "Inconclusive. Repeat with test with lower volume of blood"
|
||
|
|
|
||
|
|
def update_coefficent(source_collection):
|
||
|
|
db = firestore.client()
|
||
|
|
|
||
|
|
docs = db.collection(source_collection).where(filter = FieldFilter("deviceId", "==", "HC-V1-003")).stream()
|
||
|
|
|
||
|
|
for doc in docs:
|
||
|
|
doc_id = doc.id #doc.to_dict()["_id"]
|
||
|
|
print(doc_id)
|
||
|
|
|
||
|
|
slope = 0.5453
|
||
|
|
intercept = 0.0099
|
||
|
|
calculatedRatio = slope * doc.to_dict()["deviceRatio"] + intercept
|
||
|
|
|
||
|
|
try:
|
||
|
|
db.collection(source_collection).document(doc_id).update({
|
||
|
|
"coefficients": [slope, intercept],
|
||
|
|
"calculatedRatio": calculatedRatio,
|
||
|
|
"classificationResult": classify(calculatedRatio)
|
||
|
|
})
|
||
|
|
print(f"Document with ID '{doc_id}' updated")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Error updating document with ID '{doc_id}' from the source collection: {e}")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
update_coefficent("testData")
|