Med Cert generator API update
This commit is contained in:
@@ -29,6 +29,10 @@ class medCertUploud(BaseModel):
|
|||||||
app_id: str
|
app_id: str
|
||||||
fullName: str
|
fullName: str
|
||||||
docfname: str
|
docfname: str
|
||||||
|
busName: str
|
||||||
|
busAddr: str
|
||||||
|
busNo: str
|
||||||
|
busEmail: str
|
||||||
startDate: str
|
startDate: str
|
||||||
endDate: str
|
endDate: str
|
||||||
returnDate: str
|
returnDate: str
|
||||||
@@ -96,14 +100,15 @@ async def delete_File_of_user(requestItem: minioDeleteRequest, session: SessionC
|
|||||||
# Get List of all files by patient
|
# Get List of all files by patient
|
||||||
@router.post("/minio/generate/med-cert/", tags=["Minio"])
|
@router.post("/minio/generate/med-cert/", tags=["Minio"])
|
||||||
async def upload_File_to_user(requestItem: medCertUploud, session: SessionContainer = Depends(verify_session())):
|
async def upload_File_to_user(requestItem: medCertUploud, session: SessionContainer = Depends(verify_session())):
|
||||||
uploudMedCert(requestItem.app_id,
|
# uploudMedCert(requestItem.app_id,
|
||||||
requestItem.fullName,
|
# requestItem.fullName,
|
||||||
requestItem.docfname,
|
# requestItem.docfname,
|
||||||
requestItem.startDate,
|
# requestItem.startDate,
|
||||||
requestItem.endDate,
|
# requestItem.endDate,
|
||||||
requestItem.returnDate,
|
# requestItem.returnDate,
|
||||||
requestItem.logo_path,
|
# requestItem.logo_path,
|
||||||
requestItem.sig_path)
|
# requestItem.sig_path)
|
||||||
|
uploudMedCert(requestItem)
|
||||||
return {"message": "Successfully Generated File"}
|
return {"message": "Successfully Generated File"}
|
||||||
|
|
||||||
def uploudFile(app_id, folder, fileName, extension, content):
|
def uploudFile(app_id, folder, fileName, extension, content):
|
||||||
@@ -124,21 +129,25 @@ def uploudFile(app_id, folder, fileName, extension, content):
|
|||||||
|
|
||||||
|
|
||||||
#"minio""localhost:9000"
|
#"minio""localhost:9000"
|
||||||
def uploudMedCert(app_id, fullName, docfname, startDate, endDate, returnDate, logo_path, sig_path):
|
# def uploudMedCert(app_id, fullName, docfname, startDate, endDate, returnDate, logo_path, sig_path):
|
||||||
|
def uploudMedCert(requestItem: medCertUploud):
|
||||||
client = Minio_Storage.minioConnection.minioConnect("dev")
|
client = Minio_Storage.minioConnection.minioConnect("dev")
|
||||||
generateMedCertPDF(fullName, docfname, startDate, endDate, returnDate, logo_path, sig_path)
|
# generateMedCertPDF(fullName, docfname, startDate, endDate, returnDate, logo_path, sig_path)
|
||||||
|
generateMedCertPDF(requestItem)
|
||||||
|
today = datetime.today().strftime('%Y-%m-%d')
|
||||||
found = client.bucket_exists("mih")
|
found = client.bucket_exists("mih")
|
||||||
if not found:
|
if not found:
|
||||||
client.make_bucket("mih")
|
client.make_bucket("mih")
|
||||||
else:
|
else:
|
||||||
print("Bucket already exists")
|
print("Bucket already exists")
|
||||||
fileName = f"{app_id}/patient_files/Med-Cert-{fullName}-{startDate}.pdf"
|
fileName = f"{requestItem.app_id}/patient_files/Med-Cert-{requestItem.fullName}-{today}.pdf"
|
||||||
client.fput_object("mih", fileName, "temp.pdf")
|
client.fput_object("mih", fileName, "temp.pdf")
|
||||||
|
|
||||||
def generateMedCertPDF(fullName, docfname, startDate, endDate, returnDate, logo_path, sig_path):
|
# def generateMedCertPDF(fullName, docfname, startDate, endDate, returnDate, logo_path, sig_path):
|
||||||
|
def generateMedCertPDF(requestItem: medCertUploud):
|
||||||
client = Minio_Storage.minioConnection.minioConnect("dev")
|
client = Minio_Storage.minioConnection.minioConnect("dev")
|
||||||
new_logo_path = logo_path.replace(" ","-")
|
new_logo_path = requestItem.logo_path.replace(" ","-")
|
||||||
new_sig_path = sig_path.replace(" ","-")
|
new_sig_path = requestItem.sig_path.replace(" ","-")
|
||||||
minioLogo = client.get_object("mih", new_logo_path).read()
|
minioLogo = client.get_object("mih", new_logo_path).read()
|
||||||
imageLogo = ImageReader(io.BytesIO(minioLogo))
|
imageLogo = ImageReader(io.BytesIO(minioLogo))
|
||||||
minioSig = client.get_object("mih", new_sig_path).read()
|
minioSig = client.get_object("mih", new_sig_path).read()
|
||||||
@@ -146,40 +155,52 @@ def generateMedCertPDF(fullName, docfname, startDate, endDate, returnDate, logo_
|
|||||||
w,h = A4
|
w,h = A4
|
||||||
today = datetime.today().strftime('%d-%m-%Y')
|
today = datetime.today().strftime('%d-%m-%Y')
|
||||||
myCanvas = canvas.Canvas("temp.pdf", pagesize=A4)
|
myCanvas = canvas.Canvas("temp.pdf", pagesize=A4)
|
||||||
|
|
||||||
|
#Business Logo
|
||||||
|
myCanvas.drawImage(imageLogo, 50, h - 125,100,100, mask='auto')
|
||||||
|
|
||||||
|
#Business Details
|
||||||
|
myCanvas.setFont('Helvetica-Bold', 10)
|
||||||
|
myCanvas.drawRightString(w - 50,h - 40, f"Name: {requestItem.busName}")
|
||||||
|
myCanvas.drawRightString(w - 50,h - 55, f"Address: {requestItem.busAddr}")
|
||||||
|
myCanvas.drawRightString(w - 50,h - 70, f"Contact No.: {requestItem.busNo}")
|
||||||
|
myCanvas.drawRightString(w - 50,h - 85, f"Email: {requestItem.busEmail}")
|
||||||
|
myCanvas.line(50,h-150,w-50,h-150)
|
||||||
|
#Todays Date
|
||||||
myCanvas.setFont('Helvetica', 12)
|
myCanvas.setFont('Helvetica', 12)
|
||||||
myCanvas.drawString(w - 100,h - 50,today)
|
issueDate = str(today)
|
||||||
# with open('temp_logofile', 'wb') as file_data:
|
myCanvas.drawRightString(w - 50,h - 180,issueDate)
|
||||||
# for data in minioLogo:
|
|
||||||
# file_data.write(data)
|
#Title
|
||||||
#myCanvas.drawImage(imageLogo, 50, h - 150,100,100)
|
|
||||||
#file_data.close()
|
|
||||||
myCanvas.setFont('Helvetica-Bold', 20)
|
myCanvas.setFont('Helvetica-Bold', 20)
|
||||||
myCanvas.drawString(w-375, h - 100, "Medical Certificate")
|
myCanvas.drawString(w-375, h - 200, "Medical Certificate")
|
||||||
|
|
||||||
|
#Body
|
||||||
myCanvas.setFont('Helvetica', 12)
|
myCanvas.setFont('Helvetica', 12)
|
||||||
line1 = "This is to certify that " + fullName.upper() + " was seen by " + docfname.upper() + " on " + startDate + "."
|
line1 = "This is to certify that " + requestItem.fullName.upper() + " was seen by " + requestItem.docfname.upper() + " on " + requestItem.startDate + "."
|
||||||
line2 = "He/She is unfit to attend work/school from " + startDate + " up to and including " + endDate + "."
|
line2 = "He/She is unfit to attend work/school from " + requestItem.startDate + " up to and including " + requestItem.endDate + "."
|
||||||
line3 = "He/She will return on " + returnDate + "."
|
line3 = "He/She will return on " + requestItem.returnDate + "."
|
||||||
|
|
||||||
myCanvas.drawString(50, h-150,line1)
|
myCanvas.drawString(50, h-250,line1)
|
||||||
myCanvas.drawString(50, h-180,line2)
|
myCanvas.drawString(50, h-280,line2)
|
||||||
myCanvas.drawString(50, h-210,line3)
|
myCanvas.drawString(50, h-310,line3)
|
||||||
|
|
||||||
|
#Signature
|
||||||
|
myCanvas.drawImage(imageSig, 50, h - 690,100,100)
|
||||||
|
myCanvas.line(50,h-700,200,h-700)
|
||||||
|
myCanvas.drawString(50, h-720, requestItem.docfname.upper())
|
||||||
|
|
||||||
#myCanvas.drawImage(imageSig, 50, h - 330,100,100)
|
#QR Verification
|
||||||
myCanvas.line(50,h-430,200,h-430)
|
qrText = requestItem.fullName.upper() + " booked off from " + requestItem.startDate + " to " + requestItem.endDate + " by " + requestItem.docfname.upper() + ".\nPowered by Mzansi Innovation Hub."
|
||||||
myCanvas.drawString(50, h-450, docfname.upper())
|
|
||||||
|
|
||||||
qrText = fullName.upper() + " booked off from " + startDate + " to " + endDate + " by " + docfname.upper() + ".\nPowered by Mzansi Innovation Hub."
|
|
||||||
qrText = qrText.replace(" ","+")
|
qrText = qrText.replace(" ","+")
|
||||||
|
|
||||||
url = f"https://api.qrserver.com/v1/create-qr-code/?data={qrText}&size=100x100"
|
url = f"https://api.qrserver.com/v1/create-qr-code/?data={qrText}&size=100x100"
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
image = ImageReader(io.BytesIO(response.content))
|
image = ImageReader(io.BytesIO(response.content))
|
||||||
myCanvas.drawImage(image,50, h-700,100,100)
|
myCanvas.drawImage(image,w-150, h-700,100,100)
|
||||||
|
|
||||||
myCanvas.setFont('Helvetica-Bold', 15)
|
myCanvas.setFont('Helvetica-Bold', 15)
|
||||||
myCanvas.drawString(50,h-720,"Scan to verify")
|
myCanvas.drawString(w-150,h-720,"Scan to verify")
|
||||||
|
|
||||||
myCanvas.save()
|
myCanvas.save()
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user