1use crate::SofError;
23use crate::constants::ConstantValue;
24use helios_fhir::FhirResource;
25use helios_fhirpath::EvaluationResult;
26
27pub trait ViewDefinitionTrait {
56 type Select: ViewDefinitionSelectTrait;
58 type Where: ViewDefinitionWhereTrait;
60 type Constant: ViewDefinitionConstantTrait;
62
63 fn resource(&self) -> Option<&str>;
65 fn select(&self) -> Option<&[Self::Select]>;
67 fn where_clauses(&self) -> Option<&[Self::Where]>;
69 fn constants(&self) -> Option<&[Self::Constant]>;
71}
72
73pub trait ViewDefinitionSelectTrait {
111 type Column: ViewDefinitionColumnTrait;
113 type Select: ViewDefinitionSelectTrait;
115
116 fn column(&self) -> Option<&[Self::Column]>;
118 fn select(&self) -> Option<&[Self::Select]>;
120 fn for_each(&self) -> Option<&str>;
122 fn for_each_or_null(&self) -> Option<&str>;
124 fn repeat(&self) -> Option<Vec<&str>>;
126 fn union_all(&self) -> Option<&[Self::Select]>;
128}
129
130pub trait ViewDefinitionColumnTrait {
165 fn name(&self) -> Option<&str>;
167 fn path(&self) -> Option<&str>;
169 fn collection(&self) -> Option<bool>;
171}
172
173pub trait ViewDefinitionWhereTrait {
209 fn path(&self) -> Option<&str>;
211}
212
213pub trait ViewDefinitionConstantTrait {
266 fn name(&self) -> Option<&str>;
268 fn to_evaluation_result(&self) -> Result<EvaluationResult, SofError>;
270}
271
272pub trait BundleTrait {
310 type Resource: ResourceTrait;
312
313 fn entries(&self) -> Vec<&Self::Resource>;
315}
316
317pub trait ResourceTrait: Clone {
345 fn resource_name(&self) -> &str;
347 fn to_fhir_resource(&self) -> FhirResource;
349 fn get_last_updated(&self) -> Option<chrono::DateTime<chrono::Utc>>;
351}
352
353#[cfg(feature = "R4")]
365mod r4_impl {
366 use super::*;
367 use helios_fhir::r4::*;
368
369 impl ViewDefinitionTrait for ViewDefinition {
370 type Select = ViewDefinitionSelect;
371 type Where = ViewDefinitionWhere;
372 type Constant = ViewDefinitionConstant;
373
374 fn resource(&self) -> Option<&str> {
375 self.resource.value.as_deref()
376 }
377
378 fn select(&self) -> Option<&[Self::Select]> {
379 self.select.as_deref()
380 }
381
382 fn where_clauses(&self) -> Option<&[Self::Where]> {
383 self.r#where.as_deref()
384 }
385
386 fn constants(&self) -> Option<&[Self::Constant]> {
387 self.constant.as_deref()
388 }
389 }
390
391 impl ViewDefinitionSelectTrait for ViewDefinitionSelect {
392 type Column = ViewDefinitionSelectColumn;
393 type Select = ViewDefinitionSelect;
394
395 fn column(&self) -> Option<&[Self::Column]> {
396 self.column.as_deref()
397 }
398
399 fn select(&self) -> Option<&[Self::Select]> {
400 self.select.as_deref()
401 }
402
403 fn for_each(&self) -> Option<&str> {
404 self.for_each.as_ref()?.value.as_deref()
405 }
406
407 fn for_each_or_null(&self) -> Option<&str> {
408 self.for_each_or_null.as_ref()?.value.as_deref()
409 }
410
411 fn repeat(&self) -> Option<Vec<&str>> {
412 self.repeat
413 .as_ref()
414 .map(|paths| paths.iter().filter_map(|p| p.value.as_deref()).collect())
415 }
416
417 fn union_all(&self) -> Option<&[Self::Select]> {
418 self.union_all.as_deref()
419 }
420 }
421
422 impl ViewDefinitionColumnTrait for ViewDefinitionSelectColumn {
423 fn name(&self) -> Option<&str> {
424 self.name.value.as_deref()
425 }
426
427 fn path(&self) -> Option<&str> {
428 self.path.value.as_deref()
429 }
430
431 fn collection(&self) -> Option<bool> {
432 self.collection.as_ref()?.value
433 }
434 }
435
436 impl ViewDefinitionWhereTrait for ViewDefinitionWhere {
437 fn path(&self) -> Option<&str> {
438 self.path.value.as_deref()
439 }
440 }
441
442 impl ViewDefinitionConstantTrait for ViewDefinitionConstant {
443 fn name(&self) -> Option<&str> {
444 self.name.value.as_deref()
445 }
446
447 fn to_evaluation_result(&self) -> Result<EvaluationResult, SofError> {
448 let name = self.name().unwrap_or("unknown");
449 let value = self.value.as_ref().ok_or_else(|| {
450 SofError::InvalidViewDefinition(format!("Constant '{name}' must have a value"))
451 })?;
452 r4_constant_to_neutral(value).to_evaluation_result()
453 }
454 }
455
456 fn r4_constant_to_neutral(value: &ViewDefinitionConstantValue) -> ConstantValue {
457 match value {
458 ViewDefinitionConstantValue::String(s) => {
459 ConstantValue::String(s.value.clone().unwrap_or_default())
460 }
461 ViewDefinitionConstantValue::Boolean(b) => {
462 ConstantValue::Boolean(b.value.unwrap_or(false))
463 }
464 ViewDefinitionConstantValue::Integer(i) => {
465 ConstantValue::Integer(i.value.unwrap_or(0) as i64)
466 }
467 ViewDefinitionConstantValue::PositiveInt(p) => {
468 ConstantValue::PositiveInt(p.value.unwrap_or(1) as i64)
469 }
470 ViewDefinitionConstantValue::UnsignedInt(u) => {
471 ConstantValue::UnsignedInt(u.value.unwrap_or(0) as i64)
472 }
473 ViewDefinitionConstantValue::Decimal(d) => ConstantValue::Decimal(
474 d.value
475 .as_ref()
476 .map(|p| p.original_string().to_string())
477 .unwrap_or_else(|| "0".to_string()),
478 ),
479 ViewDefinitionConstantValue::Date(d) => {
480 ConstantValue::Date(d.value.clone().unwrap_or_default().to_string())
481 }
482 ViewDefinitionConstantValue::DateTime(dt) => {
483 ConstantValue::DateTime(dt.value.clone().unwrap_or_default().to_string())
484 }
485 ViewDefinitionConstantValue::Time(t) => {
486 ConstantValue::Time(t.value.clone().unwrap_or_default().to_string())
487 }
488 ViewDefinitionConstantValue::Instant(i) => {
489 ConstantValue::Instant(i.value.clone().unwrap_or_default().to_string())
490 }
491 ViewDefinitionConstantValue::Code(c) => {
492 ConstantValue::Code(c.value.clone().unwrap_or_default())
493 }
494 ViewDefinitionConstantValue::Base64Binary(b) => {
495 ConstantValue::Base64Binary(b.value.clone().unwrap_or_default())
496 }
497 ViewDefinitionConstantValue::Id(i) => {
498 ConstantValue::Identifier(i.value.clone().unwrap_or_default())
499 }
500 ViewDefinitionConstantValue::Oid(o) => {
501 ConstantValue::Identifier(o.value.clone().unwrap_or_default())
502 }
503 ViewDefinitionConstantValue::Uri(u) => {
504 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
505 }
506 ViewDefinitionConstantValue::Url(u) => {
507 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
508 }
509 ViewDefinitionConstantValue::Uuid(u) => {
510 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
511 }
512 ViewDefinitionConstantValue::Canonical(c) => {
513 ConstantValue::Identifier(c.value.clone().unwrap_or_default())
514 }
515 }
516 }
517
518 impl BundleTrait for Bundle {
519 type Resource = Resource;
520
521 fn entries(&self) -> Vec<&Self::Resource> {
522 self.entry
523 .as_ref()
524 .map(|entries| entries.iter().filter_map(|e| e.resource.as_ref()).collect())
525 .unwrap_or_default()
526 }
527 }
528
529 impl ResourceTrait for Resource {
530 fn resource_name(&self) -> &str {
531 self.resource_name()
532 }
533
534 fn to_fhir_resource(&self) -> FhirResource {
535 FhirResource::R4(Box::new(self.clone()))
536 }
537
538 fn get_last_updated(&self) -> Option<chrono::DateTime<chrono::Utc>> {
539 self.get_last_updated()
540 }
541 }
542}
543
544#[cfg(feature = "R4B")]
550mod r4b_impl {
551 use super::*;
552 use helios_fhir::r4b::*;
553
554 impl ViewDefinitionTrait for ViewDefinition {
555 type Select = ViewDefinitionSelect;
556 type Where = ViewDefinitionWhere;
557 type Constant = ViewDefinitionConstant;
558
559 fn resource(&self) -> Option<&str> {
560 self.resource.value.as_deref()
561 }
562
563 fn select(&self) -> Option<&[Self::Select]> {
564 self.select.as_deref()
565 }
566
567 fn where_clauses(&self) -> Option<&[Self::Where]> {
568 self.r#where.as_deref()
569 }
570
571 fn constants(&self) -> Option<&[Self::Constant]> {
572 self.constant.as_deref()
573 }
574 }
575
576 impl ViewDefinitionSelectTrait for ViewDefinitionSelect {
577 type Column = ViewDefinitionSelectColumn;
578 type Select = ViewDefinitionSelect;
579
580 fn column(&self) -> Option<&[Self::Column]> {
581 self.column.as_deref()
582 }
583
584 fn select(&self) -> Option<&[Self::Select]> {
585 self.select.as_deref()
586 }
587
588 fn for_each(&self) -> Option<&str> {
589 self.for_each.as_ref()?.value.as_deref()
590 }
591
592 fn for_each_or_null(&self) -> Option<&str> {
593 self.for_each_or_null.as_ref()?.value.as_deref()
594 }
595
596 fn repeat(&self) -> Option<Vec<&str>> {
597 self.repeat
598 .as_ref()
599 .map(|paths| paths.iter().filter_map(|p| p.value.as_deref()).collect())
600 }
601
602 fn union_all(&self) -> Option<&[Self::Select]> {
603 self.union_all.as_deref()
604 }
605 }
606
607 impl ViewDefinitionColumnTrait for ViewDefinitionSelectColumn {
608 fn name(&self) -> Option<&str> {
609 self.name.value.as_deref()
610 }
611
612 fn path(&self) -> Option<&str> {
613 self.path.value.as_deref()
614 }
615
616 fn collection(&self) -> Option<bool> {
617 self.collection.as_ref()?.value
618 }
619 }
620
621 impl ViewDefinitionWhereTrait for ViewDefinitionWhere {
622 fn path(&self) -> Option<&str> {
623 self.path.value.as_deref()
624 }
625 }
626
627 impl ViewDefinitionConstantTrait for ViewDefinitionConstant {
628 fn name(&self) -> Option<&str> {
629 self.name.value.as_deref()
630 }
631
632 fn to_evaluation_result(&self) -> Result<EvaluationResult, SofError> {
633 let name = self.name().unwrap_or("unknown");
634 let value = self.value.as_ref().ok_or_else(|| {
635 SofError::InvalidViewDefinition(format!("Constant '{name}' must have a value"))
636 })?;
637 r4b_constant_to_neutral(value).to_evaluation_result()
638 }
639 }
640
641 fn r4b_constant_to_neutral(value: &ViewDefinitionConstantValue) -> ConstantValue {
642 match value {
643 ViewDefinitionConstantValue::String(s) => {
644 ConstantValue::String(s.value.clone().unwrap_or_default())
645 }
646 ViewDefinitionConstantValue::Boolean(b) => {
647 ConstantValue::Boolean(b.value.unwrap_or(false))
648 }
649 ViewDefinitionConstantValue::Integer(i) => {
650 ConstantValue::Integer(i.value.unwrap_or(0) as i64)
651 }
652 ViewDefinitionConstantValue::PositiveInt(p) => {
653 ConstantValue::PositiveInt(p.value.unwrap_or(1) as i64)
654 }
655 ViewDefinitionConstantValue::UnsignedInt(u) => {
656 ConstantValue::UnsignedInt(u.value.unwrap_or(0) as i64)
657 }
658 ViewDefinitionConstantValue::Decimal(d) => ConstantValue::Decimal(
659 d.value
660 .as_ref()
661 .map(|p| p.original_string().to_string())
662 .unwrap_or_else(|| "0".to_string()),
663 ),
664 ViewDefinitionConstantValue::Date(d) => {
665 ConstantValue::Date(d.value.clone().unwrap_or_default().to_string())
666 }
667 ViewDefinitionConstantValue::DateTime(dt) => {
668 ConstantValue::DateTime(dt.value.clone().unwrap_or_default().to_string())
669 }
670 ViewDefinitionConstantValue::Time(t) => {
671 ConstantValue::Time(t.value.clone().unwrap_or_default().to_string())
672 }
673 ViewDefinitionConstantValue::Instant(i) => {
674 ConstantValue::Instant(i.value.clone().unwrap_or_default().to_string())
675 }
676 ViewDefinitionConstantValue::Code(c) => {
677 ConstantValue::Code(c.value.clone().unwrap_or_default())
678 }
679 ViewDefinitionConstantValue::Base64Binary(b) => {
680 ConstantValue::Base64Binary(b.value.clone().unwrap_or_default())
681 }
682 ViewDefinitionConstantValue::Id(i) => {
683 ConstantValue::Identifier(i.value.clone().unwrap_or_default())
684 }
685 ViewDefinitionConstantValue::Oid(o) => {
686 ConstantValue::Identifier(o.value.clone().unwrap_or_default())
687 }
688 ViewDefinitionConstantValue::Uri(u) => {
689 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
690 }
691 ViewDefinitionConstantValue::Url(u) => {
692 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
693 }
694 ViewDefinitionConstantValue::Uuid(u) => {
695 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
696 }
697 ViewDefinitionConstantValue::Canonical(c) => {
698 ConstantValue::Identifier(c.value.clone().unwrap_or_default())
699 }
700 }
701 }
702
703 impl BundleTrait for Bundle {
704 type Resource = Resource;
705
706 fn entries(&self) -> Vec<&Self::Resource> {
707 self.entry
708 .as_ref()
709 .map(|entries| entries.iter().filter_map(|e| e.resource.as_ref()).collect())
710 .unwrap_or_default()
711 }
712 }
713
714 impl ResourceTrait for Resource {
715 fn resource_name(&self) -> &str {
716 self.resource_name()
717 }
718
719 fn to_fhir_resource(&self) -> FhirResource {
720 FhirResource::R4B(Box::new(self.clone()))
721 }
722
723 fn get_last_updated(&self) -> Option<chrono::DateTime<chrono::Utc>> {
724 self.get_last_updated()
725 }
726 }
727}
728
729#[cfg(feature = "R5")]
736mod r5_impl {
737 use super::*;
738 use helios_fhir::r5::*;
739
740 impl ViewDefinitionTrait for ViewDefinition {
741 type Select = ViewDefinitionSelect;
742 type Where = ViewDefinitionWhere;
743 type Constant = ViewDefinitionConstant;
744
745 fn resource(&self) -> Option<&str> {
746 self.resource.value.as_deref()
747 }
748
749 fn select(&self) -> Option<&[Self::Select]> {
750 self.select.as_deref()
751 }
752
753 fn where_clauses(&self) -> Option<&[Self::Where]> {
754 self.r#where.as_deref()
755 }
756
757 fn constants(&self) -> Option<&[Self::Constant]> {
758 self.constant.as_deref()
759 }
760 }
761
762 impl ViewDefinitionSelectTrait for ViewDefinitionSelect {
763 type Column = ViewDefinitionSelectColumn;
764 type Select = ViewDefinitionSelect;
765
766 fn column(&self) -> Option<&[Self::Column]> {
767 self.column.as_deref()
768 }
769
770 fn select(&self) -> Option<&[Self::Select]> {
771 self.select.as_deref()
772 }
773
774 fn for_each(&self) -> Option<&str> {
775 self.for_each.as_ref()?.value.as_deref()
776 }
777
778 fn for_each_or_null(&self) -> Option<&str> {
779 self.for_each_or_null.as_ref()?.value.as_deref()
780 }
781
782 fn repeat(&self) -> Option<Vec<&str>> {
783 self.repeat
784 .as_ref()
785 .map(|paths| paths.iter().filter_map(|p| p.value.as_deref()).collect())
786 }
787
788 fn union_all(&self) -> Option<&[Self::Select]> {
789 self.union_all.as_deref()
790 }
791 }
792
793 impl ViewDefinitionColumnTrait for ViewDefinitionSelectColumn {
794 fn name(&self) -> Option<&str> {
795 self.name.value.as_deref()
796 }
797
798 fn path(&self) -> Option<&str> {
799 self.path.value.as_deref()
800 }
801
802 fn collection(&self) -> Option<bool> {
803 self.collection.as_ref()?.value
804 }
805 }
806
807 impl ViewDefinitionWhereTrait for ViewDefinitionWhere {
808 fn path(&self) -> Option<&str> {
809 self.path.value.as_deref()
810 }
811 }
812
813 impl ViewDefinitionConstantTrait for ViewDefinitionConstant {
814 fn name(&self) -> Option<&str> {
815 self.name.value.as_deref()
816 }
817
818 fn to_evaluation_result(&self) -> Result<EvaluationResult, SofError> {
819 let name = self.name().unwrap_or("unknown");
820 let value = self.value.as_ref().ok_or_else(|| {
821 SofError::InvalidViewDefinition(format!("Constant '{name}' must have a value"))
822 })?;
823 r5_constant_to_neutral(value).to_evaluation_result()
824 }
825 }
826
827 fn r5_constant_to_neutral(value: &ViewDefinitionConstantValue) -> ConstantValue {
828 match value {
829 ViewDefinitionConstantValue::String(s) => {
830 ConstantValue::String(s.value.clone().unwrap_or_default())
831 }
832 ViewDefinitionConstantValue::Boolean(b) => {
833 ConstantValue::Boolean(b.value.unwrap_or(false))
834 }
835 ViewDefinitionConstantValue::Integer(i) => {
836 ConstantValue::Integer(i.value.unwrap_or(0) as i64)
837 }
838 ViewDefinitionConstantValue::Integer64(i) => {
839 ConstantValue::Integer64(i.value.unwrap_or(0))
840 }
841 ViewDefinitionConstantValue::PositiveInt(p) => {
842 ConstantValue::PositiveInt(p.value.unwrap_or(1) as i64)
843 }
844 ViewDefinitionConstantValue::UnsignedInt(u) => {
845 ConstantValue::UnsignedInt(u.value.unwrap_or(0) as i64)
846 }
847 ViewDefinitionConstantValue::Decimal(d) => ConstantValue::Decimal(
848 d.value
849 .as_ref()
850 .map(|p| p.original_string().to_string())
851 .unwrap_or_else(|| "0".to_string()),
852 ),
853 ViewDefinitionConstantValue::Date(d) => {
854 ConstantValue::Date(d.value.clone().unwrap_or_default().to_string())
855 }
856 ViewDefinitionConstantValue::DateTime(dt) => {
857 ConstantValue::DateTime(dt.value.clone().unwrap_or_default().to_string())
858 }
859 ViewDefinitionConstantValue::Time(t) => {
860 ConstantValue::Time(t.value.clone().unwrap_or_default().to_string())
861 }
862 ViewDefinitionConstantValue::Instant(i) => {
863 ConstantValue::Instant(i.value.clone().unwrap_or_default().to_string())
864 }
865 ViewDefinitionConstantValue::Code(c) => {
866 ConstantValue::Code(c.value.clone().unwrap_or_default())
867 }
868 ViewDefinitionConstantValue::Base64Binary(b) => {
869 ConstantValue::Base64Binary(b.value.clone().unwrap_or_default())
870 }
871 ViewDefinitionConstantValue::Id(i) => {
872 ConstantValue::Identifier(i.value.clone().unwrap_or_default())
873 }
874 ViewDefinitionConstantValue::Oid(o) => {
875 ConstantValue::Identifier(o.value.clone().unwrap_or_default())
876 }
877 ViewDefinitionConstantValue::Uri(u) => {
878 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
879 }
880 ViewDefinitionConstantValue::Url(u) => {
881 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
882 }
883 ViewDefinitionConstantValue::Uuid(u) => {
884 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
885 }
886 ViewDefinitionConstantValue::Canonical(c) => {
887 ConstantValue::Identifier(c.value.clone().unwrap_or_default())
888 }
889 }
890 }
891
892 impl BundleTrait for Bundle {
893 type Resource = Resource;
894
895 fn entries(&self) -> Vec<&Self::Resource> {
896 self.entry
897 .as_ref()
898 .map(|entries| {
899 entries
900 .iter()
901 .filter_map(|e| e.resource.as_deref()) .collect()
903 })
904 .unwrap_or_default()
905 }
906 }
907
908 impl ResourceTrait for Resource {
909 fn resource_name(&self) -> &str {
910 self.resource_name()
911 }
912
913 fn to_fhir_resource(&self) -> FhirResource {
914 FhirResource::R5(Box::new(self.clone()))
915 }
916
917 fn get_last_updated(&self) -> Option<chrono::DateTime<chrono::Utc>> {
918 self.get_last_updated()
919 }
920 }
921}
922
923#[cfg(feature = "R6")]
930mod r6_impl {
931 use super::*;
932 use helios_fhir::r6::*;
933
934 impl ViewDefinitionTrait for ViewDefinition {
935 type Select = ViewDefinitionSelect;
936 type Where = ViewDefinitionWhere;
937 type Constant = ViewDefinitionConstant;
938
939 fn resource(&self) -> Option<&str> {
940 self.resource.value.as_deref()
941 }
942
943 fn select(&self) -> Option<&[Self::Select]> {
944 self.select.as_deref()
945 }
946
947 fn where_clauses(&self) -> Option<&[Self::Where]> {
948 self.r#where.as_deref()
949 }
950
951 fn constants(&self) -> Option<&[Self::Constant]> {
952 self.constant.as_deref()
953 }
954 }
955
956 impl ViewDefinitionSelectTrait for ViewDefinitionSelect {
957 type Column = ViewDefinitionSelectColumn;
958 type Select = ViewDefinitionSelect;
959
960 fn column(&self) -> Option<&[Self::Column]> {
961 self.column.as_deref()
962 }
963
964 fn select(&self) -> Option<&[Self::Select]> {
965 self.select.as_deref()
966 }
967
968 fn for_each(&self) -> Option<&str> {
969 self.for_each.as_ref()?.value.as_deref()
970 }
971
972 fn for_each_or_null(&self) -> Option<&str> {
973 self.for_each_or_null.as_ref()?.value.as_deref()
974 }
975
976 fn repeat(&self) -> Option<Vec<&str>> {
977 self.repeat
978 .as_ref()
979 .map(|paths| paths.iter().filter_map(|p| p.value.as_deref()).collect())
980 }
981
982 fn union_all(&self) -> Option<&[Self::Select]> {
983 self.union_all.as_deref()
984 }
985 }
986
987 impl ViewDefinitionColumnTrait for ViewDefinitionSelectColumn {
988 fn name(&self) -> Option<&str> {
989 self.name.value.as_deref()
990 }
991
992 fn path(&self) -> Option<&str> {
993 self.path.value.as_deref()
994 }
995
996 fn collection(&self) -> Option<bool> {
997 self.collection.as_ref()?.value
998 }
999 }
1000
1001 impl ViewDefinitionWhereTrait for ViewDefinitionWhere {
1002 fn path(&self) -> Option<&str> {
1003 self.path.value.as_deref()
1004 }
1005 }
1006
1007 impl ViewDefinitionConstantTrait for ViewDefinitionConstant {
1008 fn name(&self) -> Option<&str> {
1009 self.name.value.as_deref()
1010 }
1011
1012 fn to_evaluation_result(&self) -> Result<EvaluationResult, SofError> {
1013 let name = self.name().unwrap_or("unknown");
1014 let value = self.value.as_ref().ok_or_else(|| {
1015 SofError::InvalidViewDefinition(format!("Constant '{name}' must have a value"))
1016 })?;
1017 r6_constant_to_neutral(value).to_evaluation_result()
1018 }
1019 }
1020
1021 fn r6_constant_to_neutral(value: &ViewDefinitionConstantValue) -> ConstantValue {
1022 match value {
1023 ViewDefinitionConstantValue::String(s) => {
1024 ConstantValue::String(s.value.clone().unwrap_or_default())
1025 }
1026 ViewDefinitionConstantValue::Boolean(b) => {
1027 ConstantValue::Boolean(b.value.unwrap_or(false))
1028 }
1029 ViewDefinitionConstantValue::Integer(i) => {
1030 ConstantValue::Integer(i.value.unwrap_or(0) as i64)
1031 }
1032 ViewDefinitionConstantValue::Integer64(i) => {
1033 ConstantValue::Integer64(i.value.unwrap_or(0))
1034 }
1035 ViewDefinitionConstantValue::PositiveInt(p) => {
1036 ConstantValue::PositiveInt(p.value.unwrap_or(1) as i64)
1037 }
1038 ViewDefinitionConstantValue::UnsignedInt(u) => {
1039 ConstantValue::UnsignedInt(u.value.unwrap_or(0) as i64)
1040 }
1041 ViewDefinitionConstantValue::Decimal(d) => ConstantValue::Decimal(
1042 d.value
1043 .as_ref()
1044 .map(|p| p.original_string().to_string())
1045 .unwrap_or_else(|| "0".to_string()),
1046 ),
1047 ViewDefinitionConstantValue::Date(d) => {
1048 ConstantValue::Date(d.value.clone().unwrap_or_default().to_string())
1049 }
1050 ViewDefinitionConstantValue::DateTime(dt) => {
1051 ConstantValue::DateTime(dt.value.clone().unwrap_or_default().to_string())
1052 }
1053 ViewDefinitionConstantValue::Time(t) => {
1054 ConstantValue::Time(t.value.clone().unwrap_or_default().to_string())
1055 }
1056 ViewDefinitionConstantValue::Instant(i) => {
1057 ConstantValue::Instant(i.value.clone().unwrap_or_default().to_string())
1058 }
1059 ViewDefinitionConstantValue::Code(c) => {
1060 ConstantValue::Code(c.value.clone().unwrap_or_default())
1061 }
1062 ViewDefinitionConstantValue::Base64Binary(b) => {
1063 ConstantValue::Base64Binary(b.value.clone().unwrap_or_default())
1064 }
1065 ViewDefinitionConstantValue::Id(i) => {
1066 ConstantValue::Identifier(i.value.clone().unwrap_or_default())
1067 }
1068 ViewDefinitionConstantValue::Oid(o) => {
1069 ConstantValue::Identifier(o.value.clone().unwrap_or_default())
1070 }
1071 ViewDefinitionConstantValue::Uri(u) => {
1072 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
1073 }
1074 ViewDefinitionConstantValue::Url(u) => {
1075 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
1076 }
1077 ViewDefinitionConstantValue::Uuid(u) => {
1078 ConstantValue::Identifier(u.value.clone().unwrap_or_default())
1079 }
1080 ViewDefinitionConstantValue::Canonical(c) => {
1081 ConstantValue::Identifier(c.value.clone().unwrap_or_default())
1082 }
1083 }
1084 }
1085
1086 impl BundleTrait for Bundle {
1087 type Resource = Resource;
1088
1089 fn entries(&self) -> Vec<&Self::Resource> {
1090 self.entry
1091 .as_ref()
1092 .map(|entries| {
1093 entries
1094 .iter()
1095 .filter_map(|e| e.resource.as_deref()) .collect()
1097 })
1098 .unwrap_or_default()
1099 }
1100 }
1101
1102 impl ResourceTrait for Resource {
1103 fn resource_name(&self) -> &str {
1104 self.resource_name()
1105 }
1106
1107 fn to_fhir_resource(&self) -> FhirResource {
1108 FhirResource::R6(Box::new(self.clone()))
1109 }
1110
1111 fn get_last_updated(&self) -> Option<chrono::DateTime<chrono::Utc>> {
1112 self.get_last_updated()
1113 }
1114 }
1115}