import BreastCancer from '../shr/oncology/BreastCancer';
import FluxTest from '../lab/FluxTest';
import FluxTNMStage from './FluxTNMStage';
import ReceptorStatusObservation from '../shr/oncology/ReceptorStatusObservation';
import SpecificType from '../shr/core/SpecificType';
import Lang from 'lodash'
import moment from 'moment';
import lookup from '../../lib/cancer_lookup.jsx';

class FluxBreastCancer extends BreastCancer {
    get diagnosisDate() {
        return this.whenClinicallyRecognized.value.value.value.timePeriodStart.value;
    }
    get type() {
        if (!this.specificType) return null;
        return this.specificType.value.coding[0].displayText.value;
    }
    
    set type(cancerType) {
        if (!this.specificType) this.specificType = new SpecificType();
        this.specificType.value = lookup.getCancerCodeableConcept(cancerType);
    }
    
    getObservationsOfType(type) {
        if (!this.observation) return [];
		return this.observation.filter((item) => { 
			return item instanceof type;
		});
    }
    
   	getTests() {
		return this.getObservationsOfType(FluxTest);
	}

   	_observationTimeSorter(a, b) {
		const a_startTime = new moment(a.occurrenceTime, "D MMM YYYY");
		const b_startTime = new moment(b.occurrenceTime, "D MMM YYYY");
		if (a_startTime < b_startTime) { return -1; }
		if (a_startTime > b_startTime) { return 1; }
		return 0;
	}

	_getReceptorStatus(receptorType) {
		let listObs = this.getObservationsOfType(ReceptorStatusObservation);
		let list = listObs.filter((item) => {
			return item.receptorType.value.coding[0].value === receptorType;
		});
		if (list.length === 0) return null; else return list[0];
	}
    
    getERReceptorStatus() {
        return this._getReceptorStatus("23307004");
    }
    getPRReceptorStatus() {
        return this._getReceptorStatus("C0034833");
    }
    getHER2ReceptorStatus() {
        return this._getReceptorStatus("C0069515");
    }

    getMostRecentStaging(sinceDate = null) {
		let stagingList = this.getObservationsOfType(FluxTNMStage);
		if (stagingList.length === 0) return null;
        const sortedStagingList = stagingList.sort(this._observationTimeSorter);
        const length = sortedStagingList.length;
        let s = (sortedStagingList[length - 1]);
		if (Lang.isNull(sinceDate)) return s;
		const startTime = new moment(s.occurrenceTime, "D MMM YYYY");
		if (startTime < sinceDate) {
			return null;
		} else {
			return s;
		}        
    }
}

export default FluxBreastCancer;
@@ -970,18 +970,24 @@
 rn %5B%5D;%0D%0A
-%09%09
+        
 return t
@@ -1023,19 +1023,28 @@
  =%3E %7B %0D%0A
-%09%09%09
+            
 return i
@@ -1061,26 +1061,32 @@
 ceof type;%0D%0A
-%09%09
+        
 %7D);%0D%0A    %7D%0D%0A
@@ -1094,17 +1094,20 @@
    %0D%0A   
-%09
+    
 getTests
@@ -1112,18 +1112,24 @@
 ts() %7B%0D%0A
-%09%09
+        
 return t
@@ -1170,17 +1170,20 @@
 );%0D%0A
-%09
+    
 %7D%0D%0A%0D%0A   
 %09_ob
@@ -1178,17 +1178,20 @@
 %7D%0D%0A%0D%0A   
+  
-%09
+  
 _observa
@@ -1214,18 +1214,24 @@
 , b) %7B%0D%0A
-%09%09
+        
 const a_
@@ -1287,18 +1287,24 @@
 YYY%22);%0D%0A
-%09%09
+        
 const b_
@@ -1356,26 +1356,32 @@
 MM YYYY%22);%0D%0A
-%09%09
+        
 if (a_startT
@@ -1415,18 +1415,24 @@
  -1; %7D%0D%0A
-%09%09
+        
 if (a_st
@@ -1469,18 +1469,24 @@
 n 1; %7D%0D%0A
-%09%09
+        
 return 0
@@ -1492,15 +1492,21 @@
 0;%0D%0A
-%09
+    
 %7D%0D%0A%0D%0A
-%09
+    
 _get
@@ -1533,26 +1533,32 @@
 torType) %7B%0D%0A
-%09%09
+        
 let listObs 
@@ -1615,18 +1615,24 @@
 tion);%0D%0A
-%09%09
+        
 let list
@@ -1658,27 +1658,36 @@
 item) =%3E %7B%0D%0A
-%09%09%09
+            
 return item.
@@ -1744,17 +1744,29 @@
 e;%0D%0A
-%09%09%7D);%0D%0A%09%09
+        %7D);%0D%0A        
 if (
@@ -1819,17 +1819,20 @@
 st%5B0%5D;%0D%0A
-%09
+    
 %7D%0D%0A    %0D
@@ -2149,18 +2149,24 @@
 ull) %7B%0D%0A
-%09%09
+        
 let stag
@@ -2214,26 +2214,32 @@
 TNMStage);%0D%0A
-%09%09
+        
 if (stagingL
@@ -2448,26 +2448,32 @@
 gth - 1%5D);%0D%0A
-%09%09
+        
 if (Lang.isN
@@ -2499,18 +2499,24 @@
 urn s;%0D%0A
-%09%09
+        
 const st
@@ -2570,18 +2570,24 @@
 YYY%22);%0D%0A
-%09%09
+        
 if (star
@@ -2604,27 +2604,36 @@
 nceDate) %7B%0D%0A
-%09%09%09
+            
 return null;
@@ -2634,18 +2634,24 @@
  null;%0D%0A
-%09%09
+        
 %7D else %7B
@@ -2656,11 +2656,20 @@
  %7B%0D%0A
-%09%09%09
+            
 retu
@@ -2679,10 +2679,16 @@
 s;%0D%0A
-%09%09
+        
 %7D   

fix tabs to be 4 spaces