Machine Performance Check

307 views
Skip to first unread message

David Sinn

unread,
Mar 12, 2021, 11:37:02 AM3/12/21
to QATrack+
Hello,

Has anyone tried bringing MPC values into QATrack+?  MPC results are automatically saved to the I: Drive and I'm wondering if anyone has done the leg work of doing some sort of auto import into QATrack+.

Thanks in advance.

Jonathan Dysart

unread,
Mar 12, 2021, 12:07:58 PM3/12/21
to QATrack+
Yes, We have been pulling in the MPC results to store them in QATrack+. 

I can't say my solution is the most elegant, but it has been working fine for 3+ years. The basic workflow is a yes/no button that when the user selects 'Yes' the appropriate file for the work started date and unit is searched and parsed for the values. MPC results are stored in .CSV files with a standard naming system, the code looks up the correct file and reads the data and stores it as a string. 
Capture.PNG

The code in the 'MPC Import', where the custom code lives in the mpc_pull_27.py file: 
from mpc.mpc_pull_27 import mpc_data
unit=str(META["unit_number"])
s_date=str(META["work_started"])
if get_mpc:
    mpc_import=mpc_data(unit,s_date)
else:
    mpc_import="pending"

To access the value for each test:
s=mpc_import.split(';')
mpc_dict = dict(item.split(",") for item in s)
mpc_iso_size = mpc_dict['IsoCenterSize [mm]']

The custom code for mpc_pull_27.py:
import glob
import csv
import os, sys
import pandas as pd
from pathlib import Path #instead of glob?

# J. Dysart, SJRH, jon.d...@horizonnb.ca
# This  function returns a string variable containing Varian's MPC QA results
# with the input parameters of treatment unit and test Day
# Function is called from QATrack+ (tested using version 2.9.0)

def mpc_data(unit, date_string):
    #Import the unit name, return the latest Varian MPC geometry results as csv string
    #unit = "H192128" = Edge 2128
    
    # Match the QAT+ machine name with the Varian name of maching in TDS folder path. 
    unit_id =  ['2128'] # For qatrack+
    mpc_linac_id = ["H192128"]  
    unit_string=mpc_linac_id[unit_id.index(unit)]
    
    
    # Format of date_string = '2016-11-06 18:03:00+00:00'
    get_date=date_string.split(" ")[0] # remove the time from date time

    # Root path to MPC data
    MPC_DB_PATH = r"//YOURSERVERNAME/VA_Transfer/TDS/"    
    
    os.system(r'net use w: /del')
    
if not os.path.isdir("w:"):
        os.system(r'NET USE w: \\YOURSERVERNAME  \VA_Transfer\TDS  /USER:R2\Varian YOURPASSWORD')
        print("Mapped drive to w:")
    
    
    # Get the latest 'Results.csv' file for the specified machine for date requested.
    try:
        path_match = f'w:{unit_string}/MPCChecks/*{get_date}*-GeometryCheckTemplate6xMVkV/Results.csv'
        csv_file = max(glob.glob(path_match))
        
        #check the file name if needed
        print('Found File: {}'.format(csv_file))

        ret_result = ''
        with open(csv_file, 'r', newline='', encoding='utf-8') as csvfile:
            csv_reader = csv.reader(csvfile, delimiter=',')
            for row in csv_reader:
                if 'MLCLeaf' not in row[0] and 'MLCBacklash' not in row[0]: # filter out this data
                    s = row[0].replace(u'\xb0','deg') # replace the degree symbol with 'deg'
                    fld = s.rpartition('/')[2]
                    ret_result += f'{fld},{row[1]};' # shorten the name of each data field, 1024 character limit in QAT+
        
    except Exception as e:
        print(f'Error: {e}')
        ret_result = f'Err: {str(e)[0:1015]}'

    finally:
        ret_result += mpc_data_optional(unit, date_string, '6xFFF') #add Beam data for 6xFFF and 10xFFF if completed on date.
        ret_result += mpc_data_optional(unit, date_string, '10xFFF')
        r=ret_result[:-1] # remove last semicolon
        print("Returning results:")
        print(r)
    
    # Delete the mapped drive (w:)
    os.system(r'net use w: /del')
    return r

def mpc_data_optional(unit, date_string, energy): #Get the Beam results for the optional beams if test performed that day
    
    #Import the unit name, return the latest Varian MPC geometry results as csv string
    #unit = "H192128" = Edge 2128
    # Match the QAT+ machine name with the Varian name of maching in TDS folder path. 
    unit_id =  ['2128'] # For qatrack+
    mpc_linac_id = ["H192128"]  
    unit_string=mpc_linac_id[unit_id.index(unit)]
    
    # Format of date_string = '2016-11-06 18:03:00+00:00'
    get_date=date_string.split(" ")[0] # remove the time from date time

    # Root path to MPC data
    MPC_DB_PATH = r"// YOURSERVERNAME  /VA_Transfer/TDS/"     
    
    # Get the latest 'Results.csv' file for the specified machine for date requested.
    try:
        # MPC version 1.1:
        #csv_file = (max(glob.glob(MPC_DB_PATH + unit_string + "/MPCChecks/*" + get_date + "*-" + energy + "-Beam/Results.csv")))
        # MPC Verrsion 2.2 (TruBeam 2.7):
        csv_file = (max(glob.glob(MPC_DB_PATH + unit_string + "/MPCChecks/*" + get_date + "*-BeamCheckTemplate" + energy + "/Results.csv")))
        #check the file name if needed
        
        ret_result = ''
        with open(csv_file, 'r', newline='', encoding='utf-8') as csvfile:
            csv_reader = csv.reader(csvfile, delimiter=',')
            for row in csv_reader:
                s=row[0].replace(u'\xb0','deg') # replace the degree symbol with 'deg'
                ret_result += s.rpartition('/')[2] + '-' + energy + ',' + row[1] + ';' # shorten the name of each data field, 1024 character limit in QAT+
    except:
        ret_result = energy + " , not done;"
    finally:
        return ret_result
        
        ## To get data from the string, the easiest way is to convert to Dictionary:
        #s=r.split(';')
        #mpc_dict = dict(item.split(",") for item in s)
        ## Lookup values by entering the property in dictionary. 
        #print mpc_dict['IsoCenterSize [mm]'] # as example

#used for testing function outside QAT+     
if __name__ == '__main__':
    unit = sys.argv[1]
    date_string = sys.argv[2]
    mpc_data(unit,date_string)

This should at least get you started. Good luck!
Jonathan

Randle Taylor

unread,
Mar 12, 2021, 1:15:24 PM3/12/21
to Jonathan Dysart, David Sinn, QATrack+
Hi Jonathan and David,

As we speak I am working on an application QCPump that is designed for grabbing data from various sources and uploading it to QATrack+ via the API.  It is currently working for pulling in Daily QA3 data from Firebird and SQLServer (Atlas) databases and I'm working on adding support for MPC data.  I should have an initial version of the MPC data retrieval ready for testing/feedback in a day or two.  The one major caveat is that it requires QATrack+ v3.1.0 because of recent changes to the API.

Randy

--
You received this message because you are subscribed to the Google Groups "QATrack+" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qatrack/41ab6c52-cc05-4505-a584-29b6e39b9513n%40googlegroups.com.

Dysart, Jon (HorizonNB)

unread,
Mar 12, 2021, 1:46:03 PM3/12/21
to Randle Taylor, Jonathan Dysart, David Sinn, QATrack+
That's great Randy, I'm sure it will be useful to many users. We also pull data from DQA3 with an SQL connection to the FB database using similar approach to the MPC test. 

Jonathan Dysart, Ph.D., mCCPM

Medical Physicist

Horizon Health Network / Réseau de santé Horizon

Saint John Regional Hospital

Saint John, New Brunswick, Canada

Phone: (506) 648-7410

jon.d...@HorizonNB.ca

www.HorizonNB.ca



From: qat...@googlegroups.com <qat...@googlegroups.com> on behalf of Randle Taylor <randle...@gmail.com>
Sent: Friday, March 12, 2021 2:14 PM
To: Jonathan Dysart <jon.d...@gmail.com>; David Sinn <sinn...@gmail.com>
Cc: QATrack+ <qat...@googlegroups.com>
Subject: Re: [QATrack+ 2249] Re: Machine Performance Check
 

ATTENTION! External email / courriel externe.

 

------- Horizon Health Network Disclaimer -------

This e-mail communication (including any or all attachments) is intended
only for the use of the person or entity to which it is addressed and may
contain confidential and/or privileged material. If you are not the intended
recipient of this e-mail, any use, review, retransmission, distribution,
dissemination, copying, printing, or other use of, or taking of any action in
reliance upon this e-mail, is strictly prohibited. If you have received this
e-mail in error, please contact the sender and delete the original and any
copy of this e-mail and any printout thereof, immediately. Your
co-operation is appreciated.

Le présent courriel (y compris toute pièce jointe) s'adresse uniquement à
son destinataire, qu'il soit une personne ou un organisme, et pourrait
comporter des renseignements privilégiés ou confidentiels. Si vous n'êtes
pas le destinataire du courriel, il est interdit d'utiliser, de revoir, de
retransmettre, de distribuer, de disséminer, de copier ou d'imprimer ce
courriel, d'agir en vous y fiant ou de vous en servir de toute autre façon.
Si vous avez reçu le présent courriel par erreur, prière de communiquer
avec l'expéditeur et d'éliminer l'original du courriel, ainsi que toute copie
électronique ou imprimée de celui-ci, immédiatement. Nous sommes
reconnaissants de votre collaboration.

David Sinn

unread,
Mar 18, 2021, 6:09:26 PM3/18/21
to QATrack+
Thanks everyone.  Looking forward to see what Randy comes up with!
Reply all
Reply to author
Forward
0 new messages