@@ -713,62 +713,133 @@ Ext4.define('MCC.panel.MccImportPanel', {
713713 if ( missingIds . length ) {
714714 Ext4 . create ( 'Ext.window.Window' , {
715715 bodyStyle : 'padding: 5px;' ,
716- width : 500 ,
716+ width : 600 ,
717717 modal : true ,
718718 title : 'Reconcile Census with Existing IDs' ,
719+ effectiveDate : config . rowData . panel . IMPORT_DATE ,
719720 defaults : {
720721 labelWidth : 200 ,
721- width : 450 ,
722+ width : 575 ,
722723 } ,
723724 items : [ {
724725 html : 'The following IDs are listed for the indicated colony, but were not in your census. Choose any status updates and hit submit:' ,
725726 border : false ,
726727 style : 'padding-bottom: 10px;'
727728 } , {
728- layout : 'table' ,
729+ layout : {
730+ type : 'table' ,
731+ columns : 4
732+ } ,
729733 border : false ,
730- columns : 2 ,
731734 defaults : {
732- border : false
735+ border : false ,
736+ bodyStyle : 'padding: 5px'
733737 } ,
734738 items : config . rowData . panel . getAnimalRows ( missingIds )
735739 } ] ,
736740 buttons : [ {
737741 text : 'Update IDs' ,
738742 scope : this ,
739743 handler : function ( btn ) {
740- var updates = [ ]
741- btn . up ( 'window' ) . query ( 'combo' ) . forEach ( function ( f ) {
744+ var demographicsUpdates = [ ] ;
745+ var deathInserts = [ ] ;
746+ var departureInserts = [ ] ;
747+ var win = btn . up ( 'window' ) ;
748+
749+ var missingValues = false ;
750+ win . query ( 'combo[dataIndex="status_code"]' ) . forEach ( function ( f ) {
742751 if ( f . getValue ( ) && f . getValue ( ) !== f . sourceRecord . calculated_status ) {
743- updates . push ( {
744- Id : f . sourceRecord . Id ,
745- calculated_status : f . getValue ( ) ,
746- lsid : f . sourceRecord . lsid ,
747- objectid : f . sourceRecord . objectid
748- } ) ;
752+ var fields = win . query ( 'field[recordIdx=' + f . recordIdx + ']' ) ;
753+ LDK . Assert . assertEquality ( 'Incorrect number of MccImportPanel fields' , 3 , fields . length ) ;
754+
755+ var dateVal = fields [ 1 ] . getValue ( ) ;
756+ var otherVal = fields [ 2 ] . getValue ( ) ;
757+ if ( ! dateVal || ! otherVal ) {
758+ missingValues = true ;
759+ return false ;
760+ }
761+
762+ if ( f . getValue ( ) === 'Dead' ) {
763+ deathInserts . push ( {
764+ Id : f . sourceRecord . Id ,
765+ objectId : null ,
766+ QCStateLabel : 'Completed' ,
767+ QCState : null ,
768+ date : dateVal ,
769+ cause : otherVal
770+ } ) ;
771+ } else if ( f . getValue ( ) === 'Shipped' ) {
772+ departureInserts . push ( {
773+ Id : f . sourceRecord . Id ,
774+ objectId : null ,
775+ QCStateLabel : 'Completed' ,
776+ QCState : null ,
777+ date : dateVal ,
778+ destination : otherVal
779+ } ) ;
780+ } else {
781+ // Handle unknown:
782+ demographicsUpdates . push ( {
783+ Id : f . sourceRecord . Id ,
784+ calculated_status : f . getValue ( ) ,
785+ lsid : f . sourceRecord . lsid ,
786+ objectid : f . sourceRecord . objectid
787+ } ) ;
788+ }
749789 }
750790 } ) ;
751791
752- if ( updates . length ) {
753- Ext4 . Msg . wait ( 'Saving...' ) ;
754- LABKEY . Query . updateRows ( {
792+ if ( missingValues ) {
793+ Ext4 . Msg . alert ( 'Error' , 'One or more fields is missing a value' ) ;
794+ return ;
795+ }
796+
797+ var commands = [ ] ;
798+ if ( demographicsUpdates . length ) {
799+ commands . push ( {
800+ command : 'update' ,
755801 schemaName : 'study' ,
756802 queryName : 'demographics' ,
757- rows : updates ,
803+ rows : demographicsUpdates
804+ } ) ;
805+ }
806+
807+ if ( departureInserts . length ) {
808+ commands . push ( {
809+ type : 'insert' ,
810+ schemaName : 'study' ,
811+ queryName : 'departure' ,
812+ rows : departureInserts
813+ } ) ;
814+ }
815+
816+ if ( deathInserts . length ) {
817+ commands . push ( {
818+ command : 'insert' ,
819+ schemaName : 'study' ,
820+ queryName : 'deaths' ,
821+ rows : deathInserts
822+ } ) ;
823+ }
824+
825+ if ( ! commands . length ) {
826+ Ext4 . Msg . alert ( 'No updates' , 'No changes, nothing to do' ) ;
827+ btn . up ( 'window' ) . close ( ) ;
828+ }
829+ else {
830+ Ext4 . Msg . wait ( 'Saving rows...' ) ;
831+ LABKEY . Query . saveRows ( {
832+ commands : commands ,
758833 scope : this ,
759- failure : LDK . Utils . getErrorCallback ( ) ,
760- success : function ( results ) {
834+ success : function ( ) {
761835 Ext4 . Msg . hide ( ) ;
762836 Ext4 . Msg . alert ( 'Success' , 'Records updated' , function ( ) {
763837 btn . up ( 'window' ) . close ( ) ;
764838 } , this ) ;
765- }
839+ } ,
840+ failure : LDK . Utils . getErrorCallback ( )
766841 } ) ;
767842 }
768- else {
769- Ext4 . Msg . alert ( 'No updates' , 'No changes, nothing to do' ) ;
770- btn . up ( 'window' ) . close ( ) ;
771- }
772843 }
773844
774845 } , {
@@ -786,22 +857,110 @@ Ext4.define('MCC.panel.MccImportPanel', {
786857 } ,
787858
788859 getAnimalRows : function ( missingIds ) {
789- var ret = [ ] ;
790- Ext4 . Array . forEach ( missingIds , function ( r ) {
860+ var ret = [ {
861+ xtype : 'displayfield' ,
862+ width : 125 ,
863+ value : 'Animal Id'
864+ } , {
865+ xtype : 'displayfield' ,
866+ width : 100 ,
867+ value : 'Status'
868+ } , {
869+ xtype : 'displayfield' ,
870+ width : 100 ,
871+ value : 'Date'
872+ } , {
873+ xtype : 'displayfield' ,
874+ width : 125 ,
875+ value : 'Destination/Cause'
876+ } ] ;
877+
878+ Ext4 . Array . forEach ( missingIds , function ( r , idx ) {
791879 ret = ret . concat ( [ {
792880 xtype : 'displayfield' ,
793881 width : 125 ,
794882 value : r . Id + ' / ' + r . colony
795- } , {
796- xtype : 'ldk-simplelabkeycombo' ,
797- schemaName : 'ehr_lookups' ,
798- queryName : 'calculated_status_codes' ,
799- displayField : 'code' ,
800- valueField : 'code' ,
883+ } , {
884+ xtype : 'ldk-simplecombo' ,
885+ storeValues : Ext4 . Array . unique ( [ r . calculated_status , 'Alive' , 'Dead' , 'Shipped' , 'Unknown' ] ) ,
886+ recordIdx : idx ,
887+ dataIndex : 'status_code' ,
801888 forceSelection : true ,
802889 sourceRecord : r ,
803890 width : 100 ,
804- value : r . calculated_status
891+ style : 'margin-right: 5px' ,
892+ value : r . calculated_status ,
893+ listeners : {
894+ render : function ( f ) {
895+ if ( f . getValue ( ) ) {
896+ f . fireEvent ( 'change' , f , f . getValue ( ) ) ;
897+ }
898+ } ,
899+ change : function ( field , val ) {
900+ var target1 = field . up ( 'panel' ) . down ( 'container[recordIdx=' + field . recordIdx + '][areaType="date"]' ) ;
901+ target1 . removeAll ( ) ;
902+
903+ var target2 = field . up ( 'panel' ) . down ( 'container[recordIdx=' + field . recordIdx + '][areaType="other"]' ) ;
904+ target2 . removeAll ( ) ;
905+
906+ var effectiveDate = field . up ( 'window' ) . effectiveDate ;
907+
908+ if ( val === 'Shipped' ) {
909+ target1 . add ( {
910+ xtype : 'datefield' ,
911+ dataIndex : 'date' ,
912+ labelAlign : 'top' ,
913+ recordIdx : field . recordIdx ,
914+ style : 'margin-right: 5px' ,
915+ value : effectiveDate
916+ } ) ;
917+
918+ target2 . add ( {
919+ xtype : 'ldk-simplelabkeycombo' ,
920+ dataIndex : 'destination' ,
921+ labelAlign : 'top' ,
922+ recordIdx : field . recordIdx ,
923+ schemaName : 'ehr_lookups' ,
924+ queryName : 'source' ,
925+ valueField : 'code' ,
926+ displayField : 'code' ,
927+ forceSelection : true ,
928+ plugins : [ 'ldk-usereditablecombo' ]
929+ } ) ;
930+ }
931+ else if ( val === 'Dead' ) {
932+ target1 . add ( {
933+ xtype : 'datefield' ,
934+ dataIndex : 'date' ,
935+ labelAlign : 'top' ,
936+ recordIdx : field . recordIdx ,
937+ style : 'margin-right: 5px' ,
938+ value : effectiveDate
939+ } ) ;
940+
941+ target2 . add ( {
942+ xtype : 'ldk-simplelabkeycombo' ,
943+ dataIndex : 'cause' ,
944+ labelAlign : 'top' ,
945+ recordIdx : field . recordIdx ,
946+ schemaName : 'ehr_lookups' ,
947+ queryName : 'death_cause' ,
948+ valueField : 'value' ,
949+ displayField : 'value' ,
950+ forceSelection : true ,
951+ plugins : [ 'ldk-usereditablecombo' ]
952+ } ) ;
953+ }
954+ }
955+ }
956+ } , {
957+ xtype : 'container' ,
958+ recordIdx : idx ,
959+ areaType : 'date'
960+ } , {
961+ xtype : 'container' ,
962+ recordIdx : idx ,
963+ areaType : 'other'
805964 } ] ) ;
806965 } ) ;
807966
0 commit comments