@@ -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,22 +83,33 @@ 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 ;
9796 }
9897
99- set mediaType ( x ) {
100- this . that . mediaType = x ;
98+ hasVideo ( ) {
99+ return this . getVideoMedia ( ) . length > 0 ;
101100 }
102101
102+ getImageUrl ( ) {
103+ const imageMedia = this . getImageMedia ( ) ;
104+ return imageMedia . length > 0 ? imageMedia [ 0 ] . url : null ;
105+ }
106+
107+ getVideoUrl ( ) {
108+ const videoMedia = this . getVideoMedia ( ) ;
109+ return videoMedia . length > 0 ? videoMedia [ 0 ] . url : null ;
110+ }
111+
112+
103113 get name ( ) {
104114 return this . that . name ;
105115 }
@@ -132,6 +142,14 @@ export default class Concept extends BaseEntity {
132142 this . that . keyValues = this . fromEntityList ( x ) ;
133143 }
134144
145+ get media ( ) {
146+ return this . toEntityList ( "media" , ConceptMedia ) ;
147+ }
148+
149+ set media ( x ) {
150+ this . that . media = this . fromEntityList ( x ) ;
151+ }
152+
135153 static keys = {
136154 isWithinCatchment : 'isWithinCatchment' ,
137155 lowestAddressLevelTypeUUIDs : 'lowestAddressLevelTypeUUIDs' ,
@@ -186,8 +204,12 @@ export default class Concept extends BaseEntity {
186204 concept . unit = conceptResource . unit ;
187205 concept . voided = conceptResource . voided || false ; //This change should be independently deployable irrespective of server
188206 concept . keyValues = _ . map ( conceptResource . keyValues , KeyValue . fromResource ) ;
189- concept . mediaUrl = conceptResource . mediaUrl ;
190- concept . mediaType = conceptResource . mediaType ;
207+
208+ // Handle media array format from server
209+ if ( conceptResource . media ) {
210+ concept . media = _ . map ( conceptResource . media , ConceptMedia . fromResource ) ;
211+ }
212+
191213 return concept ;
192214 }
193215
@@ -414,27 +436,13 @@ export default class Concept extends BaseEntity {
414436 return ( keyValue === KeyValue . ContactYesValue ) ;
415437 }
416438
417- isMediaTypeImage ( ) {
418- return this . mediaType === MediaType . Image ;
419- }
420-
421- hasMediaType ( ) {
422- return ! _ . isNil ( this . mediaType ) ;
423- }
424-
425- hasMediaUrl ( ) {
426- return ! _ . isNil ( this . mediaUrl ) && this . mediaUrl !== '' ;
427- }
428439
429440 hasAnswersWithMedia ( ) {
430- return _ . some ( this . answers , ( answer ) => answer . concept . hasMediaUrl ( ) || answer . concept . hasMediaType ( ) ) ;
441+ return _ . some ( this . answers , ( answer ) => answer . concept . hasMedia ( ) ) ;
431442 }
432443
433444 hasMedia ( ) {
434- return this . hasMediaUrl ( ) || this . hasMediaType ( ) || this . hasAnswersWithMedia ( ) ;
445+ return this . media && this . media . length > 0 || this . hasAnswersWithMedia ( ) ;
435446 }
436447}
437448
438- export const MediaType = {
439- Image : "Image"
440- } ;
0 commit comments