@@ -4,14 +4,14 @@ import _ from "lodash";
44import MultipleCodedValues from "./observation/MultipleCodedValues" ;
55import SingleCodedValue from "./observation/SingleCodedValue" ;
66import PrimitiveValue from "./observation/PrimitiveValue" ;
7- import Duration from "./Duration" ;
87import CompositeDuration from "./CompositeDuration" ;
98import KeyValue from "./application/KeyValue" ;
109import PhoneNumber from "./PhoneNumber" ;
1110import Identifier from "./Identifier" ;
1211import QuestionGroup from "./observation/QuestionGroup" ;
1312import RepeatableQuestionGroup from "./observation/RepeatableQuestionGroup" ;
1413import ConceptAnswer from "./ConceptAnswer" ;
14+ import ConceptMedia from "./ConceptMedia" ;
1515import SchemaNames from "./SchemaNames" ;
1616
1717export default class Concept extends BaseEntity {
@@ -35,8 +35,7 @@ export default class Concept extends BaseEntity {
3535 unit : { type : "string" , optional : true } ,
3636 keyValues : { type : "list" , objectType : SchemaNames . KeyValue } ,
3737 voided : { type : "bool" , default : false } ,
38- mediaUrl : { type : "string" , optional : true } ,
39- mediaType : { type : "string" , optional : true } ,
38+ media : { type : "list" , objectType : "ConceptMedia" } ,
4039 } ,
4140 } ;
4241
@@ -84,20 +83,39 @@ export default class Concept extends BaseEntity {
8483 this . that . unit = x ;
8584 }
8685
87- get mediaUrl ( ) {
88- return this . that . mediaUrl ;
86+ getImageMedia ( ) {
87+ return this . media ? this . media . filter ( m => m . isImage ( ) ) : [ ] ;
8988 }
9089
91- set mediaUrl ( x ) {
92- this . that . mediaUrl = x ;
90+ getVideoMedia ( ) {
91+ return this . media ? this . media . filter ( m => m . isVideo ( ) ) : [ ] ;
9392 }
9493
95- get mediaType ( ) {
96- return this . that . mediaType ;
94+ hasImage ( ) {
95+ return this . getImageMedia ( ) . length > 0 ;
96+ }
97+
98+ hasVideo ( ) {
99+ return this . getVideoMedia ( ) . length > 0 ;
100+ }
101+
102+ getImageUrl ( ) {
103+ const imageMedia = this . getImageMedia ( ) ;
104+ return imageMedia . length > 0 ? imageMedia [ 0 ] . url : null ;
97105 }
98106
99- set mediaType ( x ) {
100- this . that . mediaType = x ;
107+ getVideoUrl ( ) {
108+ const videoMedia = this . getVideoMedia ( ) ;
109+ return videoMedia . length > 0 ? videoMedia [ 0 ] . url : null ;
110+ }
111+
112+ // For backward compatibility where existing code expects mediaUrl/mediaType
113+ get mediaUrl ( ) {
114+ return this . getImageUrl ( ) ;
115+ }
116+
117+ get mediaType ( ) {
118+ return this . hasImage ( ) ? 'Image' : this . hasVideo ( ) ? 'Video' : null ;
101119 }
102120
103121 get name ( ) {
@@ -132,6 +150,14 @@ export default class Concept extends BaseEntity {
132150 this . that . keyValues = this . fromEntityList ( x ) ;
133151 }
134152
153+ get media ( ) {
154+ return this . toEntityList ( "media" , ConceptMedia ) ;
155+ }
156+
157+ set media ( x ) {
158+ this . that . media = this . fromEntityList ( x ) ;
159+ }
160+
135161 static keys = {
136162 isWithinCatchment : 'isWithinCatchment' ,
137163 lowestAddressLevelTypeUUIDs : 'lowestAddressLevelTypeUUIDs' ,
@@ -186,8 +212,12 @@ export default class Concept extends BaseEntity {
186212 concept . unit = conceptResource . unit ;
187213 concept . voided = conceptResource . voided || false ; //This change should be independently deployable irrespective of server
188214 concept . keyValues = _ . map ( conceptResource . keyValues , KeyValue . fromResource ) ;
189- concept . mediaUrl = conceptResource . mediaUrl ;
190- concept . mediaType = conceptResource . mediaType ;
215+
216+ // Handle media array format from server
217+ if ( conceptResource . media ) {
218+ concept . media = _ . map ( conceptResource . media , ConceptMedia . fromResource ) ;
219+ }
220+
191221 return concept ;
192222 }
193223
@@ -427,14 +457,15 @@ export default class Concept extends BaseEntity {
427457 }
428458
429459 hasAnswersWithMedia ( ) {
430- return _ . some ( this . answers , ( answer ) => answer . concept . hasMediaUrl ( ) || answer . concept . hasMediaType ( ) ) ;
460+ return _ . some ( this . answers , ( answer ) => answer . concept . hasMedia ( ) ) ;
431461 }
432462
433463 hasMedia ( ) {
434- return this . hasMediaUrl ( ) || this . hasMediaType ( ) || this . hasAnswersWithMedia ( ) ;
464+ return this . media && this . media . length > 0 || this . hasAnswersWithMedia ( ) ;
435465 }
436466}
437467
438468export const MediaType = {
439- Image : "Image"
469+ Image : "Image" ,
470+ Video : "Video"
440471} ;
0 commit comments