@@ -1065,25 +1065,23 @@ class ResourceNode {
10651065 */
10661066 convertData ( ) {
10671067 var data = this . data ;
1068- switch ( this . path ) {
1069- case 'Quantity' :
1070- if ( data ?. system === ucumSystemUrl ) {
1071- if ( typeof data . value === 'number' && typeof data . code === 'string' ) {
1072- if ( data . comparator !== undefined )
1073- throw new Error ( 'Cannot convert a FHIR.Quantity that has a comparator' ) ;
1074- data =
1075- new FP_Quantity ( data . value , FP_Quantity . mapUCUMCodeToTimeUnits [ data . code ] || '\'' + data . code + '\'' ) ;
1076- }
1068+ if ( TypeInfo . isType ( this . path , 'Quantity' ) ) {
1069+ if ( data ?. system === ucumSystemUrl ) {
1070+ if ( typeof data . value === 'number' && typeof data . code === 'string' ) {
1071+ if ( data . comparator !== undefined )
1072+ throw new Error ( 'Cannot convert a FHIR.Quantity that has a comparator' ) ;
1073+ data = new FP_Quantity (
1074+ data . value ,
1075+ FP_Quantity . mapUCUMCodeToTimeUnits [ data . code ] || '\'' + data . code + '\''
1076+ ) ;
10771077 }
1078- break ;
1079- case 'date' :
1080- data = FP_Date . checkString ( data ) || data ;
1081- break ;
1082- case 'dateTime' :
1083- data = FP_DateTime . checkString ( data ) || data ;
1084- break ;
1085- case 'time' :
1086- data = FP_Time . checkString ( data ) || data ;
1078+ }
1079+ } else if ( this . path === 'date' ) {
1080+ data = FP_Date . checkString ( data ) || data ;
1081+ } else if ( this . path === 'dateTime' ) {
1082+ data = FP_DateTime . checkString ( data ) || data ;
1083+ } else if ( this . path === 'time' ) {
1084+ data = FP_Time . checkString ( data ) || data ;
10871085 }
10881086
10891087 return data ;
@@ -1122,23 +1120,34 @@ class TypeInfo {
11221120 * @return {boolean }
11231121 */
11241122 is ( other ) {
1125- if ( other instanceof TypeInfo
1126- && ( ! this . namespace || ! other . namespace || this . namespace === other . namespace ) ) {
1127- if ( TypeInfo . model && ( ! this . namespace || this . namespace === TypeInfo . FHIR ) ) {
1128- let name = this . name ;
1129- do {
1130- if ( name === other . name ) {
1131- return true ;
1132- }
1133- } while ( ( name = TypeInfo . model . type2Parent [ name ] ) ) ;
1134- } else {
1135- return this . name === other . name ;
1136- }
1123+ if (
1124+ other instanceof TypeInfo &&
1125+ ( ! this . namespace || ! other . namespace || this . namespace === other . namespace )
1126+ ) {
1127+ return TypeInfo . model && ( ! this . namespace || this . namespace === TypeInfo . FHIR )
1128+ ? TypeInfo . isType ( this . name , other . name )
1129+ : this . name === other . name ;
11371130 }
11381131 return false ;
11391132 }
11401133}
11411134
1135+ /**
1136+ * Checks if the type name or its parent type name is equal to
1137+ * the expected type name.
1138+ * @param type - type name to check.
1139+ * @param superType - expected type name.
1140+ * @return {boolean }
1141+ */
1142+ TypeInfo . isType = function ( type , superType ) {
1143+ do {
1144+ if ( type === superType ) {
1145+ return true ;
1146+ }
1147+ } while ( ( type = TypeInfo . model ?. type2Parent [ type ] ) ) ;
1148+ return false ;
1149+ } ;
1150+
11421151// Available namespaces:
11431152TypeInfo . System = 'System' ;
11441153TypeInfo . FHIR = 'FHIR' ;
0 commit comments