add report cycle setting

conv_bal
watcha.h@almacom.co.th 2015-06-12 10:35:33 +07:00
parent a1be6b9bcc
commit 0c9ef4b33e
8 changed files with 212 additions and 13 deletions

View File

@ -0,0 +1,8 @@
<action>
<field name="string">Report Cycle Setting</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.cycle.setting</field>
<field name="report_template">report_cycle_setting</field>
<field name="report_template_xls">report_cycle_setting</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -45,6 +45,7 @@
<item string="Sickbed" action="clinic_sickbed"/> <item string="Sickbed" action="clinic_sickbed"/>
</item> </item>
<item string="Reports" perm="clinic_report"> <item string="Reports" perm="clinic_report">
<item string="Report Cycle Setting" action="clinic_report_cycle_setting"/>
<item string="Cycle Item Summary" action="clinic_report_cycle_item"/> <item string="Cycle Item Summary" action="clinic_report_cycle_item"/>
<item string="HD Case Summary" action="clinic_report_hd_case_summary"/> <item string="HD Case Summary" action="clinic_report_hd_case_summary"/>
<item string="HD Case Expense" action="clinic_report_claim"/> <item string="HD Case Expense" action="clinic_report_claim"/>

View File

@ -0,0 +1,5 @@
<form model="clinic.report.cycle.setting">
<field name="cycle_id" span="2"/>
<field name="branch_id" onchange="onchange_type" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
</form>

View File

@ -136,5 +136,6 @@ from . import num2word
from . import province from . import province
from . import change_visit from . import change_visit
from . import share_location from . import share_location
from . import report_cycle_setting
#from . import district #from . import district
#from . import subdistrict #from . import subdistrict

View File

@ -0,0 +1,154 @@
from netforce.model import Model, fields, get_model
class ReportCycleSetting(Model):
_name="clinic.report.cycle.setting"
_transient=True
_fields={
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
}
def _get_branch(self,context={}):
res=get_model('select.company').get_select()
if res:
return res['branch_id']
def _get_department(self,context={}):
res=get_model('select.company').get_select()
if res:
if res.get("department_ids"):
return res['department_ids'][0]
else:
return res['department_id']
def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{})
branch_id=defaults.get('branch_id')
if branch_id:
branch_id=int(branch_id)
else:
branch_id=self._get_branch(context=context)
department_id=defaults.get('department_id')
if department_id:
department_id=int(department_id)
else:
department_id=self._get_department(context=context)
res={
'branch_id': branch_id,
'department_id': department_id,
}
print('report.cycle.item.setting', res)
return res
def get_report_data(self,ids,context={}):
defaults=self.default_get(context=context)
department_id=defaults.get('department_id',None)
branch_id=defaults.get('branch_id',None)
cycle_id=defaults.get('cycle_id',None)
if ids:
obj=self.browse(ids)[0]
department_id=obj.department_id.id
branch_id=obj.branch_id.id
cycle_id=obj.cycle_id.id
pts={}
dom=[]
dom.append(['patient_id.state','=','admit'])
if department_id:
dom.append(['department_id','=',department_id])
if cycle_id:
dom.append(['cycle_id','=',cycle_id])
pcs=get_model("clinic.patient.cycle").search_browse(dom)
if not pcs:
# Create patient cycle with that department
for pt in get_model("clinic.patient").search_browse([['department_id','=',department_id]]):
if pt.walkin=='yes':
continue
for pc in pt.cycles:
vals={
'patient_id': pt.id,
'department_id': pt.department_id.id,
'cycle_id': pc.cycle_id.id,
'day': pc.day,
}
res=get_model("clinic.patient.cycle").search([[
['patient_id','=',pt.id],
['day','=',pc.day],
['cycle_id','=',pc.cycle_id.id],
['department_id','=', pt.department_id.id],
]])
if not res:
pcycle_id=get_model("clinic.patient.cycle").create(vals)
print("create ", pcycle_id)
else:
print("exist ", res)
pcs=get_model("clinic.patient.cycle").search_browse(dom)
if not pcs:
raise Exception("Please go to menu 'Patients -> Patient Cycles' and import data for %s"%(department_id))
for pc in pcs:
patient=pc.patient_id
dpt=pc.department_id
branch=dpt.branch_id
if not branch:
continue
if branch_id and branch_id!=branch.id:
continue
key=(patient.id,dpt.id)
if not pts.get(key):
pts[key]={
'patient_name': patient.name,
'department_name': dpt.name,
'mon_cycle_id': None,
'tue_cycle_id': None,
'wed_cycle_id': None,
'thu_cycle_id': None,
'fri_cycle_id': None,
'sat_cycle_id': None,
'sun_cycle_id': None,
}
cycle=pc.cycle_id
day=pc.day or ''
if day=='mon':
pts[key]['mon_cycle_id']=cycle.name
elif day=='tue':
pts[key]['tue_cycle_id']=cycle.name
elif day=='wed':
pts[key]['wed_cycle_id']=cycle.name
elif day=='thu':
pts[key]['thu_cycle_id']=cycle.name
elif day=='fri':
pts[key]['fri_cycle_id']=cycle.name
elif day=='sat':
pts[key]['sat_cycle_id']=cycle.name
else:
pts[key]['sun_cycle_id']=cycle.name
lines=[]
no=1
for k, vals in pts.items():
pt_id, dpt_id=k
if pt_id:
vals['patient_id']=pt_id
if not dpt_id:
pt=get_model("clinic.patient").browse(pt_id)
dpt_id=pt.department_id.id
if dpt_id:
vals['department_id']=dpt_id
vals['no']=no
lines.append(vals)
no+=1
data={
'lines': lines,
'department_id': department_id,
}
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
ReportCycleSetting.register()

View File

@ -0,0 +1,41 @@
<div style="margin-top: 20px;" class="alert alert-info" role="alert">
<strong>Click</strong> ที่รายชื่อผู้ป่วยเพื่อทำการแก้ไขรอบการรักษา
</div>
<table class="table table-condensed table-striped" style="margin-bottom:0px;">
<thead class="scroll-header">
<th>#</th>
<th>Patient</th>
{{#unless department_id}}
<th>Department</th>
{{/unless}}
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</thead>
<tbody>
{{#each lines }}
<tr>
<td>{{no}}</td>
<td>
{{view "link" string=patient_name action="clinic_patient" action_options="mode=form" active_id=patient_id}}
</td>
{{#unless ../department_id}}
<td>{{department_name}}</td>
{{/unless}}
<td>{{mon_cycle_id}}</td>
<td>{{tue_cycle_id}}</td>
<td>{{wed_cycle_id}}</td>
<td>{{thu_cycle_id}}</td>
<td>{{fri_cycle_id}}</td>
<td>{{sat_cycle_id}}</td>
<td>{{sun_cycle_id}}</td>
</tr>
{{/each}}
</tbody>
<tfoot>
</tfoot>
</table>

View File

@ -1,13 +1,2 @@
> script: - show log for each model that use _log=True
- merge - create report patient cycle setting -> link to patient to change cycle setting
- staff -> ok
- patient
> explain nurse
กรณีแก้ไขรายชื่อหมอให้ดูรายชื่อแพทย์ให้ดี
> note:
แก้ไขยาก หากมาเจอข้อผิดพลาดบางครั้ง
> report K. boy
total qty of report_labor_cost_staff is not the same report_labor_cost