tags: ACT iBreathCare
urls.py
url(r'^i111/',view.getPatientNotInGroup),
url(r'^i112/',view.getOEHAll),
url(r'^i5000/',view.getOutPatientDate),
url(r'^i5001/',view.getEmgPatientDate),
url(r'^i5002/',view.getInPatientDate),
url(r'^i9996/',view.sendMessage),
url(r'^i9998/',view.addVitualExpGroup),
url(r'^i9999/',view.returnfilter),
url(r'^i4999/',view.selectPatientFromGroup),
view.py
returnfilter
@login_required
@csrf_exempt
@PermissionCheck(3)
def returnfilter(request, data, D_id):
resultAll = []
result = []
if data['group']!='':
result = select.filterIdByGroup(data['group'].split('/'))
resultAll.append(helper1(result))
if data['sex']=='0':
result1 = helper1(select.filterIdByGender('1'))
result2 = helper1(select.filterIdByGender('2'))
result1.extend(result2)
resultAll.append(result1)
else:
result = select.filterIdByGender(data['sex'])
resultAll.append(helper1(result))
result = select.filterIdByAge((data['age'].split('/')[0]), (data['age'].split('/')[1]))
resultAll.append(helper1(result))
result = select.filterIdByHospitalTimes((data['hstime'].split('/')[0]), (data['hstime'].split('/')[1]), (data['date'].split('/')[0]), (data['date'].split('/')[1]))
resultAll.append(helper1(result))
result = select.filterIdByMedicalVisit((data['medicvisit'].split('/')[0]), (data['medicvisit'].split('/')[1]), (data['date'].split('/')[0]), (data['date'].split('/')[1]))
resultAll.append(helper2(result))
#result = select.filterIdByCAT((data['CAT'].split('/')[0]), (data['CAT'].split('/')[1]), (data['date'].split('/')[0]), (data['date'].split('/')[1]))
#resultAll.append(helper1(result))
#result = select.filterIdBySickerTimes(int(data['sicktime'].split('/')[0]),int(data['sicktime'].split('/')[1]))
#resultAll.append(helper2(result))
#result = select.filterIdByLungFunc((data['LungF'].split('/')[0]), (data['LungF'].split('/')[1]), (data['date'].split('/')[0]), (data['date'].split('/')[1]))
tmpmessage = resultAll[0] if len(resultAll)!=0 else []
for res in resultAll:
tmpmessage = [val for val in res if val in tmpmessage]
patientlist = select.getPatientsBasicInfo()
patientmap = {}
for patient in patientlist:
patientmap[patient['P_id']]=patient
message = []
for temp in tmpmessage:
if temp in patientmap:
message.append(patientmap[temp])
js = json.dumps(message)
return HttpResponse(js)
sendMessage
@login_required
@csrf_exempt
@PermissionCheck(3)
def sendMessage(request,data,D_id):
print 'send'
print data
message = {"result":"-1"}
if(insert.sendMessage(data,D_id)):
message = {"result":"0"}
print message
js = json.dumps(message)
push.reply(data['P_id'],data['message'])
return HttpResponse(js)
addVitualExpGroup
@login_required
@csrf_exempt
@PermissionCheck(2)
def addVitualExpGroup(request,data,D_id):
message = []
if insert.addExpGroup(D_id,data['name'],data['description'], data['date']) == True:
groups = select.getExpGroups(D_id)
newg_id = int(groups[len(groups)-1]['G_id'])
print newg_id
pids = tools.forCheckbox2(data, 'add')
print pids
if insert.addPatientToExpGroup(newg_id,pids):
message.append({'g_id':newg_id})
print message
js = json.dumps(message)
return HttpResponse(js)
selectPatientFromGroup
@login_required
@csrf_exempt
@PermissionCheck(3)
def selectPatientFromGroup(request, data, D_id):
resultAll = []
result = []
if data['group']!='':
result = select.filterIdByGroup(data['group'].split('/'))
resultAll = (helper1(result))
message = []
patientlist = select.getPatientsBasicInfo()
if resultAll == []:
message = patientlist
else:
patientmap = {}
for patient in patientlist:
patientmap[patient['P_id']]=patient
for temp in resultAll:
if temp in patientmap:
message.append(patientmap[temp])
js = json.dumps(message)
return HttpResponse(js)
getOutPatientDate
@login_required
@csrf_exempt
@PermissionCheck(3)
def getOutPatientDate(request, data, D_id):
message = select.getOutPatientDate(data)
js = json.dumps(message)
return HttpResponse(js)
getEmgPatientDate
@login_required
@csrf_exempt
@PermissionCheck(3)
def getEmgPatientDate(request, data, D_id):
message = select.getEmgPatientDate(data)
js = json.dumps(message)
return HttpResponse(js)
getInPatientDate
@login_required
@csrf_exempt
@PermissionCheck(3)
def getInPatientDate(request, data, D_id):
message = select.getInPatientDate(data)
js = json.dumps(message)
return HttpResponse(js)
getPatientNotInGroup
@login_required
@csrf_exempt
@PermissionCheck(3)
def getPatientNotInGroup(request,data,D_id):
message = {}
list =[]
pglist =[]
temp = select.getAllExpGroupPatientsID()
for item in temp:
pglist.append(item[0])
patientlist = select.getPatientsBasicInfo()
print patientlist
for patient in patientlist:
print patient['P_id'],"patient"
if patient['P_id'] not in pglist:
list.append(patient)
js = json.dumps(list)
return HttpResponse(js)
getOEHAll
@login_required
@csrf_exempt
@PermissionCheck(3)
def getOEHAll(request,data,D_id):
message = select.getOEHAll(data['P_id'], data['para'])
# print type(list(message))
js = json.dumps(list(message))
# print js
return HttpResponse(js)
select.py
filterIdByHospitalTimes
def filterIdByHospitalTimes(lower, upper, start=None, end=None):
from django.utils.timezone import now
if start==None or end==None or start=='' or end=='':
end = now().date()
start = datetime.date(end.year - 1, end.month, end.day)
lower = int(lower) if lower!='' else 0
upper = int(upper) if upper!='' else 0
try:
#此处应该从inhospitalinfo表中取出未合并相同项的P_id 再计算次数 不需要从medicalvisit中取数 但是略麻烦
result = MedicalVisit.objects.filter(h_time__gte=lower, h_time__lte=upper).values_list('P_id').distinct()
result2 = InHospitalInfo.objects.filter(date__gte=start,date__lte=end).values_list('P_id').distinct()
if lower != 0 and result2!=None and result!=None:
result = [val for val in result2 if val in result]
return result
except Exception, e:
tools.exceptionRecord('select.py', 'filterIdByHospitalTimes', e)
filterIdByGroup
def filterIdByGroup(group):
resultAll = []
try:
for gid in group:
result = PatientGroup.objects.filter(G_id=int(gid)).values_list('P_id')
if result!=None:
for res in result:
resultAll.append(res)
return list(set(resultAll))
except Exception, e:
tools.exceptionRecord('select.py', 'filterIdByGroup', e)
filterIdByCAT 此处还需要继续修改
def filterIdByCAT(lower, upper, start=None, end=None):
from django.utils.timezone import now
if start==None or end==None or start=='' or end=='':
end = now().date()
start = datetime.date(end.year - 1, end.month, end.day)
lower = int(lower) if lower!='' else 0
upper = int(upper) if upper!='' else 0
try:
result = CATandMRC.objects.filter(date__gte=start, date__lte=end,
catSum__gte=lower, catSum__lte=upper).values_list('P_id').distinct()
return result
except Exception, e:
tools.exceptionRecord('select.py', 'filterIdByCAT', e)
filterIdByLungFunc 此处需要继续修改
def filterIdByLungFunc(lower, upper, start=None, end=None):
from django.utils.timezone import now
if start==None or end==None or start=='' or end=='':
end = now().date()
start = datetime.date(end.year - 1, end.month, end.day)
lower = int(lower) if lower!='' else 0
upper = int(upper) if upper!='' else 0
try:
result = LungFunc.objects.filter(date__gte=start, date__lte=end,
GOLD__gte=lower, GOLD__lte=upper).values_list('P_id').distinct()
return result
except Exception, e:
tools.exceptionRecord('select.py', 'filterIdByLungFunc', e)
filterIdBySickerTimes 此处有错
def filterIdBySickerTimes(lower, upper, start=None, end=None):
from django.utils.timezone import now
lower = str(lower) if lower!='' else '0'
upper = str(upper) if upper!='' else '0'
if start==None or end==None or start=='' or end=='':
end = now().date()
start = datetime.date(end.year - 1, end.month, end.day)
try:
print 'sicktime'
print str(start)
result = []
for i in Clinic.objects.raw('select distinct P_id from Website_clinic X where '
'(select count(*) from Website_clinic Website_inhospitalinfo where date >= "' + str(start) + '" and P_id = X.P_id and Website_inhospitalinfo.acuteExac = "1") >= ' + lower + ' and '
'(select count(*) from Website_clinic where date >= "' + str(start) + '" and P_id = X.P_id and acuteExac = "1") <= ' + upper + ';'):
#Website_catandmrc Website_emergcallinfo Website_inhospitalinfo Website_outpatientserviceinfo
result.append(i.P_id)
print result
return result
except Exception, e:
tools.exceptionRecord('select.py', 'filterIdBySickerTimes', e)
getMsg2Weeks
def getMsg2Weeks(P_id, type, num, times):
num = int(num)
part = num*int(times)
if part<0: part = 0;#new add
if part>26: part = 26;
end = now().date()-timedelta(weeks=part)
#num = 20
# end = datetime.datetime.strptime('2017-05-16', "%Y-%m-%d").date()
start = end - timedelta(weeks=num)
temp = {}
message =[]
record = []
message.append(temp)
for i in xrange(num*7 + 1):
temp[str(i+1)] = str(start + timedelta(days=i))[5:10].replace("-","")
record.append(str(start + timedelta(days=i))[0:4])
print temp, len(temp)
try:
if type == 1:
values = CATandMRC.objects.filter(date__gte=start, P_id=P_id).values('date', 'catSum', 'mrc')
elif type == 2:
values = PmExposure.objects.filter(date__gte=start, P_id=P_id).values('date','exposure')
# else:
# return message
for v in values:
v['date']= str(v['date'])[5:10].replace("-","")
message.append(list(values))
except Exception, e:
tools.exceptionRecord('select.py','getMsg2Weeks',e)
message.append(record)
return message
getMessage
def getMessage(data):
try:
start = datetime.date.today().replace(day=1)
print 'start'
print datetime.date.today()
print start
text = MessageText.objects.filter(Q(date_upload__gte=start)).values("id","P_id","date","date_upload","content","sign")
print text
for t in text:
t['type'] = "0"
audio = MessageAudio.objects.filter(Q(date_upload__gte=start)).values("id","P_id","date","date_upload","content","sign")
for a in audio:
a['type'] = "1"
q = list(chain(text,audio))
# print q
q = sorted(q, key=lambda q:q['date_upload'])
q = sorted(q, key=lambda q:q['P_id'])
#q = sorted(q, key=lambda q:q['sign'], reverse=True)
a = {}
for v in q:
if v['P_id'] not in a:
a[v['P_id']] = {"P_id":v['P_id'],"content":[{"date":str(v['date']),"date_upload":str(v['date_upload']),"content":v['content'],"sign":v['sign'],"type":v['type']}]}
else:
a[v['P_id']]['content'].append({"date":str(v['date']),"date_upload":str(v['date_upload']),"content":v['content'],"sign":v['sign'],"type":v['type']})
result = list(a.values())
print result
return result
except Exception, e:
tools.exceptionRecord('select.py', 'getMessage', e)
return {"result":"-1"}
getOutPatientDate
def getOutPatientDate(data):
try:
temp = OutPatientServiceInfo.objects.all().values('date')
result = []
for i in temp:
i['date'] = str(i['date'])
result.append(i)
return result
except Exception, e:
tools.exceptionRecord('select.py', 'getOutPatientDate', e)
getEmgPatientDate
def getEmgPatientDate(data):
try:
temp = EmergCallInfo.objects.all().values('date')
result = []
for i in temp:
i['date'] = str(i['date'])
result.append(i)
return result
except Exception, e:
tools.exceptionRecord('select.py', 'getEmgPatientDate', e)
getInPatientDate
def getInPatientDate(data):
try:
temp = InHospitalInfo.objects.all().values('date')
result = []
for i in temp:
i['date'] = str(i['date'])
result.append(i)
return result
except Exception, e:
tools.exceptionRecord('select.py', 'getInPatientDate', e)
罗小萌同学的select部分未加入
insert.py
sendMessage
def sendMessage(data,D_id):
try:
d = datetime.datetime.strptime('1970-01-01', "%Y-%m-%d").date()
newobj = MessageText(P_id = data['P_id'],D_id=D_id,content = data['message'],date = d,sign=data['sign'])
newobj.save()
return True
except Exception, e:
tools.exceptionRecord('insert.py','sendMessage',e)
return False
models.py
class MessageText(models.Model):
P_id = models.CharField(max_length=12, null=False)
D_id = models.CharField(max_length=12, default='')
content = models.CharField(max_length=200)
date = models.DateField(null=False)
date_upload = models.DateTimeField(auto_now_add=True)
sign = models.CharField(max_length=1, default="1")
class MessageAudio(models.Model):
P_id = models.CharField(max_length=12, null=False)
D_id = models.CharField(max_length=12, default='')
content = models.FileField(upload_to="AUDIO")
date = models.DateField(null=False)
date_upload = models.DateTimeField(auto_now_add=True)
sign = models.CharField(max_length=1, default="1")