@@ -85,6 +85,8 @@ def validate(self):
8585 self .pre_validate_route_coding_display ,
8686 self .pre_validate_dose_quantity_value ,
8787 self .pre_validate_dose_quantity_code ,
88+ self .pre_validate_dose_quantity_system ,
89+ self .pre_validate_dose_quantity_system_and_code ,
8890 self .pre_validate_dose_quantity_unit ,
8991 self .pre_validate_reason_code_codings ,
9092 self .pre_validate_reason_code_coding_codes ,
@@ -814,27 +816,17 @@ def pre_validate_dose_quantity_value(self, values: dict) -> dict:
814816 PreValidation .for_integer_or_decimal (field_value , "doseQuantity.value" )
815817 except KeyError :
816818 pass
817-
818- def pre_validate_dose_quantity_system_and_code (self , values : dict ) -> dict :
819+
820+ def pre_validate_dose_quantity_system (self , values : dict ) -> dict :
819821 """
820- Pre-validate doseQuantity.code and doseQuantity.system:
821- 1. If code exists, it must be a non-empty string (legacy CSV: DOSE_UNIT_CODE).
822- 2. If system exists, it must be a non-empty string.
823- 3. If code exists, system MUST also exist (FHIR SimpleQuantity rule).
822+ Pre-validate that if doseQuantity.system exists then it is a non-empty string:
823+ If system exists, it must be a non-empty string.
824824 """
825- field_value = values .get ("doseQuantity" , {})
826- code = field_value .get ("code" )
827- system = field_value .get ("system" )
828-
829- if code is not None :
830- PreValidation .for_string (code , "doseQuantity.code" )
831-
832- if system is not None :
833- PreValidation .for_string (system , "doseQuantity.system" )
834-
835- PreValidation .require_system_when_code_present (
836- code , system , "doseQuantity.code" , "doseQuantity.system"
837- )
825+ try :
826+ field_value = values ["doseQuantity" ]["system" ]
827+ PreValidation .for_string (field_value , "doseQuantity.system" )
828+ except KeyError :
829+ pass
838830
839831 def pre_validate_dose_quantity_code (self , values : dict ) -> dict :
840832 """
@@ -847,6 +839,21 @@ def pre_validate_dose_quantity_code(self, values: dict) -> dict:
847839 except KeyError :
848840 pass
849841
842+ def pre_validate_dose_quantity_system_and_code (self , values : dict ) -> dict :
843+ """
844+ Pre-validate doseQuantity.code and doseQuantity.system:
845+ 1. If code exists, system MUST also exist (FHIR SimpleQuantity rule).
846+ """
847+ dose_quantity = values .get ("doseQuantity" , {})
848+ code = dose_quantity .get ("code" )
849+ system = dose_quantity .get ("system" )
850+
851+ PreValidation .require_system_when_code_present (
852+ code , system , "doseQuantity.code" , "doseQuantity.system"
853+ )
854+
855+ return values
856+
850857 def pre_validate_dose_quantity_unit (self , values : dict ) -> dict :
851858 """
852859 Pre-validate that, if doseQuantity.unit (legacy CSV field name: DOSE_UNIT_TERM) exists,
0 commit comments