/// <summary> /// Validates this Prescription Item /// </summary> /// <param name="path">The path to this object as a string</param> /// <param name="messages">the validation messages to date, these may be added to within this method</param> public void Validate(string path, List <ValidationMessage> messages) { var vb = new ValidationBuilder(path, messages); if (vb.ArgumentRequiredCheck("DateTimePrescriptionExpires", DateTimePrescriptionExpires)) { if (DateTimePrescriptionExpires.PrecisionIndicator == null || DateTimePrescriptionExpires.PrecisionIndicator.Value != ISO8601DateTime.Precision.Day || DateTimePrescriptionExpires.TimeZone != null) { vb.AddValidationMessage(vb.PathName, null, "SHALL include a complete date (century, year, month and day)"); } } vb.ArgumentRequiredCheck("PrescriptionItemIdentifier", PrescriptionItemIdentifier); vb.ArgumentRequiredCheck("Directions", Directions); if (vb.ArgumentRequiredCheck("TherapeuticGoodIdentification", TherapeuticGoodIdentification)) { TherapeuticGoodIdentification.Validate(vb.Path + "TherapeuticGoodIdentification", messages); if (PBSRPBSItemCode != null && TherapeuticGoodIdentification.OriginalText.IsNullOrEmptyWhitespace()) { vb.AddValidationMessage(vb.PathName, null, "TherapeuticGoodIdentification's OriginalText is a required field when PBSRPBSItemCode is present"); } if (TherapeuticGoodIdentification.Translations != null) { vb.AddValidationMessage(vb.PathName, null, "Translations can not be set for TherapeuticGoodIdentification please use PBS/RPBS Item Code instead"); } } if (StructuredDose != null) { StructuredDose.Validate(vb.Path + "StructuredDose", messages); } if (Timing != null) { Timing.Validate(vb.Path + "Timing", messages); if (Timing.TimingDescription.IsNullOrEmptyWhitespace()) { vb.AddValidationMessage(vb.PathName, string.Empty, "If TIMING is included, Timing Description SHALL be fully and automatically derived"); } } if (PBSCloseTheGapBenefit != null) { PBSCloseTheGapBenefit.Validate(vb.Path + "PBSCloseTheGapBenefit", messages); } if (AdministrationDetails != null) { AdministrationDetails.Validate(vb.Path + "AdministrationDetails]", vb.Messages); } if (vb.ArgumentRequiredCheck("QuantityToDispense", QuantityToDispense)) { QuantityToDispense.ValidateDispensingUnit(vb.Path + "QuantityToDispense", messages); } vb.ArgumentRequiredCheck("MaximumNumberOfRepeats", MaximumNumberOfRepeats); if (MinimumIntervalBetweenRepeats != null) { MinimumIntervalBetweenRepeats.Validate(vb.Path + "MinimumIntervalBetweenRepeats", messages); } vb.ArgumentRequiredCheck("PBSPrescriptionType", PBSPrescriptionType); if (vb.ArgumentRequiredCheck("MedicalBenefitCategoryType", MedicalBenefitCategoryType)) { if (MedicalBenefitCategoryType.Value == Nehta.VendorLibrary.CDA.Common.Enums.MedicalBenefitCategoryType.CTG) { vb.AddValidationMessage(vb.PathName, null, "Medical Benefit Category Type of CTG is not valid for this document"); } } if (PBSRPBSItemCode != null) { PBSRPBSItemCode.Validate(vb.Path + "PBSRPBSItemCode", messages); } if (PBSRPBSManufacturerCode != null) { PBSRPBSManufacturerCode.Validate(vb.Path + "PBSRPBSManufacturerCode", messages); if (MedicalBenefitCategoryType.HasValue && !(MedicalBenefitCategoryType.Value == Nehta.VendorLibrary.CDA.Common.Enums.MedicalBenefitCategoryType.PBS || MedicalBenefitCategoryType.Value == Nehta.VendorLibrary.CDA.Common.Enums.MedicalBenefitCategoryType.RPBS)) { vb.AddValidationMessage(vb.PathName, null, "PBSRPBSManufacturerCode SHALL be present on an e-prescription where the Medical Benefit Type Category is one of the following: PBS RPBS "); } } vb.ArgumentRequiredCheck("GroundsForConcurrentSupply", GroundsForConcurrentSupply); if (PBSExtemporaneousIngredient != null) { for (var x = 0; x < PBSExtemporaneousIngredient.Count; x++) { PBSExtemporaneousIngredient[x].Validate(vb.Path + string.Format("PBSExtemporaneousIngredient[{0}]", x), vb.Messages); } } if (StateAuthorityNumber != null) { StateAuthorityNumber.Validate(vb.Path + "StateAuthorityNumber", messages); if (StateAuthorityNumber.Extension.IsNullOrEmptyWhitespace()) { vb.AddValidationMessage(vb.PathName, null, "Extension is required for StateAuthorityNumber"); } } if (MedicationInstructionIdentifier != null) { MedicationInstructionIdentifier.Validate(vb.Path + "MedicationInstructionIdentifier", messages); } if (DispenseItemIdentifier != null) { DispenseItemIdentifier.Validate(vb.Path + "DispenseItemIdentifier", messages); } if (Observations != null) { Observations.Validate(vb.Path + "Observations", messages); } }