report hdcase summary , dispose, reactive
parent
b6027ebb60
commit
be9976cb6e
|
@ -0,0 +1 @@
|
|||
from . import del_patient_move
|
|
@ -0,0 +1,15 @@
|
|||
from netforce.controller import Controller
|
||||
|
||||
|
||||
class DelPatientMove(Controller):
|
||||
_path="/del_patient_move"
|
||||
|
||||
def get(self):
|
||||
try:
|
||||
id=self.get_argument("id")
|
||||
id=int(id)
|
||||
get_model("clinic.patient.move").delete([id])
|
||||
except Exception as e:
|
||||
print("ERROR ", e)
|
||||
|
||||
DelPatientMove.register()
|
|
@ -174,7 +174,7 @@
|
|||
<field name="comments"/>
|
||||
</related>
|
||||
<foot>
|
||||
<button string="Dispose" type="danger" action="do_disposte" attrs='{"invisible":[["dispose","=",true]]}'/>
|
||||
<!--<button string="Restore" method="do_restore" icon="repeat" attrs='{"invisible":[["dispose","=",false]]}'/>-->
|
||||
<button string="Dispose" type="danger" method="do_dispose" attrs='{"invisible":[["dispose","=",true]]}'/>
|
||||
<button string="Reactive" type="success" method="do_reactive" icon="repeat" attrs='{"invisible":[["dispose","=",false]]}'/>
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<list model="clinic.patient" colors='{"#cfc":[["state","=","confirmed"]],"#dbdbdb":[["state","=","dispose"]]}'>
|
||||
<top replace="1">
|
||||
<button string="New Patient" action="new_patient"/>
|
||||
<button string="Import" action="import_data" action_options='{"import_model":"clinic.patient","next":"clinic_patient"}' icon="download"/>
|
||||
</top>
|
||||
<field name="reg_date"/>
|
||||
<field name="hn_no"/>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
</top>
|
||||
<group attrs='{"invisible": [["state","in",["step2","step3"]]]}'>
|
||||
<field name="name"/>
|
||||
<field name="date"/>
|
||||
</group>
|
||||
<field name="state" invisible="1"/>
|
||||
<group attrs='{"invisible": [["state","in",["step1","step3"]]]}'>
|
||||
|
@ -14,10 +15,19 @@
|
|||
<field name="lines" nolabel="1">
|
||||
<list>
|
||||
<field name="choose"/>
|
||||
<field name="patient_id"/>
|
||||
<!--<field name="patient_id"/>-->
|
||||
<field name="patient_name"/>
|
||||
<!--<field name="department_id"/>-->
|
||||
<field name="department_name"/>
|
||||
</list>
|
||||
</field>
|
||||
</group>
|
||||
<group attrs='{"invisible": [["state","in",["step1","step2"]]]}'>
|
||||
<field name="name"/>
|
||||
<newline/>
|
||||
<field name="location_from_id"/>
|
||||
<field name="location_to_id"/>
|
||||
</group>
|
||||
<foot replace="1">
|
||||
<button string="Next" method="step1" states="step1" type="success" icon="arrow-right"/>
|
||||
|
||||
|
@ -25,6 +35,6 @@
|
|||
<button string="Next" method="step2" states="step2" type="primary" icon="arrow-right"/>
|
||||
|
||||
<button string="Back" method="back_step2" states="step3" icon="arrow-left"/>
|
||||
<button string="Next" method="step3" states="step3" type="primary" icon="arrow-right"/>
|
||||
<button string="Confirm" method="confirm" states="step3" type="success"/>
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<form model="clinic.patient.move">
|
||||
<field name="patient_id"/>
|
||||
<head>
|
||||
<button string="View HDCase Summary" action="report_hdcase_summary" icon="print"/>
|
||||
</head>
|
||||
<field name="patient_id" onchange="onchange_patient"/>
|
||||
<field name="date"/>
|
||||
<field name="location_from_id"/>
|
||||
<field name="location_to_id"/>
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
import time
|
||||
from netforce.model import Model, fields, get_model
|
||||
from netforce.access import get_active_user, set_active_user
|
||||
'''
|
||||
lines:
|
||||
patient, location -> text
|
||||
patient:
|
||||
share location
|
||||
'''
|
||||
|
||||
class NewPatient(Model):
|
||||
_name="new.patient"
|
||||
|
@ -6,24 +14,35 @@ class NewPatient(Model):
|
|||
|
||||
_fields={
|
||||
'name': fields.Char("Patient Name", required=True),
|
||||
'date': fields.Date("Date"),
|
||||
'lines': fields.One2Many("new.patient.line","new_id","Lines"),
|
||||
'state': fields.Selection([['step1','Step1'],['step2','Step2']], 'State'),
|
||||
|
||||
'location_from_id': fields.Many2One("clinic.department","From Location"),
|
||||
'location_to_id': fields.Many2One("clinic.department","To Location"),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
'state': 'step1',
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d")
|
||||
}
|
||||
|
||||
def find_patient(self, ids, context={}):
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
|
||||
obj=self.browse(ids)[0]
|
||||
get_model("new.patient.line").delete([l.id for l in obj.lines])
|
||||
lines=[]
|
||||
cond=[
|
||||
['name','ilike',obj.name],
|
||||
]
|
||||
for patient_id in get_model("clinic.patient").search(cond+[["dispose","=",True]]):
|
||||
for patient in get_model("clinic.patient").search_browse(cond+[["dispose","=",True]]):
|
||||
vals={
|
||||
'patient_id': patient_id,
|
||||
'patient_id': patient.id,
|
||||
'department_id': patient.department_id.id,
|
||||
'patient_name': patient.name,
|
||||
'department_name': patient.department_id.name,
|
||||
}
|
||||
lines.append(('create',vals))
|
||||
if not lines:
|
||||
|
@ -36,10 +55,14 @@ class NewPatient(Model):
|
|||
},
|
||||
'flash': "ผู้ป่วยนี้มีอยู่แล้วในระบบ",
|
||||
}
|
||||
|
||||
if len(lines)==1:
|
||||
lines[0][1]['choose']=True
|
||||
obj.write({
|
||||
'lines': lines,
|
||||
})
|
||||
|
||||
set_active_user(user_id)
|
||||
|
||||
def step1(self, ids, context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
|
@ -59,6 +82,10 @@ class NewPatient(Model):
|
|||
|
||||
def step2(self, ids, context={}):
|
||||
print("step2")
|
||||
location_to_id=get_model("clinic.patient")._get_department(context)
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
|
||||
obj=self.browse(ids)[0]
|
||||
if not obj.lines:
|
||||
res=obj.name.split(" ")
|
||||
|
@ -88,9 +115,23 @@ class NewPatient(Model):
|
|||
raise Exception("Please choose patient!")
|
||||
if len(select_lines)>1:
|
||||
raise Exception("Can not select patient more than 1!")
|
||||
|
||||
line=[line for line in obj.lines if line.choose][0]
|
||||
patient=line.patient_id
|
||||
patient_id=patient.id
|
||||
|
||||
#default location from
|
||||
#1. find in patient profile
|
||||
location_code=patient.location.split(",")[-1]
|
||||
location_from_id=None
|
||||
for location_id in get_model("clinic.department").search([['code','=',location_code]]):
|
||||
location_from_id=location_id
|
||||
obj.write({
|
||||
'state': 'step3',
|
||||
'location_from_id': location_from_id,
|
||||
'location_to_id': location_to_id,
|
||||
})
|
||||
set_active_user(user_id)
|
||||
|
||||
def back_step2(self, ids, context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
|
@ -99,25 +140,49 @@ class NewPatient(Model):
|
|||
})
|
||||
print("back step2")
|
||||
|
||||
def step3(self, ids, context={}):
|
||||
def confirm(self, ids, context={}):
|
||||
user_id=get_active_user()
|
||||
set_active_user(1)
|
||||
|
||||
obj=self.browse(ids)[0]
|
||||
line=[line for line in obj.lines if line.choose][0]
|
||||
patient=line.patient_id
|
||||
|
||||
#share location here
|
||||
|
||||
location=patient.location.split(",")+[obj.location_to_id.code or '']
|
||||
sloc=list(set(location))
|
||||
location=','.join([loc for loc in sloc if loc])
|
||||
patient.write({
|
||||
'location': location,
|
||||
})
|
||||
|
||||
set_active_user(user_id)
|
||||
|
||||
patient_id=patient.id
|
||||
location_code=patient.location.split(",")[-1]
|
||||
location_from_id=None
|
||||
for location_id in get_model("clinic.department").search([['code','=',location_code]]):
|
||||
location_from_id=location_id
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_patient_move',
|
||||
'mode': 'form',
|
||||
'defaults': {
|
||||
|
||||
vals={
|
||||
'patient_id': patient_id,
|
||||
'location_from_id': location_from_id,
|
||||
'location_from_id': obj.location_from_id.id,
|
||||
'location_to_id': obj.location_to_id.id,
|
||||
'state': 'new',
|
||||
}
|
||||
}
|
||||
'date': obj.date,
|
||||
}
|
||||
|
||||
get_model("clinic.patient.move").create(vals)
|
||||
|
||||
patient.write({
|
||||
'dispose': False,
|
||||
})
|
||||
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_patient',
|
||||
'mode': 'form',
|
||||
'active_id': patient.id,
|
||||
},
|
||||
'flash': "New patient successful!",
|
||||
}
|
||||
|
||||
|
||||
NewPatient.register()
|
||||
|
|
|
@ -8,6 +8,9 @@ class NewPatientLine(Model):
|
|||
'new_id': fields.Many2One("new.patient","New", required=True, on_delete="cascade"),
|
||||
"choose": fields.Boolean("Choose"),
|
||||
"patient_id": fields.Many2One("clinic.patient","Patient"),
|
||||
'patient_name': fields.Char("Patient Name"),
|
||||
'department_id': fields.Many2One("clinic.department","Department"),
|
||||
'department_name': fields.Char("Department Name"),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
|
|
|
@ -583,4 +583,35 @@ class Patient(Model):
|
|||
#data['doctor_id']=None
|
||||
return data
|
||||
|
||||
def create_move(self, ids, state):
|
||||
obj=self.browse(ids)[0]
|
||||
department=obj.department_id
|
||||
location_to_id=self._get_department()
|
||||
location_from_id=department.id
|
||||
res=get_model("clinic.patient.move").search_browse([['patient_id','=',obj.id]])
|
||||
if res:
|
||||
location_from_id=res[-1].location_to_id.id
|
||||
|
||||
vals={
|
||||
'patient_id': obj.id,
|
||||
'location_from_id': location_from_id,
|
||||
'location_to_id': location_to_id,
|
||||
'state': state,
|
||||
}
|
||||
get_model("clinic.patient.move").create(vals)
|
||||
|
||||
def do_dispose(self, ids, context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
obj.create_move('dispose')
|
||||
return {
|
||||
'flash': 'Dispose successful',
|
||||
}
|
||||
|
||||
def do_reactive(self, ids, context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
obj.create_move('new')
|
||||
return {
|
||||
'flash': 'Reactive successful',
|
||||
}
|
||||
|
||||
Patient.register()
|
||||
|
|
|
@ -11,7 +11,7 @@ class PatientMove(Model):
|
|||
_name="clinic.patient.move"
|
||||
|
||||
_fields={
|
||||
'patient_id': fields.Many2One('clinic.patient','Patient',search=True),
|
||||
'patient_id': fields.Many2One('clinic.patient','Patient',search=True, required=True),
|
||||
'date': fields.Date("Date", required=True,search=True),
|
||||
'location_from_id': fields.Many2One("clinic.department","Location From",search=True,required=True),
|
||||
'location_to_id': fields.Many2One("clinic.department","Location To",search=True,required=True),
|
||||
|
@ -20,10 +20,48 @@ class PatientMove(Model):
|
|||
}
|
||||
|
||||
_defaults={
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||
'state': 'normal',
|
||||
}
|
||||
|
||||
def onchange_patient(self, context={}):
|
||||
data=context['data']
|
||||
patient_id=data['patient_id']
|
||||
patient=get_model('clinic.patient').browse(patient_id)
|
||||
|
||||
location_from_id=patient.department_id.id
|
||||
location_to_id=get_model('clinic.patient')._get_department(context)
|
||||
|
||||
data.update({
|
||||
'location_from_id': location_from_id,
|
||||
'location_to_id': location_to_id,
|
||||
})
|
||||
return data
|
||||
|
||||
def dispose_patient(self, ids, context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
if obj.state=='new':
|
||||
obj.patient_id.write({
|
||||
'dispose': False,
|
||||
})
|
||||
elif obj.state=='dispose':
|
||||
obj.patient_id.write({
|
||||
'dispose': True,
|
||||
})
|
||||
else:
|
||||
pass
|
||||
|
||||
def create(self, vals, **kw):
|
||||
new_id=super().create(vals, **kw)
|
||||
obj=self.browse(new_id)
|
||||
obj.dispose_patient()
|
||||
return new_id
|
||||
|
||||
def write(self, ids, vals, **kw):
|
||||
super().write(ids, vals, **kw)
|
||||
for obj in self.browse(ids):
|
||||
obj.dispose_patient()
|
||||
|
||||
def get_data(self, date, department_id, context={}):
|
||||
if not date:
|
||||
raise Exception("Missing date!")
|
||||
|
|
|
@ -2,7 +2,7 @@ import time
|
|||
from calendar import monthrange
|
||||
|
||||
from netforce.model import Model, fields, get_model
|
||||
from netforce.access import get_active_company
|
||||
from netforce.access import get_active_company, get_active_user
|
||||
|
||||
from . import utils
|
||||
|
||||
|
@ -29,6 +29,7 @@ class ReportHDCaseSummaryV2(Model):
|
|||
return vals
|
||||
|
||||
def get_report_data(self, ids, context={}):
|
||||
user_id=get_active_user()
|
||||
defaults=self.default_get(context=context)
|
||||
month=defaults.get("month")
|
||||
y,m,d=month.split("-")
|
||||
|
@ -93,10 +94,18 @@ class ReportHDCaseSummaryV2(Model):
|
|||
'total_hdcase': len(hdcase_ids),
|
||||
'medicals': medical_lines,
|
||||
'titles': medical_titles,
|
||||
'date': month,
|
||||
'can_edit': False,
|
||||
}
|
||||
data2=get_model("clinic.patient.move").get_data(date=month, department_id=department_id)
|
||||
data.update(data2)
|
||||
|
||||
res=get_model("permission").search([['code','=','hdcase_report_admin']])
|
||||
if res or user_id==1:
|
||||
data.update({
|
||||
'can_edit': True,
|
||||
})
|
||||
|
||||
from pprint import pprint
|
||||
pprint(data)
|
||||
return data
|
||||
|
|
|
@ -7,6 +7,21 @@
|
|||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
function delete_patient_move(id){
|
||||
var res=confirm("Are you sure?");
|
||||
if(res){
|
||||
ids=[[id]];
|
||||
rpc_execute("clinic.patient.move","delete",ids,{},function(err, data){
|
||||
if(err){
|
||||
alert("ERROR "+err.message);
|
||||
}else{
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<center>
|
||||
<h2>
|
||||
HDCase Summary
|
||||
|
@ -52,6 +67,7 @@
|
|||
<th>No.</th>
|
||||
<th>วันที่</th>
|
||||
<th>ชื่อ</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each current_items}}
|
||||
|
@ -59,10 +75,23 @@
|
|||
<td>{{no}}</td>
|
||||
<td>{{date}}</td>
|
||||
<td>{{patient_id.1.}}</td>
|
||||
{{#if ../can_edit}}
|
||||
<td>
|
||||
<a onclick="delete_patient_move({{id}})" style="cursor:pointer" class="text-danger">
|
||||
<span class="glyphicon glyphicon-remove-sign"></span>
|
||||
</a>
|
||||
</td>
|
||||
{{/if}}
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{#if can_edit}}
|
||||
<a class="btn btn-default btn-sm" href="/ui#name=new_patient&defaults.date={{date}}">
|
||||
<span class="glyphicon glyphicon-plus"></span>
|
||||
New item
|
||||
</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<h4 style="text-align:center;text-decoration: underline">รายชื่อผู้ป่วยจำหน่าย</h4>
|
||||
|
@ -71,6 +100,7 @@
|
|||
<th>No.</th>
|
||||
<th>วันที่</th>
|
||||
<th>ชื่อ</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each dispose_items}}
|
||||
|
@ -78,11 +108,24 @@
|
|||
<td>{{no}}</td>
|
||||
<td>{{date}}</td>
|
||||
<td>{{patient_id.1.}}</td>
|
||||
{{#if ../can_edit}}
|
||||
<td>
|
||||
<a onclick="delete_patient_move({{id}})" style="cursor:pointer" class="text-danger">
|
||||
<span class="glyphicon glyphicon-remove-sign"></span>
|
||||
</a>
|
||||
</td>
|
||||
{{/if}}
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{#if can_edit}}
|
||||
<a class="btn btn-default btn-sm" href="/ui#name=clinic_patient_move&mode=form&defaults.state=dispose&defaults.date={{date}}">
|
||||
<span class="glyphicon glyphicon-plus"></span>
|
||||
New item
|
||||
</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
|
Loading…
Reference in New Issue