@@ -799,9 +799,6 @@ def pre_validate_route_coding_display(self, values: dict) -> dict:
799799 except (KeyError , IndexError ):
800800 pass
801801
802- # TODO: need to validate that doseQuantity.system is "http://unitsofmeasure.org"?
803- # Check with Martin
804-
805802 def pre_validate_dose_quantity_value (self , values : dict ) -> dict :
806803 """
807804 Pre-validate that, if doseQuantity.value (legacy CSV field name: DOSE_AMOUNT) exists,
@@ -817,7 +814,28 @@ def pre_validate_dose_quantity_value(self, values: dict) -> dict:
817814 PreValidation .for_integer_or_decimal (field_value , "doseQuantity.value" )
818815 except KeyError :
819816 pass
817+
818+ def pre_validate_dose_quantity_system_and_code (self , values : dict ) -> dict :
819+ """
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).
824+ """
825+ field_value = values .get ("doseQuantity" , {})
826+ code = field_value .get ("code" )
827+ system = field_value .get ("system" )
820828
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+ )
838+
821839 def pre_validate_dose_quantity_code (self , values : dict ) -> dict :
822840 """
823841 Pre-validate that, if doseQuantity.code (legacy CSV field name: DOSE_UNIT_CODE) exists,
0 commit comments