fix: Inpatient Medication Order and Entry fixes
diff --git a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js
index b953b8a..f523cf2 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js
+++ b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js
@@ -21,6 +21,19 @@
 				}
 			};
 		});
+
+		frm.set_query('warehouse', () => {
+			return {
+				filters: {
+					company: frm.doc.company
+				}
+			};
+		});
+	},
+
+	patient: function(frm) {
+		if (frm.doc.patient)
+			frm.set_value('service_unit', '');
 	},
 
 	get_medication_orders: function(frm) {
diff --git a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json
index 5d80251..dd4c423 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json
+++ b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json
@@ -67,6 +67,7 @@
   },
   {
    "collapsible": 1,
+   "collapsible_depends_on": "eval: doc.__islocal",
    "fieldname": "filters_section",
    "fieldtype": "Section Break",
    "label": "Filters"
@@ -93,6 +94,7 @@
    "options": "Patient"
   },
   {
+   "depends_on": "eval:!doc.patient",
    "fieldname": "service_unit",
    "fieldtype": "Link",
    "label": "Healthcare Service Unit",
@@ -178,7 +180,7 @@
  "index_web_pages_for_search": 1,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-09-30 23:40:45.528715",
+ "modified": "2020-11-03 13:22:37.820707",
  "modified_by": "Administrator",
  "module": "Healthcare",
  "name": "Inpatient Medication Entry",
diff --git a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
index 2385893..23e7519 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
+++ b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
@@ -199,6 +199,7 @@
 
 def get_pending_medication_orders(entry):
 	filters, values = get_filters(entry)
+	to_remove = []
 
 	data = frappe.db.sql("""
 		SELECT
@@ -225,7 +226,10 @@
 		doc['service_unit'] = get_current_healthcare_service_unit(inpatient_record)
 
 		if entry.service_unit and doc.service_unit != entry.service_unit:
-			data.remove(doc)
+			to_remove.append(doc)
+
+	for doc in to_remove:
+		data.remove(doc)
 
 	return data
 
diff --git a/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js b/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js
index c51f3cf..690e2e7 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js
+++ b/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js
@@ -12,7 +12,8 @@
 		frm.set_query('patient', () => {
 			return {
 				filters: {
-					'inpatient_record': ['!=', '']
+					'inpatient_record': ['!=', ''],
+					'inpatient_status': 'Admitted'
 				}
 			};
 		});