Skip to content

Commit 38a21f9

Browse files
authored
Update the availability of Xpert (#1725)
* update the availability of Xpert - to match the average of the last 4 months of 2018 (as per OpenLMIS) * add explanatory comments to script
1 parent f1ae3c6 commit 38a21f9

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:f945b15a98e571464b6931f0a3a071c1c90be93d8ba0bd9d1eca751caab34793
3-
size 55657974
2+
oid sha256:3bc044868ad9f1c618fc9b3fd6fc0ed23f32b153c8438f52fd4b72e40d8f503f
3+
size 55831644

src/scripts/data_file_processing/healthsystem/consumables/consumable_resource_analyses_with_lmis/consumables_availability_estimation.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,33 @@ def get_inflow_to_outflow_ratio_by_item_and_facilitylevel(_df):
765765
mwanza_1b = sf.loc[(sf.district_std == 'Mwanza') & (sf.fac_type_tlo == '1a')].copy().assign(fac_type_tlo='1b')
766766
sf = pd.concat([sf, mwanza_1b], axis=0, ignore_index=True)
767767

768-
# 4) Copy all the results to create a level 0 with an availability equal to half that in the respective 1a
768+
# 4) Update the availability Xpert (item_code = 187)
769+
# First add rows for Xpert at level 1b by cloning rows for level 2 -> only if not already present
770+
xpert_item = sf['item_code'].eq(187)
771+
level_2 = sf['fac_type_tlo'].eq('2')
772+
level_1b = sf['fac_type_tlo'].eq('1b')
773+
774+
# Clone rows from level 2
775+
base = sf.loc[level_2 & xpert_item].copy()
776+
new_rows = base.copy()
777+
new_rows['fac_type_tlo'] = '1b'
778+
779+
# Add rows to main availability dataframe and drop duplicates, if any
780+
sf = pd.concat([sf, new_rows], ignore_index=True)
781+
id_cols = [c for c in sf.columns if c != 'available_prop']
782+
dupe_mask = sf.duplicated(subset=id_cols, keep=False)
783+
dupes = sf.loc[dupe_mask].sort_values(id_cols)
784+
sf = sf.drop_duplicates(subset=id_cols, keep='first').reset_index(drop=True)
785+
786+
# Compute the average availability Sep–Dec (months >= 9) for level 2, item 187
787+
sep_to_dec = sf['month'].ge(9)
788+
new_xpert_availability = sf.loc[level_2 & xpert_item & sep_to_dec, 'available_prop'].mean()
789+
# Assign new availability to relevant facility levels
790+
levels_1b_2_or_3 = sf['fac_type_tlo'].isin(['1b', '2', '3'])
791+
xpert_item = sf['item_code'].eq(187)
792+
sf.loc[levels_1b_2_or_3 & xpert_item, 'available_prop'] = new_xpert_availability
793+
794+
# 5) Copy all the results to create a level 0 with an availability equal to half that in the respective 1a
769795
all_1a = sf.loc[sf.fac_type_tlo == '1a']
770796
all_0 = sf.loc[sf.fac_type_tlo == '1a'].copy().assign(fac_type_tlo='0')
771797
all_0.available_prop *= 0.5

0 commit comments

Comments
 (0)