feat: admission and discharge schedule detials via dialog
This commit is contained in:
		
							parent
							
								
									18ace30a81
								
							
						
					
					
						commit
						08f76d73e3
					
				| @ -2,22 +2,37 @@ | |||||||
| // For license information, please see license.txt
 | // For license information, please see license.txt
 | ||||||
| 
 | 
 | ||||||
| frappe.ui.form.on('Inpatient Record', { | frappe.ui.form.on('Inpatient Record', { | ||||||
|  | 	setup: function(frm) { | ||||||
|  | 		frm.get_field('drug_prescription').grid.editable_fields = [ | ||||||
|  | 			{fieldname: 'drug_code', columns: 2}, | ||||||
|  | 			{fieldname: 'drug_name', columns: 2}, | ||||||
|  | 			{fieldname: 'dosage', columns: 2}, | ||||||
|  | 			{fieldname: 'period', columns: 2} | ||||||
|  | 		]; | ||||||
|  | 	}, | ||||||
| 	refresh: function(frm) { | 	refresh: function(frm) { | ||||||
| 		if(!frm.doc.__islocal && frm.doc.status == "Admission Scheduled"){ | 		if(!frm.doc.__islocal && (frm.doc.status == 'Admission Scheduled' || frm.doc.status == 'Admitted')) { | ||||||
|  | 			frm.enable_save(); | ||||||
|  | 		} else { | ||||||
|  | 			frm.disable_save(); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if(!frm.doc.__islocal && frm.doc.status == 'Admission Scheduled') { | ||||||
| 			frm.add_custom_button(__('Admit'), function() { | 			frm.add_custom_button(__('Admit'), function() { | ||||||
| 				admit_patient_dialog(frm); | 				admit_patient_dialog(frm); | ||||||
| 			} ); | 			} ); | ||||||
| 			frm.set_df_property("btn_transfer", "hidden", 1); |  | ||||||
| 		} | 		} | ||||||
| 		if(!frm.doc.__islocal && frm.doc.status == "Discharge Scheduled"){ | 
 | ||||||
|  | 		if(!frm.doc.__islocal && frm.doc.status == 'Discharge Scheduled') { | ||||||
| 			frm.add_custom_button(__('Discharge'), function() { | 			frm.add_custom_button(__('Discharge'), function() { | ||||||
| 				discharge_patient(frm); | 				discharge_patient(frm); | ||||||
| 			} ); | 			} ); | ||||||
| 			frm.set_df_property("btn_transfer", "hidden", 0); |  | ||||||
| 		} | 		} | ||||||
| 		if(!frm.doc.__islocal && (frm.doc.status == "Discharged" || frm.doc.status == "Discharge Scheduled")){ | 		if(!frm.doc.__islocal && frm.doc.status != 'Admitted') { | ||||||
| 			frm.disable_save(); | 			frm.disable_save(); | ||||||
| 			frm.set_df_property("btn_transfer", "hidden", 1); | 			frm.set_df_property('btn_transfer', 'hidden', 1); | ||||||
|  | 		} else { | ||||||
|  | 			frm.set_df_property('btn_transfer', 'hidden', 0); | ||||||
| 		} | 		} | ||||||
| 	}, | 	}, | ||||||
| 	btn_transfer: function(frm) { | 	btn_transfer: function(frm) { | ||||||
| @ -28,14 +43,14 @@ frappe.ui.form.on('Inpatient Record', { | |||||||
| var discharge_patient = function(frm) { | var discharge_patient = function(frm) { | ||||||
| 	frappe.call({ | 	frappe.call({ | ||||||
| 		doc: frm.doc, | 		doc: frm.doc, | ||||||
| 		method: "discharge", | 		method: 'discharge', | ||||||
| 		callback: function(data) { | 		callback: function(data) { | ||||||
| 			if(!data.exc){ | 			if(!data.exc){ | ||||||
| 				frm.reload_doc(); | 				frm.reload_doc(); | ||||||
| 			} | 			} | ||||||
| 		}, | 		}, | ||||||
| 		freeze: true, | 		freeze: true, | ||||||
| 		freeze_message: "Process Discharge" | 		freeze_message: 'Processing Inpatient Discharge' | ||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| @ -44,12 +59,20 @@ var admit_patient_dialog = function(frm){ | |||||||
| 		title: 'Admit Patient', | 		title: 'Admit Patient', | ||||||
| 		width: 100, | 		width: 100, | ||||||
| 		fields: [ | 		fields: [ | ||||||
| 			{fieldtype: "Link", label: "Service Unit Type", fieldname: "service_unit_type", options: "Healthcare Service Unit Type"}, | 			{fieldtype: 'Link', label: 'Service Unit Type', fieldname: 'service_unit_type', | ||||||
| 			{fieldtype: "Link", label: "Service Unit", fieldname: "service_unit", options: "Healthcare Service Unit", reqd: 1}, | 				options: 'Healthcare Service Unit Type', default: frm.doc.admission_service_unit_type | ||||||
| 			{fieldtype: "Datetime", label: "Admission Datetime", fieldname: "check_in", reqd: 1}, | 			}, | ||||||
| 			{fieldtype: "Date", label: "Expected Discharge", fieldname: "expected_discharge"} | 			{fieldtype: 'Link', label: 'Service Unit', fieldname: 'service_unit', | ||||||
|  | 				options: 'Healthcare Service Unit', reqd: 1 | ||||||
|  | 			}, | ||||||
|  | 			{fieldtype: 'Datetime', label: 'Admission Datetime', fieldname: 'check_in', | ||||||
|  | 				reqd: 1, default: frappe.datetime.now_datetime() | ||||||
|  | 			}, | ||||||
|  | 			{fieldtype: 'Date', label: 'Expected Discharge', fieldname: 'expected_discharge', | ||||||
|  | 				default: frm.doc.expected_length_of_stay ? frappe.datetime.add_days(frappe.datetime.now_datetime(), frm.doc.expected_length_of_stay) : '' | ||||||
|  | 			} | ||||||
| 		], | 		], | ||||||
| 		primary_action_label: __("Admit"), | 		primary_action_label: __('Admit'), | ||||||
| 		primary_action : function(){ | 		primary_action : function(){ | ||||||
| 			var service_unit = dialog.get_value('service_unit'); | 			var service_unit = dialog.get_value('service_unit'); | ||||||
| 			var check_in = dialog.get_value('check_in'); | 			var check_in = dialog.get_value('check_in'); | ||||||
| @ -74,27 +97,28 @@ var admit_patient_dialog = function(frm){ | |||||||
| 					} | 					} | ||||||
| 				}, | 				}, | ||||||
| 				freeze: true, | 				freeze: true, | ||||||
| 				freeze_message: "Process Admission" | 				freeze_message: 'Processing Patient Admission' | ||||||
| 			}); | 			}); | ||||||
| 			frm.refresh_fields(); | 			frm.refresh_fields(); | ||||||
| 			dialog.hide(); | 			dialog.hide(); | ||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	dialog.fields_dict["service_unit_type"].get_query = function(){ | 	dialog.fields_dict['service_unit_type'].get_query = function() { | ||||||
| 		return { | 		return { | ||||||
| 			filters: { | 			filters: { | ||||||
| 				"inpatient_occupancy": 1, | 				'inpatient_occupancy': 1, | ||||||
| 				"allow_appointments": 0 | 				'allow_appointments': 0 | ||||||
| 			} | 			} | ||||||
| 		}; | 		}; | ||||||
| 	}; | 	}; | ||||||
| 	dialog.fields_dict["service_unit"].get_query = function(){ | 	dialog.fields_dict['service_unit'].get_query = function() { | ||||||
| 		return { | 		return { | ||||||
| 			filters: { | 			filters: { | ||||||
| 				"is_group": 0, | 				'is_group': 0, | ||||||
| 				"service_unit_type": dialog.get_value("service_unit_type"), | 				'company': frm.doc.company, | ||||||
| 				"occupancy_status" : "Vacant" | 				'service_unit_type': dialog.get_value('service_unit_type'), | ||||||
|  | 				'occupancy_status' : 'Vacant' | ||||||
| 			} | 			} | ||||||
| 		}; | 		}; | ||||||
| 	}; | 	}; | ||||||
|  | |||||||
| @ -22,17 +22,41 @@ | |||||||
|   "scheduled_date", |   "scheduled_date", | ||||||
|   "admitted_datetime", |   "admitted_datetime", | ||||||
|   "expected_discharge", |   "expected_discharge", | ||||||
|   "discharge_date", |  | ||||||
|   "references", |   "references", | ||||||
|   "cb_admission", |  | ||||||
|   "admission_practitioner", |  | ||||||
|   "admission_encounter", |   "admission_encounter", | ||||||
|   "cb_discharge", |   "admission_practitioner", | ||||||
|   "discharge_practitioner", |   "medical_department", | ||||||
|   "discharge_encounter", |   "admission_ordered_for", | ||||||
|  |   "expected_length_of_stay", | ||||||
|  |   "admission_service_unit_type", | ||||||
|  |   "cb_admission", | ||||||
|  |   "primary_practitioner", | ||||||
|  |   "secondary_practitioner", | ||||||
|  |   "admission_instruction", | ||||||
|  |   "encounter_details_section", | ||||||
|  |   "chief_complaint", | ||||||
|  |   "column_break_29", | ||||||
|  |   "diagnosis", | ||||||
|  |   "medication_section", | ||||||
|  |   "drug_prescription", | ||||||
|  |   "investigations_section", | ||||||
|  |   "lab_test_prescription", | ||||||
|  |   "procedures_section", | ||||||
|  |   "procedure_prescription", | ||||||
|  |   "rehabilitation_section", | ||||||
|  |   "therapy_plan", | ||||||
|  |   "therapies", | ||||||
|   "sb_inpatient_occupancy", |   "sb_inpatient_occupancy", | ||||||
|   "inpatient_occupancies", |   "inpatient_occupancies", | ||||||
|   "btn_transfer", |   "btn_transfer", | ||||||
|  |   "sb_discharge_details", | ||||||
|  |   "discharge_ordered_date", | ||||||
|  |   "discharge_practitioner", | ||||||
|  |   "discharge_encounter", | ||||||
|  |   "discharge_date", | ||||||
|  |   "cb_discharge", | ||||||
|  |   "discharge_instructions", | ||||||
|  |   "followup_date", | ||||||
|   "sb_discharge_note", |   "sb_discharge_note", | ||||||
|   "discharge_note" |   "discharge_note" | ||||||
|  ], |  ], | ||||||
| @ -54,7 +78,8 @@ | |||||||
|    "in_list_view": 1, |    "in_list_view": 1, | ||||||
|    "label": "Patient", |    "label": "Patient", | ||||||
|    "options": "Patient", |    "options": "Patient", | ||||||
|    "reqd": 1 |    "reqd": 1, | ||||||
|  |    "set_only_once": 1 | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "fetch_from": "patient.patient_name", |    "fetch_from": "patient.patient_name", | ||||||
| @ -108,11 +133,31 @@ | |||||||
|    "label": "Phone", |    "label": "Phone", | ||||||
|    "read_only": 1 |    "read_only": 1 | ||||||
|   }, |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "medical_department", | ||||||
|  |    "fieldtype": "Link", | ||||||
|  |    "label": "Medical Department", | ||||||
|  |    "options": "Medical Department", | ||||||
|  |    "set_only_once": 1 | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "primary_practitioner", | ||||||
|  |    "fieldtype": "Link", | ||||||
|  |    "label": "Healthcare Practitioner (Primary)", | ||||||
|  |    "options": "Healthcare Practitioner" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "secondary_practitioner", | ||||||
|  |    "fieldtype": "Link", | ||||||
|  |    "label": "Healthcare Practitioner (Secondary)", | ||||||
|  |    "options": "Healthcare Practitioner" | ||||||
|  |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "column_break_8", |    "fieldname": "column_break_8", | ||||||
|    "fieldtype": "Column Break" |    "fieldtype": "Column Break" | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|  |    "default": "Admission Scheduled", | ||||||
|    "fieldname": "status", |    "fieldname": "status", | ||||||
|    "fieldtype": "Select", |    "fieldtype": "Select", | ||||||
|    "in_list_view": 1, |    "in_list_view": 1, | ||||||
| @ -126,37 +171,45 @@ | |||||||
|    "fieldtype": "Date", |    "fieldtype": "Date", | ||||||
|    "in_list_view": 1, |    "in_list_view": 1, | ||||||
|    "label": "Admission Schedule Date", |    "label": "Admission Schedule Date", | ||||||
|  |    "read_only": 1, | ||||||
|    "reqd": 1 |    "reqd": 1 | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "default": "Today", |    "fieldname": "admission_ordered_for", | ||||||
|  |    "fieldtype": "Date", | ||||||
|  |    "label": "Admission Ordered For", | ||||||
|  |    "read_only": 1 | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|    "fieldname": "admitted_datetime", |    "fieldname": "admitted_datetime", | ||||||
|    "fieldtype": "Datetime", |    "fieldtype": "Datetime", | ||||||
|    "in_list_view": 1, |    "in_list_view": 1, | ||||||
|    "label": "Admitted Datetime" |    "label": "Admitted Datetime", | ||||||
|  |    "read_only": 1 | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "depends_on": "eval:(doc.expected_length_of_stay > 0)", | ||||||
|  |    "fieldname": "expected_length_of_stay", | ||||||
|  |    "fieldtype": "Int", | ||||||
|  |    "label": "Expected Length of Stay", | ||||||
|  |    "set_only_once": 1 | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "expected_discharge", |    "fieldname": "expected_discharge", | ||||||
|    "fieldtype": "Date", |    "fieldtype": "Date", | ||||||
|    "in_list_view": 1, |    "in_list_view": 1, | ||||||
|    "label": "Expected Discharge" |    "label": "Expected Discharge", | ||||||
|   }, |    "read_only": 1 | ||||||
|   { |  | ||||||
|    "fieldname": "discharge_date", |  | ||||||
|    "fieldtype": "Date", |  | ||||||
|    "in_list_view": 1, |  | ||||||
|    "label": "Discharge Date" |  | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "collapsible": 1, |    "collapsible": 1, | ||||||
|    "fieldname": "references", |    "fieldname": "references", | ||||||
|    "fieldtype": "Section Break", |    "fieldtype": "Section Break", | ||||||
|    "label": "References" |    "label": "Admission Order Details" | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "cb_admission", |    "fieldname": "cb_admission", | ||||||
|    "fieldtype": "Column Break", |    "fieldtype": "Column Break" | ||||||
|    "label": "Admission" |  | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "admission_practitioner", |    "fieldname": "admission_practitioner", | ||||||
| @ -172,10 +225,21 @@ | |||||||
|    "options": "Patient Encounter", |    "options": "Patient Encounter", | ||||||
|    "read_only": 1 |    "read_only": 1 | ||||||
|   }, |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "chief_complaint", | ||||||
|  |    "fieldtype": "Table MultiSelect", | ||||||
|  |    "label": "Chief Complaint", | ||||||
|  |    "options": "Patient Encounter Symptom" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "admission_instruction", | ||||||
|  |    "fieldtype": "Small Text", | ||||||
|  |    "label": "Admission Instruction", | ||||||
|  |    "set_only_once": 1 | ||||||
|  |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "cb_discharge", |    "fieldname": "cb_discharge", | ||||||
|    "fieldtype": "Column Break", |    "fieldtype": "Column Break" | ||||||
|    "label": "Discharge" |  | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "discharge_practitioner", |    "fieldname": "discharge_practitioner", | ||||||
| @ -192,10 +256,51 @@ | |||||||
|    "read_only": 1 |    "read_only": 1 | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|  |    "collapsible": 1, | ||||||
|  |    "fieldname": "medication_section", | ||||||
|  |    "fieldtype": "Section Break", | ||||||
|  |    "label": "Medications" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "drug_prescription", | ||||||
|  |    "fieldtype": "Table", | ||||||
|  |    "options": "Drug Prescription" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "collapsible": 1, | ||||||
|  |    "fieldname": "investigations_section", | ||||||
|  |    "fieldtype": "Section Break", | ||||||
|  |    "label": "Investigations" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "lab_test_prescription", | ||||||
|  |    "fieldtype": "Table", | ||||||
|  |    "options": "Lab Prescription" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "collapsible": 1, | ||||||
|  |    "fieldname": "procedures_section", | ||||||
|  |    "fieldtype": "Section Break", | ||||||
|  |    "label": "Procedures" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "procedure_prescription", | ||||||
|  |    "fieldtype": "Table", | ||||||
|  |    "options": "Procedure Prescription" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "depends_on": "eval:(doc.status != \"Admission Scheduled\")", | ||||||
|    "fieldname": "sb_inpatient_occupancy", |    "fieldname": "sb_inpatient_occupancy", | ||||||
|    "fieldtype": "Section Break", |    "fieldtype": "Section Break", | ||||||
|    "label": "Inpatient Occupancy" |    "label": "Inpatient Occupancy" | ||||||
|   }, |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "admission_service_unit_type", | ||||||
|  |    "fieldtype": "Link", | ||||||
|  |    "label": "Admission Service Unit Type", | ||||||
|  |    "options": "Healthcare Service Unit Type", | ||||||
|  |    "read_only": 1 | ||||||
|  |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "inpatient_occupancies", |    "fieldname": "inpatient_occupancies", | ||||||
|    "fieldtype": "Table", |    "fieldtype": "Table", | ||||||
| @ -208,10 +313,10 @@ | |||||||
|    "label": "Transfer" |    "label": "Transfer" | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "depends_on": "eval:doc.status != \"Admission Scheduled\"", |    "depends_on": "eval:(doc.status == \"Discharge Scheduled\" || doc.status == \"Discharged\")", | ||||||
|    "fieldname": "sb_discharge_note", |    "fieldname": "sb_discharge_note", | ||||||
|    "fieldtype": "Section Break", |    "fieldtype": "Section Break", | ||||||
|    "label": "Discharge Note" |    "label": "Discharge Notes" | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|    "fieldname": "discharge_note", |    "fieldname": "discharge_note", | ||||||
| @ -224,10 +329,76 @@ | |||||||
|    "in_standard_filter": 1, |    "in_standard_filter": 1, | ||||||
|    "label": "Company", |    "label": "Company", | ||||||
|    "options": "Company" |    "options": "Company" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "collapsible": 1, | ||||||
|  |    "collapsible_depends_on": "eval:(doc.status == \"Admitted\")", | ||||||
|  |    "fieldname": "encounter_details_section", | ||||||
|  |    "fieldtype": "Section Break", | ||||||
|  |    "label": "Encounter Impression" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "column_break_29", | ||||||
|  |    "fieldtype": "Column Break" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "diagnosis", | ||||||
|  |    "fieldtype": "Table MultiSelect", | ||||||
|  |    "label": "Diagnosis", | ||||||
|  |    "options": "Patient Encounter Diagnosis" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "followup_date", | ||||||
|  |    "fieldtype": "Date", | ||||||
|  |    "label": "Follow Up Date" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "collapsible": 1, | ||||||
|  |    "depends_on": "eval:(doc.status == \"Discharge Scheduled\" || doc.status == \"Discharged\")", | ||||||
|  |    "fieldname": "sb_discharge_details", | ||||||
|  |    "fieldtype": "Section Break", | ||||||
|  |    "label": "Discharge Detials" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "discharge_instructions", | ||||||
|  |    "fieldtype": "Small Text", | ||||||
|  |    "label": "Discharge Instructions" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "discharge_ordered_date", | ||||||
|  |    "fieldtype": "Date", | ||||||
|  |    "in_list_view": 1, | ||||||
|  |    "label": "Discharge Ordered Date", | ||||||
|  |    "read_only": 1 | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "collapsible": 1, | ||||||
|  |    "fieldname": "rehabilitation_section", | ||||||
|  |    "fieldtype": "Section Break", | ||||||
|  |    "label": "Rehabilitation" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "therapy_plan", | ||||||
|  |    "fieldtype": "Link", | ||||||
|  |    "hidden": 1, | ||||||
|  |    "label": "Therapy Plan", | ||||||
|  |    "options": "Therapy Plan", | ||||||
|  |    "read_only": 1 | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "therapies", | ||||||
|  |    "fieldtype": "Table", | ||||||
|  |    "options": "Therapy Plan Detail" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "fieldname": "discharge_date", | ||||||
|  |    "fieldtype": "Date", | ||||||
|  |    "label": "Discharge Date", | ||||||
|  |    "read_only": 1 | ||||||
|   } |   } | ||||||
|  ], |  ], | ||||||
|  "links": [], |  "links": [], | ||||||
|  "modified": "2020-04-07 13:13:39.351977", |  "modified": "2020-05-21 00:37:12.939925", | ||||||
|  "modified_by": "Administrator", |  "modified_by": "Administrator", | ||||||
|  "module": "Healthcare", |  "module": "Healthcare", | ||||||
|  "name": "Inpatient Record", |  "name": "Inpatient Record", | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ | |||||||
| # For license information, please see license.txt | # For license information, please see license.txt | ||||||
| 
 | 
 | ||||||
| from __future__ import unicode_literals | from __future__ import unicode_literals | ||||||
| import frappe | import frappe, json | ||||||
| from frappe import _ | from frappe import _ | ||||||
| from frappe.utils import today, now_datetime, getdate | from frappe.utils import today, now_datetime, getdate | ||||||
| from frappe.model.document import Document | from frappe.model.document import Document | ||||||
| @ -11,8 +11,12 @@ from frappe.desk.reportview import get_match_cond | |||||||
| 
 | 
 | ||||||
| class InpatientRecord(Document): | class InpatientRecord(Document): | ||||||
| 	def after_insert(self): | 	def after_insert(self): | ||||||
| 		frappe.db.set_value("Patient", self.patient, "inpatient_status", "Admission Scheduled") | 		frappe.db.set_value('Patient', self.patient, 'inpatient_record', self.name) | ||||||
| 		frappe.db.set_value("Patient", self.patient, "inpatient_record", self.name) | 		frappe.db.set_value('Patient', self.patient, 'inpatient_status', self.status) | ||||||
|  | 
 | ||||||
|  | 		if self.admission_encounter: # Update encounter | ||||||
|  | 			frappe.db.set_value('Patient Encounter', self.admission_encounter, 'inpatient_record', self.name) | ||||||
|  | 			frappe.db.set_value('Patient Encounter', self.admission_encounter, 'inpatient_status', self.status) | ||||||
| 
 | 
 | ||||||
| 	def validate(self): | 	def validate(self): | ||||||
| 		self.validate_dates() | 		self.validate_dates() | ||||||
| @ -26,7 +30,7 @@ class InpatientRecord(Document): | |||||||
| 			(getdate(self.admitted_datetime) < getdate(today())): | 			(getdate(self.admitted_datetime) < getdate(today())): | ||||||
| 				frappe.throw(_("Scheduled and Admitted dates can not be less than today")) | 				frappe.throw(_("Scheduled and Admitted dates can not be less than today")) | ||||||
| 		if (getdate(self.expected_discharge) < getdate(self.scheduled_date)) or \ | 		if (getdate(self.expected_discharge) < getdate(self.scheduled_date)) or \ | ||||||
| 			(getdate(self.discharge_date) < getdate(self.scheduled_date)): | 			(getdate(self.discharge_ordered_date) < getdate(self.scheduled_date)): | ||||||
| 			frappe.throw(_("Expected and Discharge dates cannot be less than Admission Schedule date")) | 			frappe.throw(_("Expected and Discharge dates cannot be less than Admission Schedule date")) | ||||||
| 	 | 	 | ||||||
| 	def validate_already_scheduled_or_admitted(self): | 	def validate_already_scheduled_or_admitted(self): | ||||||
| @ -59,37 +63,76 @@ class InpatientRecord(Document): | |||||||
| 		if service_unit: | 		if service_unit: | ||||||
| 			transfer_patient(self, service_unit, check_in) | 			transfer_patient(self, service_unit, check_in) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| @frappe.whitelist() | @frappe.whitelist() | ||||||
| def schedule_inpatient(patient, encounter_id, practitioner): | def schedule_inpatient(args): | ||||||
| 	patient_obj = frappe.get_doc('Patient', patient) | 	admission_order = json.loads(args) # admission order via Encounter | ||||||
|  | 	if not admission_order or not admission_order['patient'] or not admission_order['admission_encounter']: | ||||||
|  | 		frappe.throw(_('Missing required details, did not create Inpatient Record')) | ||||||
|  | 
 | ||||||
| 	inpatient_record = frappe.new_doc('Inpatient Record') | 	inpatient_record = frappe.new_doc('Inpatient Record') | ||||||
| 	inpatient_record.patient = patient | 
 | ||||||
| 	inpatient_record.patient_name = patient_obj.patient_name | 	# Admission order details | ||||||
| 	inpatient_record.gender = patient_obj.sex | 	set_details_from_ip_order(inpatient_record, admission_order) | ||||||
| 	inpatient_record.blood_group = patient_obj.blood_group | 
 | ||||||
| 	inpatient_record.dob = patient_obj.dob | 	# Patient details | ||||||
| 	inpatient_record.mobile = patient_obj.mobile | 	patient = frappe.get_doc('Patient', admission_order['patient']) | ||||||
| 	inpatient_record.email = patient_obj.email | 	inpatient_record.patient = patient.name | ||||||
| 	inpatient_record.phone = patient_obj.phone | 	inpatient_record.patient_name = patient.patient_name | ||||||
| 	inpatient_record.status = "Admission Scheduled" | 	inpatient_record.gender = patient.sex | ||||||
|  | 	inpatient_record.blood_group = patient.blood_group | ||||||
|  | 	inpatient_record.dob = patient.dob | ||||||
|  | 	inpatient_record.mobile = patient.mobile | ||||||
|  | 	inpatient_record.email = patient.email | ||||||
|  | 	inpatient_record.phone = patient.phone | ||||||
| 	inpatient_record.scheduled_date = today() | 	inpatient_record.scheduled_date = today() | ||||||
| 	inpatient_record.admission_practitioner = practitioner | 
 | ||||||
| 	inpatient_record.admission_encounter = encounter_id | 	# Set encounter detials | ||||||
|  | 	encounter = frappe.get_doc('Patient Encounter', admission_order['admission_encounter']) | ||||||
|  | 	if encounter and encounter.symptoms: # Symptoms | ||||||
|  | 		set_ip_child_records(inpatient_record, 'chief_complaint', encounter.symptoms) | ||||||
|  | 
 | ||||||
|  | 	if encounter and encounter.diagnosis: # Diagnosis | ||||||
|  | 		set_ip_child_records(inpatient_record, 'diagnosis', encounter.diagnosis) | ||||||
|  | 
 | ||||||
|  | 	if encounter and encounter.drug_prescription: # Medication | ||||||
|  | 		set_ip_child_records(inpatient_record, 'drug_prescription', encounter.drug_prescription) | ||||||
|  | 
 | ||||||
|  | 	if encounter and encounter.lab_test_prescription: # Lab Tests | ||||||
|  | 		set_ip_child_records(inpatient_record, 'lab_test_prescription', encounter.lab_test_prescription) | ||||||
|  | 
 | ||||||
|  | 	if encounter and encounter.procedure_prescription: # Procedure Prescription | ||||||
|  | 		set_ip_child_records(inpatient_record, 'procedure_prescription', encounter.procedure_prescription) | ||||||
|  | 
 | ||||||
|  | 	if encounter and encounter.therapies: # Therapies | ||||||
|  | 		inpatient_record.therapy_plan = encounter.therapy_plan | ||||||
|  | 		set_ip_child_records(inpatient_record, 'therapies', encounter.therapies) | ||||||
|  | 
 | ||||||
|  | 	inpatient_record.status = 'Admission Scheduled' | ||||||
| 	inpatient_record.save(ignore_permissions = True) | 	inpatient_record.save(ignore_permissions = True) | ||||||
| 
 | 
 | ||||||
| @frappe.whitelist() | @frappe.whitelist() | ||||||
| def schedule_discharge(patient, encounter_id=None, practitioner=None): | def schedule_discharge(args): | ||||||
| 	inpatient_record_id = frappe.db.get_value('Patient', patient, 'inpatient_record') | 	discharge_order = json.loads(args) | ||||||
|  | 	inpatient_record_id = frappe.db.get_value('Patient', discharge_order['patient'], 'inpatient_record') | ||||||
| 	if inpatient_record_id: | 	if inpatient_record_id: | ||||||
| 		inpatient_record = frappe.get_doc("Inpatient Record", inpatient_record_id) | 		inpatient_record = frappe.get_doc('Inpatient Record', inpatient_record_id) | ||||||
| 		inpatient_record.discharge_practitioner = practitioner |  | ||||||
| 		inpatient_record.discharge_encounter = encounter_id |  | ||||||
| 		inpatient_record.status = "Discharge Scheduled" |  | ||||||
| 
 |  | ||||||
| 		check_out_inpatient(inpatient_record) | 		check_out_inpatient(inpatient_record) | ||||||
| 
 | 		set_details_from_ip_order(inpatient_record, discharge_order) | ||||||
|  | 		inpatient_record.status = 'Discharge Scheduled' | ||||||
| 		inpatient_record.save(ignore_permissions = True) | 		inpatient_record.save(ignore_permissions = True) | ||||||
| 	frappe.db.set_value("Patient", patient, "inpatient_status", "Discharge Scheduled") | 		frappe.db.set_value('Patient', discharge_order['patient'], 'inpatient_status', inpatient_record.status) | ||||||
|  | 		frappe.db.set_value('Patient Encounter', inpatient_record.discharge_encounter, 'inpatient_status', inpatient_record.status) | ||||||
|  | 
 | ||||||
|  | def set_details_from_ip_order(inpatient_record, ip_order): | ||||||
|  | 	for key in ip_order: | ||||||
|  | 		inpatient_record.set(key, ip_order[key]) | ||||||
|  | 
 | ||||||
|  | def set_ip_child_records(inpatient_record, inpatient_record_child, encounter_child): | ||||||
|  | 	for item in encounter_child: | ||||||
|  | 		table = inpatient_record.append(inpatient_record_child) | ||||||
|  | 		for df in table.meta.get('fields'): | ||||||
|  | 			table.set(df.fieldname, item.get(df.fieldname)) | ||||||
| 
 | 
 | ||||||
| def check_out_inpatient(inpatient_record): | def check_out_inpatient(inpatient_record): | ||||||
| 	if inpatient_record.inpatient_occupancies: | 	if inpatient_record.inpatient_occupancies: | ||||||
| @ -149,14 +192,14 @@ def get_inpatient_docs_not_invoiced(doc, inpatient_record): | |||||||
| 
 | 
 | ||||||
| def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=None): | def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=None): | ||||||
| 	inpatient_record.admitted_datetime = check_in | 	inpatient_record.admitted_datetime = check_in | ||||||
| 	inpatient_record.status = "Admitted" | 	inpatient_record.status = 'Admitted' | ||||||
| 	inpatient_record.expected_discharge = expected_discharge | 	inpatient_record.expected_discharge = expected_discharge | ||||||
| 
 | 
 | ||||||
| 	inpatient_record.set('inpatient_occupancies', []) | 	inpatient_record.set('inpatient_occupancies', []) | ||||||
| 	transfer_patient(inpatient_record, service_unit, check_in) | 	transfer_patient(inpatient_record, service_unit, check_in) | ||||||
| 
 | 
 | ||||||
| 	frappe.db.set_value("Patient", inpatient_record.patient, "inpatient_status", "Admitted") | 	frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_status', 'Admitted') | ||||||
| 	frappe.db.set_value("Patient", inpatient_record.patient, "inpatient_record", inpatient_record.name) | 	frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_record', inpatient_record.name) | ||||||
| 
 | 
 | ||||||
| def transfer_patient(inpatient_record, service_unit, check_in): | def transfer_patient(inpatient_record, service_unit, check_in): | ||||||
| 	item_line = inpatient_record.append('inpatient_occupancies', {}) | 	item_line = inpatient_record.append('inpatient_occupancies', {}) | ||||||
|  | |||||||
| @ -180,32 +180,111 @@ frappe.ui.form.on('Patient Encounter', { | |||||||
| 	} | 	} | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| let schedule_inpatient = function(frm) { | var schedule_inpatient = function(frm) { | ||||||
|  | 	var dialog = new frappe.ui.Dialog({ | ||||||
|  | 		title: 'Patient Admission', | ||||||
|  | 		fields: [ | ||||||
|  | 			{fieldtype: 'Link', label: 'Medical Department', fieldname: 'medical_department', options: 'Medical Department', reqd: 1}, | ||||||
|  | 			{fieldtype: 'Link', label: 'Healthcare Practitioner (Primary)', fieldname: 'primary_practitioner', options: 'Healthcare Practitioner', reqd: 1}, | ||||||
|  | 			{fieldtype: 'Link', label: 'Healthcare Practitioner (Secondary)', fieldname: 'secondary_practitioner', options: 'Healthcare Practitioner'}, | ||||||
|  | 			{fieldtype: 'Column Break'}, | ||||||
|  | 			{fieldtype: 'Date', label: 'Admission Ordered For', fieldname: 'admission_ordered_for', default: 'Today'}, | ||||||
|  | 			{fieldtype: 'Link', label: 'Service Unit Type', fieldname: 'service_unit_type', options: 'Healthcare Service Unit Type'}, | ||||||
|  | 			{fieldtype: 'Int', label: 'Expected Length of Stay', fieldname: 'expected_length_of_stay'}, | ||||||
|  | 			{fieldtype: 'Section Break', label: 'Admission Instructions'}, | ||||||
|  | 			{fieldtype: 'Small Text', fieldname: 'admission_instruction'} | ||||||
|  | 		], | ||||||
|  | 		primary_action_label: __('Order Admission'), | ||||||
|  | 		primary_action : function() { | ||||||
|  | 			var args = { | ||||||
|  | 				patient: frm.doc.patient, | ||||||
|  | 				admission_encounter: frm.doc.name, | ||||||
|  | 				referring_practitioner: frm.doc.practitioner, | ||||||
|  | 				company: frm.doc.company, | ||||||
|  | 				medical_department: dialog.get_value('medical_department'), | ||||||
|  | 				primary_practitioner: dialog.get_value('primary_practitioner'), | ||||||
|  | 				secondary_practitioner: dialog.get_value('secondary_practitioner'), | ||||||
|  | 				admission_ordered_for: dialog.get_value('admission_ordered_for'), | ||||||
|  | 				admission_service_unit_type: dialog.get_value('service_unit_type'), | ||||||
|  | 				expected_length_of_stay: dialog.get_value('expected_length_of_stay'), | ||||||
|  | 				admission_instruction: dialog.get_value('admission_instruction') | ||||||
|  | 			} | ||||||
| 			frappe.call({ | 			frappe.call({ | ||||||
| 				method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_inpatient', | 				method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_inpatient', | ||||||
| 		args: {patient: frm.doc.patient, encounter_id: frm.doc.name, practitioner: frm.doc.practitioner}, | 				args: { | ||||||
|  | 					args: args | ||||||
|  | 				}, | ||||||
| 				callback: function(data) { | 				callback: function(data) { | ||||||
| 					if(!data.exc){ | 					if(!data.exc){ | ||||||
| 						frm.reload_doc(); | 						frm.reload_doc(); | ||||||
| 					} | 					} | ||||||
| 				}, | 				}, | ||||||
| 				freeze: true, | 				freeze: true, | ||||||
| 		freeze_message: __('Process Inpatient Scheduling') | 				freeze_message: 'Scheduling Patient Admission' | ||||||
| 			}); | 			}); | ||||||
|  | 			frm.refresh_fields(); | ||||||
|  | 			dialog.hide(); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  | 
 | ||||||
|  | 	dialog.set_values({ | ||||||
|  | 		'medical_department': frm.doc.medical_department, | ||||||
|  | 		'primary_practitioner': frm.doc.practitioner, | ||||||
|  | 	}); | ||||||
|  | 
 | ||||||
|  | 	dialog.fields_dict['service_unit_type'].get_query = function() { | ||||||
|  | 		return { | ||||||
|  | 			filters: { | ||||||
|  | 				'inpatient_occupancy': 1, | ||||||
|  | 				'allow_appointments': 0 | ||||||
|  | 			} | ||||||
|  | 		}; | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| let schedule_discharge = function(frm) { | 	dialog.show(); | ||||||
|  | 	dialog.$wrapper.find('.modal-dialog').css('width', '800px'); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | var schedule_discharge = function(frm) { | ||||||
|  | 	var dialog = new frappe.ui.Dialog ({ | ||||||
|  | 		title: 'Inpatient Discharge', | ||||||
|  | 		fields: [ | ||||||
|  | 			{fieldtype: 'Date', label: 'Discharge Ordered Date', fieldname: 'discharge_ordered_date', default: 'Today', read_only: 1}, | ||||||
|  | 			{fieldtype: 'Date', label: 'Followup Date', fieldname: 'followup_date'}, | ||||||
|  | 			{fieldtype: 'Column Break'}, | ||||||
|  | 			{fieldtype: 'Small Text', label: 'Discharge Instructions', fieldname: 'discharge_instructions'}, | ||||||
|  | 			{fieldtype: 'Section Break', label:'Discharge Summary'}, | ||||||
|  | 			{fieldtype: 'Text Editor', label: 'Discharge Note', fieldname: 'discharge_note'} | ||||||
|  | 		], | ||||||
|  | 		primary_action_label: __('Order Discharge'), | ||||||
|  | 		primary_action : function() { | ||||||
|  | 			var args = { | ||||||
|  | 				patient: frm.doc.patient, | ||||||
|  | 				discharge_encounter: frm.doc.name, | ||||||
|  | 				discharge_practitioner: frm.doc.practitioner, | ||||||
|  | 				discharge_ordered_date: dialog.get_value('discharge_ordered_date'), | ||||||
|  | 				followup_date: dialog.get_value('followup_date'), | ||||||
|  | 				discharge_instructions: dialog.get_value('discharge_instructions'), | ||||||
|  | 				discharge_note: dialog.get_value('discharge_note') | ||||||
|  | 			} | ||||||
| 			frappe.call ({ | 			frappe.call ({ | ||||||
| 				method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_discharge', | 				method: 'erpnext.healthcare.doctype.inpatient_record.inpatient_record.schedule_discharge', | ||||||
| 		args: {patient: frm.doc.patient, encounter_id: frm.doc.name, practitioner: frm.doc.practitioner}, | 				args: {args}, | ||||||
| 				callback: function(data) { | 				callback: function(data) { | ||||||
| 					if(!data.exc){ | 					if(!data.exc){ | ||||||
| 						frm.reload_doc(); | 						frm.reload_doc(); | ||||||
| 					} | 					} | ||||||
| 				}, | 				}, | ||||||
| 				freeze: true, | 				freeze: true, | ||||||
| 		freeze_message: 'Process Discharge' | 				freeze_message: 'Scheduling Inpatient Discharge' | ||||||
| 			}); | 			}); | ||||||
|  | 			frm.refresh_fields(); | ||||||
|  | 			dialog.hide(); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  | 
 | ||||||
|  | 	dialog.show(); | ||||||
|  | 	dialog.$wrapper.find('.modal-dialog').css('width', '800px'); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| let create_medical_record = function(frm) { | let create_medical_record = function(frm) { | ||||||
|  | |||||||
| @ -52,6 +52,7 @@ | |||||||
|  ], |  ], | ||||||
|  "fields": [ |  "fields": [ | ||||||
|   { |   { | ||||||
|  |    "allow_on_submit": 1, | ||||||
|    "fieldname": "inpatient_record", |    "fieldname": "inpatient_record", | ||||||
|    "fieldtype": "Link", |    "fieldtype": "Link", | ||||||
|    "label": "Inpatient Record", |    "label": "Inpatient Record", | ||||||
| @ -296,6 +297,7 @@ | |||||||
|    "read_only": 1 |    "read_only": 1 | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|  |    "allow_on_submit": 1, | ||||||
|    "fieldname": "inpatient_status", |    "fieldname": "inpatient_status", | ||||||
|    "fieldtype": "Data", |    "fieldtype": "Data", | ||||||
|    "label": "Inpatient Status", |    "label": "Inpatient Status", | ||||||
| @ -326,7 +328,7 @@ | |||||||
|  ], |  ], | ||||||
|  "is_submittable": 1, |  "is_submittable": 1, | ||||||
|  "links": [], |  "links": [], | ||||||
|  "modified": "2020-04-27 21:58:29.789797", |  "modified": "2020-05-16 21:00:08.644531", | ||||||
|  "modified_by": "Administrator", |  "modified_by": "Administrator", | ||||||
|  "module": "Healthcare", |  "module": "Healthcare", | ||||||
|  "name": "Patient Encounter", |  "name": "Patient Encounter", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user