def jqmobile_station_summary(request,clinic_id): #clinic = get_object_or_404(Clinic,id = clinic_id) stations = [] clinic = Clinic.objects.get(id = clinic_id) dtStart, dtEnd = get_request_period(request,clinic) eshs = EventSetHeader.objects.filter(clinic = clinic).exclude(dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) response = get_aggr_patients(eshs) event_map = get_clinic_event_map(clinic_id) for event in event_map: e=Event.objects.get(name = event[1]) if response.has_key(event[1]): count,avg_time = response.get(event[1]) stations.append((e.id,event[1],count,avg_time)) else: stations.append((e.id,event[1],0,0)) datas = { 'clinic_event_map': event_map } return render_to_response('jqmobile/stationsummary.html',{'stations':stations})
def jqmtab_payment(request): ansDict = dict() ansDict['menu'] = 'paymenthistory' ansDict['left_menu'] = Clinic.objects.all() # ansDict["date"] = request.REQUEST.get("date_in_frontdesk",None) #if not request.REQUEST.has_key("clinicID"): #ansDict['work_time'] = get_current_worktime() #ansDict['clinics'] = get_current_clinics() #return direct_to_template(request,'payment-base.html',ansDict) clinic = get_object_or_404(Clinic.objects, id=request.REQUEST.get("clinicID", None)) ''' dt = datetime.datetime.now() dtStart = datetime.datetime(dt.year,dt.month,dt.day,0,0,0) dayAddDelta = datetime.timedelta(1) dtEnd = dtStart + dayAddDelta ''' dtStart, dtEnd = get_request_period(request, clinic) eshs = EventSetHeader.objects.filter(clinic=clinic).exclude( dateTime__gte=dtEnd).filter(dateTime__gte=dtStart).order_by("dateTime") total = {} total['cash'] = reduce(lambda a, b: a + b.get_cash(), eshs, 0.0) total['cc'] = reduce(lambda a, b: a + b.get_cc(), eshs, 0.0) total['total'] = total['cash'] + total['cc'] ansDict['total'] = total ansDict['clinic'] = clinic ansDict['events'] = eshs return direct_to_template(request, 'jqmtab/jqmtab_payment_page.html', ansDict)
def jqmobile_event_patient_summary(request, clinic_id, event_id): ''' List the patients specific to an event under a clinic. ''' clinic = Clinic.objects.get(id=clinic_id) event = Event.objects.get(id=event_id) dtStart, dtEnd = get_request_period(request, clinic) eshs = EventSetHeader.objects.filter(clinic=clinic).exclude( dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) patient_list = [] patient_info = {} for esh in eshs: flag = "false" pevlog = PatientEventLog.objects.filter(header=esh) ''' if a patient has a delete entry in PatientEventLog table,we have to remove that patient from further process. We use a flag to check the delete entry. flag=false means that patient has no delete entry ''' for pev in pevlog: if pev.event.name == "delete": flag = "True" if flag == "false": patient_name = get_patient_full_name(esh) current_event = get_current_patient_event(pevlog) patient_info = { 'name': patient_name, 'header_id': esh.id, 'event_num': current_event.get('event_num'), 'waiting_time': format_time(current_event.get('waiting_time')) } #Add the patient_info to master dict, if its matches the filter condition. if current_event.get('event_name') == event.name: patient_list.append(patient_info) #To get the new patient at the top patient_list.reverse() data = {'patients': patient_list} return render_to_response('jqmobile/patientsummary.html', data)
def getFrontDeskClinicListCount(request): ''' Return Total count of Patients under a clinicID,it consider only Current day's list only. ''' count = 0 clinicID = request.REQUEST["clinicID"] dtStart, dtEnd = get_request_period(request) eshs = EventSetHeader.objects.filter(clinic = Clinic.objects.get(id=clinicID)).exclude(dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) for esh in eshs: count += PatientEventLog.objects.filter(header=esh).count() outputStr = "<count>%s</count>" % (str(count)) return HttpResponse(outputStr, mimetype="application/xml")
def getFrontDeskClinicList(request): ''' Returns List of current days "headerID" and total rows in the PatientEventLog( which represents where the the patient right now under that clinic.) of every patients under a clincID. ''' clinicID = request.REQUEST["clinicID"] dtStart, dtEnd = get_request_period(request) eshs = EventSetHeader.objects.filter(clinic = Clinic.objects.get(id=clinicID)).exclude(dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) outputList = list() outputList.append("<eventList>") for esh in eshs: count = PatientEventLog.objects.filter(header=esh).count() outputList.append("<li><header>%s</header><count>%s</count></li>" % (esh.id,count)) outputList.append("</eventList>") return HttpResponse("".join(outputList), mimetype="application/xml")
def jqmobile_event_patient_summary(request,clinic_id,event_id): ''' List the patients specific to an event under a clinic. ''' clinic = Clinic.objects.get(id = clinic_id) event = Event.objects.get(id = event_id) dtStart, dtEnd = get_request_period(request,clinic) eshs = EventSetHeader.objects.filter(clinic = clinic).exclude(dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) patient_list = [] patient_info = {} for esh in eshs: pevlog = PatientEventLog.objects.filter(header = esh) patient_name = get_patient_full_name(esh) current_event = get_current_patient_event(pevlog) patient_info = { 'name': patient_name, 'header_id': esh.id, 'event_num': current_event.get('event_num'), 'waiting_time': format_time(current_event.get('waiting_time')) } #Add the patient_info to master dict, if its matches the filter condition. if current_event.get('event_name') == event.name: patient_list.append(patient_info) #To get the new patient at the top patient_list.reverse() data = { 'patients': patient_list } return render_to_response('jqmobile/patientsummary.html',data)
def payment_page(request): header = get_object_or_404(EventSetHeader,id=request.REQUEST.get("header",None)) patintr=Payment.objects.filter(header=header) result=patintr.values_list('interrupttype','amount','type') listofinterrupts=[] amount=[] type=[] c=0 for i in result: c=c+1 listofinterrupts.append(i[0]) amount.append(i[1]) type.append(i[2]) if not request.REQUEST.has_key("clinicID"): raise Http404 clinic_id = request.REQUEST['clinicID'] clinic = get_object_or_404(Clinic, id=clinic_id) dtStart,dtEnd = get_request_period(request,clinic) eshs = EventSetHeader.objects.filter(clinic = clinic).exclude(dateTime__gte=dtEnd).filter(dateTime__gte=dtStart).order_by("dateTime") total = {} total['cash']=reduce(lambda a,b: a+b.get_cash(), eshs, 0.0) total['cc']=reduce(lambda a,b: a+b.get_cc(), eshs, 0.0) total['total'] = total['cash'] + total['cc'] ansDict={} ansDict['total'] = total ansDict['clinic']=clinic ansDict['events']=eshs ansDict['result']=result ansDict['number']=c return direct_to_template(request,'tools/payment-page.htm',ansDict)
def get_json_report(request): ''' Implemented to send the report page information via json form. Json data fromat:- Default user:- msg = {'user':user,'clinicID':clinicID,'patients':[{'headerID':headerID,'patient':{'name':name,'eventTevent':time,...}},... ]} ''' user = request.POST['user'] clinicID = request.POST['clinicID'] clinic = Clinic.objects.get(id = clinicID) msg = {'user':user, 'clinicID':clinicID} #msg = simplejson.dumps(msg) if user == 'default': #Featch the initial Report from the server itself rather than go for axaj method. dtStart, dtEnd = get_request_period(request,clinic) eshs = EventSetHeader.objects.filter(clinic = clinicID).exclude(dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) patients = [] patient = {} events = {} pel_temp = {} patient_full = {} for esh in eshs: pels = PatientEventLog.objects.filter(header = esh) patient_name = get_patient_full_name(esh) #esh.patient.lName + "," + esh.patient.fName + "," + str(esh.patient.dob) for pel in pels: pel_temp[pel.event.name] = pel.dateTime #Get Event map function from the views module. event_map = get_clinic_event_map(clinicID) #Get the time based on the event order from the clinic design for i in range(len(event_map)): ''' Get time interval between events. ''' if (i+1) < len(event_map): if event_map[i][1] in pel_temp and event_map[i+1][1] in pel_temp: events[event_map[i][1]+'T'+event_map[i+1][1]] = ":".join(str(pel_temp[event_map[i+1][1]] - pel_temp[event_map[i][1]]).split(":")[:2]) else: if event_map[i][1] in pel_temp: events[event_map[i][1]] = ":".join(str(datetime.datetime.now() - pel_temp[event_map[i][1]] ).split(":")[:2]) ''' if 'signin' in pel_temp and 'registration' in pel_temp: events['signinTregistration'] = ":".join(str(pel_temp['registration'] - pel_temp['signin']).split(":")[:2]) if 'registration' in pel_temp and 'triage' in pel_temp: events['registrationTtriage'] = ":".join(str(pel_temp['triage'] - pel_temp['registration']).split(":")[:2]) if 'triage' in pel_temp and 'provider' in pel_temp: events['triageTprovider'] = ":".join(str(pel_temp['provider'] - pel_temp['triage']).split(":")[:2]) if 'provider' in pel_temp and 'checkout' in pel_temp: events['providerTcheckout'] = ":".join(str(pel_temp['checkout'] - pel_temp['provider']).split(":")[:2]) if 'appointment' in pel_temp: events['appointment'] = ":".join(str(datetime.datetime.now() - pel_temp['appointment'] ).split(":")[:2]) ''' #some adjustment in the json datatype to make it similar structure of comet based integrations. patient = {"name":patient_name} patient.update(events) patient_full = {"headerID":esh.id,"patient":patient} if not 'delete' in pel_temp: ''' If "delete" entry were present, we just discard that user from frontdesk. ''' patients.append(patient_full) #Clear old values. pel_temp = {} events = {} #patients.reverse(), Dont need to reverse here, because we adding rows to the table via jquery. #name = {"name":patient_name} #patient = {"name":patient_name,"headerID":esh.id,"events":events} #patients = [] #patients = [{'headerID': 354, 'name': 'suresh', 'events': {'signinTregistration': '20:33'}}] msg['patients'] = patients else: ''' Other users; Here we have to return the events of a particular User. JSON message format:- msg = {'user':user,'clinicID':clinicID,'patients':[{'headerID':headerID,'patient':{'name':name,'event':time,...}}, ...]} ''' #user = request.POST['user'] #Featch the initial Report from the server itself rather than go for axaj method. dtStart, dtEnd = get_request_period(request,clinic) eshs = EventSetHeader.objects.filter(clinic = clinicID).exclude(dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) local_timezone = eshs[0].clinic.location.timezone #patients = [{'headerId': 433, 'patient': {u'name':u'test',u'signin': datetime.datetime(2011, 3, 23, 13, 40, 13, 407482), 'name': 'adf', u'registration': datetime.datetime(2011, 3, 23, 14, 2, 52, 31204)}}] for esh in eshs: patient_full = {'headerID':esh.id} pels = PatientEventLog.objects.filter( header = esh , user = user ) #If empty. if not pels: continue patient_name = get_patient_full_name(esh) #esh.patient.lName + "," + esh.patient.fName + "," + str(esh.patient.dob) patient = {'name': patient_name} for pel in pels: patient[pel.event.name] = get_local_time(local_timezone,pel.dateTime) #str(pel.dateTime.hour) + ":" + str(pel.dateTime.minute) patient_full['patient'] = patient #List of Patients. patients.append(patient_full) #Clear Previous user datas. patient = {} patient_full = {} msg['patients'] = patients #endof else block msg = simplejson.dumps(msg) return HttpResponse(msg,mimetype="application/json")
def jqmtab_reports(request): ansDict = updateDict(request) ansDict['menu'] = 'reports' ansDict['left_menu'] = Clinic.objects.all() #if not request.REQUEST.has_key("clinicID"): #ansDict['work_time'] = get_current_worktime() #ansDict['clinics'] = get_current_clinics() #return direct_to_template(request,'reports-base.html',ansDict) clinic = get_object_or_404(Clinic.objects, id=request.REQUEST.get("clinicID", None)) ansDict["clinic"] = clinic #ansDict["date"] = request.REQUEST.get("date_in_frontdesk",None) #Added variables required for the comet session at report page. #channel_name = 'frontdesk' + str(clinic.id) #comet = {"SESSION_COOKIE_NAME":settings.SESSION_COOKIE_NAME,"HOST":settings.INTERFACE,"CHANNEL_NAME":channel_name, #"STOMP_PORT":settings.STOMP_PORT,"USER":request.user} #ansDict.update(comet) #Get Event map of this clininc. event_map = [(1,signin),(2,registration),...] #For User specific mode its better. event_map = get_clinic_event_map(clinic.id) ansDict['user_clinic_event_map'] = event_map #Get user specific event_map, signinTregistration or,,, like that format. default_clinic_event_map = [] for i in range(len(event_map)): ''' creating special header names for report templates. ''' if (i + 1) < len(event_map): default_clinic_event_map.append(event_map[i][1] + ' To ' + event_map[i + 1][1]) else: default_clinic_event_map.append(event_map[i][1]) ansDict['default_clinic_event_map'] = default_clinic_event_map #Featch the initial Report from the serverclinic = get_object_or_404(Clinic.objects, id=request.REQUEST.get("clinicID",None)) itself rather than go for axaj method. dtStart, dtEnd = get_request_period(request, clinic) eshs = EventSetHeader.objects.filter(clinic=clinic).exclude( dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) patients = [] patient = {} events = [] pel_temp = {} for esh in eshs: pels = PatientEventLog.objects.filter(header=esh) patient_name = get_patient_full_name( esh ) #esh.patient.lName + "," + esh.patient.fName + "," + str(esh.patient.dob) for pel in pels: pel_temp[pel.event.name] = pel.dateTime for i in range(len(event_map)): ''' Get time interval between events. The order of the event name is passed in "default_clinic_event_map", it hold the ordered events, signingTregistration,..etc.. So the events are already ordered, so we take the event_times according to that order in a list. clinic = get_object_or_404(Clinic.objects, id=request.REQUEST.get("clinicID",None)) ''' if (i + 1) < len(event_map): if event_map[i][1] in pel_temp and event_map[i + 1][1] in pel_temp: events.append(":".join( str(pel_temp[event_map[i + 1][1]] - pel_temp[event_map[i][1]]).split(":")[:2])) else: events.append(False) else: if event_map[i][1] in pel_temp: events.append(":".join( str(datetime.datetime.now() - pel_temp[event_map[i][1]]).split(":")[:2])) else: events.append(False) '''pel_temp = {} events = [] if 'signin' in pel_temp and 'registration' in pel_temp:clinic = get_object_or_404(Clinic.objects, id=request.REQUEST.get("clinicID",None)) events['signinTregistration'] = ":".join(str(pel_temp['registration'] - pel_temp['signin']).split(":")[:2]) if 'registration' in pel_temp and 'triage' in pel_temp: events['registrationTtriage'] = ":".join(str(pel_temp['triage'] - pel_temp['registration']).split(":")[:2]) if 'triage' in pel_temp and 'provider' in pel_temp: events['triageTprovider'] = ":".join(str(pel_temp['provider'] - pel_temp['triage']).split(":")[:2]) if 'provider' in pel_temp and 'checkout' in pel_temp: events['providerTcheckout'] = ":".join(str(pel_temp['checkout'] - pel_temp['provider']).split(":")[:2]) if 'appointment' in pel_temp: events['appointment'] = ":".join(str(datetime.datetime.now() - pel_temp['appointment'] ).split(":")[:2]) ''' patient = { "patient_name": patient_name, "header": esh.id, "events": events } if not 'delete' in pel_temp: ''' If "delete" entry were present, we just discard that user from frontdesk. ''' patients.append(patient) #Clear old values. pel_temp = {} events = [] patients.reverse() ansDict['patients'] = patients users = User.objects.all() ansDict['users'] = users return direct_to_template(request, 'jqmtab/jqmtab_reports.html', ansDict)
def jqmtab_frontdesk(request): ''' Index page of the Jquery Mobile Web application. ''' locations = Location.objects.all() clinics = Clinic.objects.all() ''' Currently taking first location's first clinic as default clinic to be displyed at frontdesk. ''' clinic = get_object_or_404(Clinic.objects, id=request.REQUEST.get("clinicID", None)) event_map = get_clinic_event_map(clinic.id) dtStart, dtEnd = get_request_period(request, clinic) eshs = EventSetHeader.objects.filter(clinic=clinic).exclude( dateTime__gte=dtEnd).filter(dateTime__gte=dtStart) patients = [] patient = {} events = [] #Get this delete event objects to check whether this patient have delete event. delete = Event.objects.get(name='delete') #Get details of each patients with their current status in specified clinic. for esh in eshs: patient_name = get_patient_full_name( esh ) #esh.patient.lName + "," + esh.patient.fName + "," + str(esh.patient.dob) patient_event_logs = PatientEventLog.objects.filter(header=esh) #Will have value when this use is been deleted : BUG Fixed(6-May-2010) delete_event = patient_event_logs.filter(event=delete) #for pevlog in patient_event_logs: # events[pevlog.event.name] = pevlog.dateTime.strftime("%H:%M") #str(pevlog.dateTime.hour) + ":" + str(pevlog.dateTime.minute) #Here we creating events in the Array format with index gives the order, to match the order and genearlized event management. ''' events = [('22:22','event_name'),...] Due to the clinic generalization, we may have different event order.So we taking genearl methods to get correct event order for a clinic. ''' events = [] #To check deleted users. delete_flag = False for event in event_map: event_time = get_event_time(patient_event_logs, event[1]) events.append((event_time, event[1])) if delete_event: delete_flag = True patient = { "patient_name": patient_name, "header": esh.id, "events": events } #Add This patient to the patient List if the event include "delete" then just discard it. if not delete_flag: patients.append(patient) #patients.append(patient) #if not events.has_key("delete"): # ''' # If "delete" entry were present, we just discard that user from frontdesk. # ''' # patients.append(patient) patients.reverse() #Channel name is specific for each Clinics. At frontdesk we list the patients of one clinic at a time. channel_name = 'frontdesk' + str(clinic.id) comet = { "SESSION_COOKIE_NAME": settings.SESSION_COOKIE_NAME, "HOST": settings.INTERFACE, "CHANNEL_NAME": channel_name, "STOMP_PORT": settings.STOMP_PORT, "USER": request.user } provider_list = Provider.objects.filter( loc=clinic.location.id ) #select the provider info corresponding to a location #For hidden header layout fixing, we taking one row of patient data. patient_hidden = '' dynamic_datas = { 'STATIC_URL': settings.STATIC_URL, 'locations': locations, 'clinic': clinic, 'clinics': clinics, 'clinic_event_map': event_map, 'patients': patients, 'patient_hidden': patient_hidden, 'provider_list': provider_list, } dynamic_datas.update(comet) return render_to_response('jqmtab/jqmtab_frontdesk.html', dynamic_datas)