report hdcase summary , dispose, reactive

v2
watcha.h 2017-06-12 00:35:26 +07:00
parent b6027ebb60
commit be9976cb6e
12 changed files with 244 additions and 25 deletions

View File

@ -0,0 +1 @@
from . import del_patient_move

View File

@ -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()

View File

@ -174,7 +174,7 @@
<field name="comments"/> <field name="comments"/>
</related> </related>
<foot> <foot>
<button string="Dispose" type="danger" action="do_disposte" attrs='{"invisible":[["dispose","=",true]]}'/> <button string="Dispose" type="danger" method="do_dispose" attrs='{"invisible":[["dispose","=",true]]}'/>
<!--<button string="Restore" method="do_restore" icon="repeat" attrs='{"invisible":[["dispose","=",false]]}'/>--> <button string="Reactive" type="success" method="do_reactive" icon="repeat" attrs='{"invisible":[["dispose","=",false]]}'/>
</foot> </foot>
</form> </form>

View File

@ -1,6 +1,7 @@
<list model="clinic.patient" colors='{"#cfc":[["state","=","confirmed"]],"#dbdbdb":[["state","=","dispose"]]}'> <list model="clinic.patient" colors='{"#cfc":[["state","=","confirmed"]],"#dbdbdb":[["state","=","dispose"]]}'>
<top replace="1"> <top replace="1">
<button string="New Patient" action="new_patient"/> <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> </top>
<field name="reg_date"/> <field name="reg_date"/>
<field name="hn_no"/> <field name="hn_no"/>

View File

@ -3,6 +3,7 @@
</top> </top>
<group attrs='{"invisible": [["state","in",["step2","step3"]]]}'> <group attrs='{"invisible": [["state","in",["step2","step3"]]]}'>
<field name="name"/> <field name="name"/>
<field name="date"/>
</group> </group>
<field name="state" invisible="1"/> <field name="state" invisible="1"/>
<group attrs='{"invisible": [["state","in",["step1","step3"]]]}'> <group attrs='{"invisible": [["state","in",["step1","step3"]]]}'>
@ -14,10 +15,19 @@
<field name="lines" nolabel="1"> <field name="lines" nolabel="1">
<list> <list>
<field name="choose"/> <field name="choose"/>
<field name="patient_id"/> <!--<field name="patient_id"/>-->
<field name="patient_name"/>
<!--<field name="department_id"/>-->
<field name="department_name"/>
</list> </list>
</field> </field>
</group> </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"> <foot replace="1">
<button string="Next" method="step1" states="step1" type="success" icon="arrow-right"/> <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="Next" method="step2" states="step2" type="primary" icon="arrow-right"/>
<button string="Back" method="back_step2" states="step3" icon="arrow-left"/> <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> </foot>
</form> </form>

View File

@ -1,5 +1,8 @@
<form model="clinic.patient.move"> <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="date"/>
<field name="location_from_id"/> <field name="location_from_id"/>
<field name="location_to_id"/> <field name="location_to_id"/>

View File

@ -1,4 +1,12 @@
import time
from netforce.model import Model, fields, get_model 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): class NewPatient(Model):
_name="new.patient" _name="new.patient"
@ -6,24 +14,35 @@ class NewPatient(Model):
_fields={ _fields={
'name': fields.Char("Patient Name", required=True), 'name': fields.Char("Patient Name", required=True),
'date': fields.Date("Date"),
'lines': fields.One2Many("new.patient.line","new_id","Lines"), 'lines': fields.One2Many("new.patient.line","new_id","Lines"),
'state': fields.Selection([['step1','Step1'],['step2','Step2']], 'State'), '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={ _defaults={
'state': 'step1', 'state': 'step1',
'date': lambda *a: time.strftime("%Y-%m-%d")
} }
def find_patient(self, ids, context={}): def find_patient(self, ids, context={}):
user_id=get_active_user()
set_active_user(1)
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
get_model("new.patient.line").delete([l.id for l in obj.lines]) get_model("new.patient.line").delete([l.id for l in obj.lines])
lines=[] lines=[]
cond=[ cond=[
['name','ilike',obj.name], ['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={ 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)) lines.append(('create',vals))
if not lines: if not lines:
@ -36,10 +55,14 @@ class NewPatient(Model):
}, },
'flash': "ผู้ป่วยนี้มีอยู่แล้วในระบบ", 'flash': "ผู้ป่วยนี้มีอยู่แล้วในระบบ",
} }
if len(lines)==1:
lines[0][1]['choose']=True
obj.write({ obj.write({
'lines': lines, 'lines': lines,
}) })
set_active_user(user_id)
def step1(self, ids, context={}): def step1(self, ids, context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
@ -59,6 +82,10 @@ class NewPatient(Model):
def step2(self, ids, context={}): def step2(self, ids, context={}):
print("step2") 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] obj=self.browse(ids)[0]
if not obj.lines: if not obj.lines:
res=obj.name.split(" ") res=obj.name.split(" ")
@ -88,9 +115,23 @@ class NewPatient(Model):
raise Exception("Please choose patient!") raise Exception("Please choose patient!")
if len(select_lines)>1: if len(select_lines)>1:
raise Exception("Can not select patient more than 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({ obj.write({
'state': 'step3', '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={}): def back_step2(self, ids, context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
@ -99,25 +140,49 @@ class NewPatient(Model):
}) })
print("back step2") 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] obj=self.browse(ids)[0]
line=[line for line in obj.lines if line.choose][0] line=[line for line in obj.lines if line.choose][0]
patient=line.patient_id 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 patient_id=patient.id
location_code=patient.location.split(",")[-1]
location_from_id=None vals={
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': {
'patient_id': patient_id, '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', '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() NewPatient.register()

View File

@ -8,6 +8,9 @@ class NewPatientLine(Model):
'new_id': fields.Many2One("new.patient","New", required=True, on_delete="cascade"), 'new_id': fields.Many2One("new.patient","New", required=True, on_delete="cascade"),
"choose": fields.Boolean("Choose"), "choose": fields.Boolean("Choose"),
"patient_id": fields.Many2One("clinic.patient","Patient"), "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={ _defaults={

View File

@ -583,4 +583,35 @@ class Patient(Model):
#data['doctor_id']=None #data['doctor_id']=None
return data 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() Patient.register()

View File

@ -11,7 +11,7 @@ class PatientMove(Model):
_name="clinic.patient.move" _name="clinic.patient.move"
_fields={ _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), 'date': fields.Date("Date", required=True,search=True),
'location_from_id': fields.Many2One("clinic.department","Location From",search=True,required=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), 'location_to_id': fields.Many2One("clinic.department","Location To",search=True,required=True),
@ -20,10 +20,48 @@ class PatientMove(Model):
} }
_defaults={ _defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"), 'date': lambda *a: time.strftime("%Y-%m-%d"),
'state': 'normal', '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={}): def get_data(self, date, department_id, context={}):
if not date: if not date:
raise Exception("Missing date!") raise Exception("Missing date!")

View File

@ -2,7 +2,7 @@ import time
from calendar import monthrange from calendar import monthrange
from netforce.model import Model, fields, get_model 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 from . import utils
@ -29,6 +29,7 @@ class ReportHDCaseSummaryV2(Model):
return vals return vals
def get_report_data(self, ids, context={}): def get_report_data(self, ids, context={}):
user_id=get_active_user()
defaults=self.default_get(context=context) defaults=self.default_get(context=context)
month=defaults.get("month") month=defaults.get("month")
y,m,d=month.split("-") y,m,d=month.split("-")
@ -93,10 +94,18 @@ class ReportHDCaseSummaryV2(Model):
'total_hdcase': len(hdcase_ids), 'total_hdcase': len(hdcase_ids),
'medicals': medical_lines, 'medicals': medical_lines,
'titles': medical_titles, 'titles': medical_titles,
'date': month,
'can_edit': False,
} }
data2=get_model("clinic.patient.move").get_data(date=month, department_id=department_id) data2=get_model("clinic.patient.move").get_data(date=month, department_id=department_id)
data.update(data2) 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 from pprint import pprint
pprint(data) pprint(data)
return data return data

View File

@ -7,6 +7,21 @@
} }
</style> </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> <center>
<h2> <h2>
HDCase Summary HDCase Summary
@ -52,6 +67,7 @@
<th>No.</th> <th>No.</th>
<th>วันที่</th> <th>วันที่</th>
<th>ชื่อ</th> <th>ชื่อ</th>
<th></th>
</thead> </thead>
<tbody> <tbody>
{{#each current_items}} {{#each current_items}}
@ -59,10 +75,23 @@
<td>{{no}}</td> <td>{{no}}</td>
<td>{{date}}</td> <td>{{date}}</td>
<td>{{patient_id.1.}}</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> </tr>
{{/each}} {{/each}}
</tbody> </tbody>
</table> </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>
<div class="col-sm-6"> <div class="col-sm-6">
<h4 style="text-align:center;text-decoration: underline">รายชื่อผู้ป่วยจำหน่าย</h4> <h4 style="text-align:center;text-decoration: underline">รายชื่อผู้ป่วยจำหน่าย</h4>
@ -71,6 +100,7 @@
<th>No.</th> <th>No.</th>
<th>วันที่</th> <th>วันที่</th>
<th>ชื่อ</th> <th>ชื่อ</th>
<th></th>
</thead> </thead>
<tbody> <tbody>
{{#each dispose_items}} {{#each dispose_items}}
@ -78,11 +108,24 @@
<td>{{no}}</td> <td>{{no}}</td>
<td>{{date}}</td> <td>{{date}}</td>
<td>{{patient_id.1.}}</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> </tr>
{{/each}} {{/each}}
</tbody> </tbody>
</table> </table>
</div> </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>
<div class="row"> <div class="row">